Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/lazaroDevelop' into lazaroDevelop
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarocosta committed Jun 4, 2020
2 parents 12b77fb + 1ebade8 commit b27f5a5
Show file tree
Hide file tree
Showing 95 changed files with 1,506 additions and 675 deletions.
25 changes: 20 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
FROM ubuntu:18.04 as dependencies_ready
ARG PRELOAD_GRAPH
ENV PRELOAD_GRAPH "$PRELOAD_GRAPH"
FROM ubuntu:18.04 as os_dependencies_ready

RUN apt-get update -qq
RUN apt-get install -y -qq git curl wget build-essential
FROM dependencies_ready

FROM os_dependencies_ready as backend_dependencies

WORKDIR /archgraph_setup
COPY ./conf /archgraph_setup/conf
COPY ./requirements.txt /archgraph_setup/requirements.txt
COPY ./frontend/package.json /archgraph_setup/frontend/package.json
RUN ./conf/install_backend.sh

FROM backend_dependencies as frontend_dependencies
RUN ./conf/install_frontend.sh

FROM frontend_dependencies as archgraph_installed
COPY . /archgraph
RUN mv /archgraph_setup/frontend/* /archgraph/frontend

FROM archgraph_installed as cleanup_complete
RUN rm -rf /archgraph_setup

WORKDIR /archgraph
RUN ./conf/install.sh

ENTRYPOINT [ "./conf/run.sh" ]
83 changes: 3 additions & 80 deletions conf/install.sh
Original file line number Diff line number Diff line change
@@ -1,88 +1,11 @@
#!/bin/bash

ROOT_DIR=$(pwd)
echo "Running at $ROOT_DIR"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

ARCHGRAPH_ENV="archgraph"
PYTHON27_ENV="nodegyp-python27"
source "$DIR/install_backend.sh"
source "$DIR/install_frontend.sh"

if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
if [ $(conda > /dev/null) > /dev/null ]; then
brew cask install miniconda || brew cask upgrade miniconda
else
echo "Miniconda already installed, continuing..."
fi
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ] ; then
if ! type conda &> /dev/null ; then
# Do something under GNU/Linux platform
rm -rf Miniconda3-latest-Linux-x86_64.sh
wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -p "$HOME/miniconda" || ./Miniconda3-latest-Linux-x86_64.sh -u -b -p "$HOME/miniconda"
rm -rf Miniconda3-latest-Linux-x86_64.sh
else
echo "Miniconda already installed, continuing..."
fi
fi

# run conda
if [ "$(uname)" == "Darwin" ]; then
source "$HOME/.bash_profile"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
source "$HOME/.profile"
fi

if [ "$(uname)" == "Darwin" ]; then
# make conda binary available in path
export PATH="$HOME/miniconda/bin":$PATH
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# init conda cli
source "$HOME/miniconda/etc/profile.d/conda.sh"
fi

conda init bash
conda create --quiet -y -n "$PYTHON27_ENV" python=2.7 anaconda
conda activate "$PYTHON27_ENV"
PYTHON27_PATH=$(which python)
echo "Node-Gyp interpreter Python (2.7) is at: ---> ${PYTHON27_PATH} <---"

# create archgraph env
conda create --quiet -y -n "$ARCHGRAPH_ENV" python=3.7 anaconda
conda activate "$ARCHGRAPH_ENV"

# Get location of python interpreter
PYTHON_PATH=$(which python)
echo "Python interpreter is at: ---> ${PYTHON_PATH} <---"

# install pip
conda install pip -y --all --quiet
echo "Pip at: ---> $(which pip) <---"
# (optional) install any requirements of your current app in this venv
pip install -r "$ROOT_DIR/requirements.txt"


# install nodejs and yarn
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

# activate nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

#install nodejs
nvm install v10
nvm use v10

# install frontend stuff
cd frontend
npm install -g npm@latest
npm config set python "$PYTHON27_PATH"
npm install

# preload graph
if [ -z "$PRELOAD_GRAPH" ] ; then
echo "Preload graph flag is not active, skipping tests"
else
echo "Preload graph flag is active, loading graph through tests"
coverage run -m unittest discover test || true
fi
62 changes: 62 additions & 0 deletions conf/install_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

ROOT_DIR=$(pwd)
echo "Running at $ROOT_DIR"

ARCHGRAPH_ENV="archgraph"
PYTHON27_ENV="nodegyp-python27"

if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
if [ $(conda > /dev/null) > /dev/null ]; then
brew cask install miniconda || brew cask upgrade miniconda
else
echo "Miniconda already installed, continuing..."
fi
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ] ; then
if ! type conda &> /dev/null ; then
# Do something under GNU/Linux platform
rm -rf Miniconda3-latest-Linux-x86_64.sh
wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -p "$HOME/miniconda" || ./Miniconda3-latest-Linux-x86_64.sh -u -b -p "$HOME/miniconda"
rm -rf Miniconda3-latest-Linux-x86_64.sh
else
echo "Miniconda already installed, continuing..."
fi
fi

# run conda
if [ "$(uname)" == "Darwin" ]; then
source "$HOME/.bash_profile"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
source "$HOME/.profile"
fi

if [ "$(uname)" == "Darwin" ]; then
# make conda binary available in path
export PATH="$HOME/miniconda/bin":$PATH
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# init conda cli
source "$HOME/miniconda/etc/profile.d/conda.sh"
fi

conda init bash
conda create --quiet -y -n "$PYTHON27_ENV" python=2.7 anaconda
conda activate "$PYTHON27_ENV"
PYTHON27_PATH=$(which python)
echo "Node-Gyp interpreter Python (2.7) is at: ---> ${PYTHON27_PATH} <---"

# create archgraph env
conda create --quiet -y -n "$ARCHGRAPH_ENV" python=3.7 anaconda
conda activate "$ARCHGRAPH_ENV"

# Get location of python interpreter
PYTHON_PATH=$(which python)
echo "Python interpreter is at: ---> ${PYTHON_PATH} <---"

# install pip
conda install pip -y --all --quiet
echo "Pip at: ---> $(which pip) <---"
# (optional) install any requirements of your current app in this venv
pip install -r "$ROOT_DIR/requirements.txt"
27 changes: 27 additions & 0 deletions conf/install_frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

ROOT_DIR=$(pwd)
echo "Installing frontend dependencies at $ROOT_DIR"

ARCHGRAPH_ENV="archgraph"
PYTHON27_ENV="nodegyp-python27"

# install nodejs and yarn
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

# activate nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

#install nodejs
nvm install v10
nvm use v10

# install frontend stuff
cd "$ROOT_DIR/frontend"
npm install -g npm@latest
npm config set python "$PYTHON27_PATH"
npm install
echo "Current directory: $(pwd)"
ls -la
cd -
49 changes: 43 additions & 6 deletions conf/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,56 @@ nvm use v10
echo "Starting archgraph server at $ROOT_DIR"
cd "$ROOT_DIR"

if [[ "$NEO4J_CONNECTION_STRING" != "" ]]; then
echo "Neo4j Server at $NEO4J_CONNECTION_STRING";
if [[ "$NEO4J_HOST" != "" ]]; then
echo "Neo4j Server Host: $NEO4J_HOST"
else
NEO4J_HOST="127.0.0.1"
fi

if [[ "$NEO4J_PORT" != "" ]]; then
echo "Neo4j Server Port: $NEO4J_PORT"
else
NEO4J_PORT="7687"
fi

if [[ "$MONGODB_CONNECTION_STRING" != "" ]]; then
echo "MongoDB Server at $MONGODB_CONNECTION_STRING";
if [[ "$MONGODB_HOST" != "" ]]; then
echo "MongoDB Server Host: $MONGODB_HOST"
else
MONGODB_HOST="127.0.0.1"
fi

if [[ "$MONGODB_PORT" != "" ]]; then
echo "MongoDB Server Port: $MONGODB_PORT"
else
MONGODB_PORT="27017"
fi

if [[ "$CUSTOM_HOST_FOR_SERVER_BIND" != "" ]]; then
echo "Flask Server binding to host with address $CUSTOM_HOST_FOR_SERVER_BIND";
echo "Flask Server binding to host with address $CUSTOM_HOST_FOR_SERVER_BIND"
fi

## wait for servers to be active before running the application

./conf/wait-for-it.sh "$NEO4J_HOST:$NEO4J_PORT" --timeout=120 &
./conf/wait-for-it.sh "$MONGODB_HOST:$MONGODB_PORT" --timeout=120 &

wait

# preload graph
if [[ -z "$INIT_GRAPH" ]] ; then
echo "Preload graph flag is not active, skipping tests"
elif [[ ! -f "$ROOT_DIR/.preloaded.txt" ]] || [[ "$FORCE_RELOAD_GRAPH" == "1" ]] ; then
rm -f "$ROOT_DIR/.preloaded.txt"
echo "Preload graph flag is active, loading graph through tests"
coverage run -m unittest discover test
echo "true" > "$ROOT_DIR/.preloaded.txt"
else
echo "Preload graph flag is active but the database has already been initialized once. \
To re-initialize, delete the $ROOT_DIR/.preloaded.txt file and run this script again, or \
set the FORCE_RELOAD_GRAPH environment variable before re-running this script."
fi

python "$ROOT_DIR/src/Routes/routes.py" --neo4j="$NEO4J_CONNECTION_STRING" --mongodb="$MONGODB_CONNECTION_STRING" --host="$CUSTOM_HOST_FOR_SERVER_BIND" &
python "$ROOT_DIR/src/Routes/routes.py" &
SERVER_PID=$!
cd "$ROOT_DIR/frontend" || ( echo "folder missing " && exit 1 )
if [[ "$RUN_IN_PRODUCTION" != "" ]] ; then
Expand Down
Loading

0 comments on commit b27f5a5

Please sign in to comment.