From 1fa60d11953e073160aef2c9ae3f2b42036e26e6 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 31 Dec 2018 19:14:43 -0500 Subject: fix algo launch script for algo updates python dependencies are mostly installed by ansible now --- bin/algo-config | 4 ++-- bin/helpers/algo-virtualenv | 20 ++++---------------- bin/helpers/launch-algo | 26 +++++++++++++++++++++----- 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'bin') diff --git a/bin/algo-config b/bin/algo-config index 80a8e29..0aa413a 100755 --- a/bin/algo-config +++ b/bin/algo-config @@ -4,7 +4,7 @@ set -o pipefail script_path="$(realpath "$(dirname "$0")")" secrets_bin="${script_path}/secrets" -config_path="$(echo /mnt/algo/algo/configs/*/wireguard)" +config_path="$(echo /mnt/algo/configs/*/wireguard)" "$secrets_bin" open trap '"$secrets_bin" close' EXIT @@ -12,7 +12,7 @@ trap '"$secrets_bin" close' EXIT if [ -z "${VIRTUAL_ENV:-}" ]; then # shellcheck disable=SC1090 . "${script_path}/helpers/algo-virtualenv" - : + python -m pip install segno fi # hush diff --git a/bin/helpers/algo-virtualenv b/bin/helpers/algo-virtualenv index 531873f..efb0c64 100755 --- a/bin/helpers/algo-virtualenv +++ b/bin/helpers/algo-virtualenv @@ -2,21 +2,9 @@ set -eu set -o pipefail -# using tmpdir as a virtualenv because the tozt-secrets filesystem is too small -# to hold the whole python installation -envdir="$(mktemp --tmpdir -d launch-algo.XXXXXXXXXX)" -cleanup() { - if perl -e'exit 1 unless $ARGV[0] =~ m{^/tmp/launch-algo.*$}' "$envdir"; then - rm -rf "$envdir" - fi -} -trap cleanup EXIT - -python2 -m virtualenv --python="$(command -v python2)" "$envdir" +python -m virtualenv --python="$(command -v python2)" env set +eu -# shellcheck disable=SC1090 -. "$envdir"/bin/activate +# shellcheck disable=SC1091 +source env/bin/activate set -eu - -python -m pip install -U pip -python -m pip install -r /mnt/algo/algo/requirements.txt +python -m pip install -U pip virtualenv diff --git a/bin/helpers/launch-algo b/bin/helpers/launch-algo index f926529..3e4c9a7 100755 --- a/bin/helpers/launch-algo +++ b/bin/helpers/launch-algo @@ -5,22 +5,38 @@ set -o pipefail script_path="$(realpath "$(dirname "$0")")" logfile="/mnt/algo/algo-log-$(date +%s).log" latest_logfile=/mnt/algo/algo-log-latest.log +algodir="$(mktemp --tmpdir -d launch-algo.XXXXXXXXXX)" + +cleanup() { + if perl -e'exit 1 unless $ARGV[0] =~ m{^/tmp/launch-algo.*$}' "$algodir"; then + rm -rf "$algodir" + fi +} +trap cleanup EXIT touch "$logfile" ln -sf "$(basename "$logfile")" "$latest_logfile" echo "Logging to $latest_logfile" -cd /mnt/algo/algo -git reset --hard -git clean -dfx -git pull -git apply "${script_path}/algo-config.diff" +git clone git@github.com:trailofbits/algo "$algodir" +cd "$algodir" echo "Installing dependencies..." # shellcheck disable=SC1090 . "${script_path}/algo-virtualenv" >> "$logfile" +python -m pip install -r requirements.txt echo "done." +rm -f configs/.gitinit +rmdir configs +mkdir -p .venvs +rm -rf /mnt/algo/configs +mkdir -p /mnt/algo/configs +ln -sf /mnt/algo/configs configs +ln -sf "$algodir"/.venvs /mnt/algo/configs/.venvs + +git apply "${script_path}/algo-config.diff" + echo "Running Ansible..." do_token=$(cat /mnt/digitalocean) ansible-playbook main.yml -e " -- cgit v1.2.3-54-g00ecf