summaryrefslogtreecommitdiffstats
path: root/bin/helpers/launch-algo
blob: bf8937bea47afb7e688e25104aff0275a6df00a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -eu
set -o pipefail

script_path="$(realpath "$(dirname "$0")")"

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
}
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/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."