summaryrefslogtreecommitdiffstats
path: root/bin/helpers/launch-algo
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-10-16 04:25:09 -0400
committerJesse Luehrs <doy@tozt.net>2018-10-16 04:25:09 -0400
commitbd4b8406ddf02f6223fc1f508c4102d42765ead7 (patch)
tree50262362fe8b1ac1577d3aa9144e5099c4c312e7 /bin/helpers/launch-algo
parentd78e3fe6779b8bccfcc3c05bb5c601de6ffa45ef (diff)
downloadpuppet-tozt-bd4b8406ddf02f6223fc1f508c4102d42765ead7.tar.gz
puppet-tozt-bd4b8406ddf02f6223fc1f508c4102d42765ead7.zip
support managing algo instances
Diffstat (limited to 'bin/helpers/launch-algo')
-rwxr-xr-xbin/helpers/launch-algo60
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/helpers/launch-algo b/bin/helpers/launch-algo
new file mode 100755
index 0000000..06260b7
--- /dev/null
+++ b/bin/helpers/launch-algo
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+set -eu
+set -o pipefail
+
+script_path="$(realpath "$(dirname "$0")")"
+secrets_bin="${script_path}/../secrets"
+
+"$secrets_bin" open
+
+cd /mnt/algo/algo
+git reset --hard
+git clean -dfx
+git pull
+git apply "${script_path}/algo-config.diff"
+
+# 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
+
+ cd
+ "$secrets_bin" close
+}
+trap cleanup EXIT
+
+python2 -m virtualenv --python="$(command -v python2)" "$envdir"
+set +eu
+# shellcheck disable=SC1090
+. "$envdir"/bin/activate
+set -eu
+
+logfile="/mnt/algo/algo-log-$(date +%s).log"
+latest_logfile=/mnt/algo/algo-log-latest.log
+touch "$logfile"
+ln -sf "$(basename "$logfile")" "$latest_logfile"
+echo "Logging to $latest_logfile"
+
+echo "Installing dependencies..."
+python -m pip install -U pip >> "$logfile"
+python -m pip install -r requirements.txt >> "$logfile"
+echo "done."
+
+echo "Running Ansible..."
+do_token=$(cat /mnt/algo/algo-digitalocean)
+ansible-playbook main.yml -e "
+ provider=digitalocean
+ server_name=algo
+ ondemand_cellular=false
+ ondemand_wifi=false
+ local_dns=false
+ ssh_tunneling=true
+ windows=false
+ store_cakey=true
+ region=nyc3
+ do_token=$do_token
+" >> "$logfile"
+echo "done."