Skip to content

Commit

Permalink
adding an updater for full installs using /opt/venv virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-johnson committed Jun 23, 2018
1 parent ea47bbb commit ba077f3
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 25 deletions.
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ RUN echo "Enabling Rise" \
&& /opt/venv/bin/jupyter-nbextension enable rise --py

RUN ls /opt/antinex/core/ \
&& cp /opt/antinex/core/docker/update-all.sh /opt/antinex/update-all.sh \
&& chmod 777 /opt/antinex/core/docker/update-all.sh \
&& chmod 777 /opt/antinex/update-all.sh \
&& chmod 777 /opt/antinex/core/docker/jupyter/start-container.sh \
&& chmod 777 /opt/antinex/core/run-antinex-core.sh

Expand Down
62 changes: 38 additions & 24 deletions docker/install-on-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,20 @@ else
git pull
fi
fi
if [[ ! -e /opt/spylunking ]]; then
anmt "cloning spylunking logging"
git clone ${transport_prefix}jay-johnson/spylunking.git /opt/spylunking
else
if [[ "${should_update}" == "1" ]]; then
anmt "updating spylunking"
cd /opt/spylunking
git pull
fi
fi

anmt "installing spylunking logger"
cd /opt/spylunking
pip install -e .
anmt "installing pipeline"
cd $install_dir/pipeline
pip install -e .
Expand All @@ -196,32 +209,33 @@ finish_date=$(date +"%Y-%m-%d %H:%M:%S")

if [[ "${should_update}" == "0" ]]; then
anmt "Install finished: ${finish_date}"

echo ""
anmt "Activate virtualenv with command:"
echo "source ${venv}/bin/activate"

echo ""
anmt "Set your bashrc alias by running these commands in your shell:"
echo ""
echo "echo \"\" >> ~/.bashrc"
echo "echo '###################################' >> ~/.bashrc"
echo "echo '#' >> ~/.bashrc"
echo "echo '# AntiNex nav aliases' >> ~/.bashrc"
echo "echo '#' >> ~/.bashrc"

echo "echo 'alias api=\"cd /opt/antinex/api && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias core=\"cd /opt/antinex/core && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias client=\"cd /opt/antinex/client && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias dbmigrate=\"source ~/.venvs/venvdrfpipeline/bin/activate && source /opt/antinex/api/envs/drf-dev.env && cd /opt/antinex/api && ./run-migrations.sh\"' >> ~/.bashrc"
echo "echo 'alias dev=\"cd /opt/antinex/api && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias docs=\"cd /opt/antinex/api/webapp/drf_network_pipeline/docs && source ~/.venvs/venvdrfpipeline/bin/activate && make html\"' >> ~/.bashrc"
echo "echo 'alias pipeline=\"cd /opt/antinex/pipeline && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias sqlmigrate=\"source ~/.venvs/venvdrfpipeline/bin/activate && source /opt/antinex/api/envs/dev.env && cd /opt/antinex/api && ./run-migrations.sh\"' >> ~/.bashrc"
echo "echo 'alias spylunk=\"source ~/.venvs/venvdrfpipeline/bin/activate && cd /opt/spylunking && pip install -e .\"' >> ~/.bashrc"
echo "echo 'alias run=\"source ~/.venvs/venvdrfpipeline/bin/activate && source /opt/antinex/api/envs/dev.env && cd /opt/antinex/api/webapp && python manage.py runserver 0.0.0.0:8080\"' >> ~/.bashrc"
echo "echo 'alias utils=\"cd /opt/antinex/utils && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
else
anmt "Update finished: ${finish_date}"
fi

echo ""
anmt "Activate virtualenv with command:"
echo "source ${venv}/bin/activate"

echo ""
anmt "Set your bashrc alias by running these commands in your shell:"
echo ""
echo "echo \"\" >> ~/.bashrc"
echo "echo '###################################' >> ~/.bashrc"
echo "echo '#' >> ~/.bashrc"
echo "echo '# AntiNex nav aliases' >> ~/.bashrc"
echo "echo '#' >> ~/.bashrc"

echo "echo 'alias dev=\"cd /opt/antinex/api && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias api=\"cd /opt/antinex/api && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias core=\"cd /opt/antinex/core && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias client=\"cd /opt/antinex/client && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias pipeline=\"cd /opt/antinex/pipeline && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias utils=\"cd /opt/antinex/utils && source ~/.venvs/venvdrfpipeline/bin/activate\"' >> ~/.bashrc"
echo "echo 'alias docs=\"cd /opt/antinex/api/webapp/drf_network_pipeline/docs && source ~/.venvs/venvdrfpipeline/bin/activate && make html\"' >> ~/.bashrc"
echo "echo 'alias run=\"source ~/.venvs/venvdrfpipeline/bin/activate && source /opt/antinex/api/envs/dev.env && cd /opt/antinex/api/webapp && python manage.py runserver 0.0.0.0:8080\"' >> ~/.bashrc"
echo "echo 'alias sqlmigrate=\"source ~/.venvs/venvdrfpipeline/bin/activate && source /opt/antinex/api/envs/dev.env && cd /opt/antinex/api && ./run-migrations.sh\"' >> ~/.bashrc"
echo "echo 'alias dbmigrate=\"source ~/.venvs/venvdrfpipeline/bin/activate && source /opt/antinex/api/envs/drf-dev.env && cd /opt/antinex/api && ./run-migrations.sh\"' >> ~/.bashrc"

exit 0
108 changes: 108 additions & 0 deletions docker/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

default_venv="/opt/venv"
venv=${default_venv}
if [[ "${1}" != "" ]]; then
venv="${1}"
fi

activate_path=$(echo ${venv} | grep activate | wc -l)
if [[ "${activate_path}" == "0" ]]; then
venv=${venv}/bin/activate
fi

if [[ ! -f "${venv}" ]]; then
venv=${default_venv}
echo "creating virtualenv: ${venv}"
virtualenv -p python3 ${venv}
if [[ "$?" != "0" ]]; then
echo "Failed creating virtualenv ${venv} with command:"
echo ""
echo "virtualenv -p python3 ${venv}"
echo ""
exit 1
fi
venv=${default_venv}/bin/activate
fi

echo "loading venv: ${venv}"
. ${venv}
if [[ "$?" != "0" ]]; then
echo " - failed loading virtualenv: ${venv}"
echo ""
echo ". ${venv}"
echo ""
exit 1
fi

# the install order matters to prevent pips getting installed from the local directories instead of pulling from pypi
org_dir=$(pwd)
repos="/opt/spylunking /opt/antinex/utils /opt/antinex/pipeline /opt/antinex/client /opt/antinex/core /opt/antinex/api /opt/antinex/antinex-datasets /opt/antinex/datasets"
for d in ${repos}; do
echo ""
if [[ ! -e ${d} ]]; then
repo_url=""
if [[ "${d}" == "/opt/antinex/antinex-datasets" ]]; then
repo_url="https://github.com/jay-johnson/antinex-datasets.git"
elif [[ "${d}" == "/opt/antinex/api" ]]; then
repo_url="https://github.com/jay-johnson/train-ai-with-django-swagger-jwt.git"
elif [[ "${d}" == "/opt/antinex/client" ]]; then
repo_url="https://github.com/jay-johnson/antinex-client.git"
elif [[ "${d}" == "/opt/antinex/core" ]]; then
repo_url="https://github.com/jay-johnson/antinex-core.git"
elif [[ "${d}" == "/opt/antinex/datasets" ]]; then
repo_url="https://github.com/jay-johnson/network-pipeline-datasets.git"
elif [[ "${d}" == "/opt/antinex/pipeline" ]]; then
repo_url="https://github.com/jay-johnson/network-pipeline.git"
elif [[ "${d}" == "/opt/antinex/utils" ]]; then
repo_url="https://github.com/jay-johnson/antinex-utils.git"
elif [[ "${d}" == "/opt/spylunking" ]]; then
repo_url="https://github.com/jay-johnson/spylunking"
else
echo "Unknown directory: ${d}"
repo_url=""
fi

if [[ "${repo_url}" != "" ]]; then
echo ""
echo "cloning project: ${d}"
git clone ${repo_url} ${d}
if [[ "$?" != "0" ]]; then
echo ""
echo "Failed cloning project: ${d} with command:"
echo "git clone ${repo_url} ${d}"
echo ""
exit 1
fi
fi
fi
cd $d
if [[ -e .git/config ]]; then
echo " - pulling latest"
git pull
if [[ "$?" != "0" ]]; then
echo ""
echo "Failed to update: ${d}"
echo "cd ${d} && git pull"
echo ""
fi
fi
if [[ -e setup.py ]]; then
echo " - installing"
pip install -e .
if [[ "$?" != "0" ]]; then
echo ""
echo "Failed to install latest: ${d}"
echo "cd ${d} && pip install -e ."
echo ""
fi
fi
done

cd ${org_dir}
echo ""
echo "load the updated virtualenv with:"
echo ". ${venv}"
echo ""
echo "done"
exit 0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def run_tests(self):
setup(
name="antinex-core",
cmdclass={"test": PyTest},
version="1.0.53",
version="1.0.54",
description=("AntiNex publisher-subscriber core for processing "
"training and prediction requests for deep neural "
"networks to detect network exploits using Keras "
Expand Down

0 comments on commit ba077f3

Please sign in to comment.