This repository has been archived by the owner on Sep 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runme.sh
executable file
·91 lines (83 loc) · 2.83 KB
/
runme.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
__repo=$(cd $(dirname ${BASH_SOURCE[0]}); pwd -P)
VM_BRANCH=${VM_BRANCH:-main}
###
# Check for .env
cd ${__repo}
if test -e ${__repo}/.env; then
. ${__repo}/.env # source our config
else
echo "Configuring .env"
read -p "Cardano network [mainnet|preview]: " CARDANO_NETWORK
read -p "VM API token: " VM_API_TOKEN
read -p "Cloudflare Pre-Shared Key (optional): " CLOUDFLARE_PSK
read -p "DataDog API key (optional): " DD_API_KEY
if test -z "${CARDANO_NETWORK}"; then
CARDANO_NETWORK=preview
fi
if test -z "${VM_API_TOKEN}"; then
echo "You must give an API token!"
exit 1
fi
KOIOS_URL=https://preview.koios.rest/api/v1
VM_URL=https://vmprev.adaseal.eu
if test "${CARDANO_NETWORK}" == "mainnet"; then
KOIOS_URL=https://koios.rest/api/v1
VM_URL=https://vm.adaseal.eu
fi
echo "VM_BRANCH=${VM_BRANCH}" > ${__repo}/.env
echo "CARDANO_NETWORK=${CARDANO_NETWORK}" >> ${__repo}/.env
echo "KOIOS_URL=${KOIOS_URL}" >> ${__repo}/.env
echo "VM_URL=${VM_URL}" >> ${__repo}/.env
echo "VM_API_TOKEN=${VM_API_TOKEN}" >> ${__repo}/.env
if test -n "${CLOUDFLARE_PSK}"; then
echo "CLOUDFLARE_PSK=${CLOUDFLARE_PSK}" >> ${__repo}/.env
fi
if test -n "${DD_API_KEY}"; then
echo "DD_API_KEY=${DD_API_KEY}" >> ${__repo}/.env
fi
. ${__repo}/.env # source our config
fi
###
# Check for updates
cd ${__repo}
git fetch --tags origin && git merge --ff-only origin/${VM_BRANCH}
# Install python3-virtualenv on debian-likes
if [[ $(type -P dpkg) ]]; then
if dpkg -L python3-venv >/dev/null 2>&1; then
echo "Package python3-venv found"
else
echo "Installing python3-venv"
sudo apt-get update && sudo apt-get install -y python3-venv
fi
fi
# Create our virtualenv, if needed
python3 -m venv ${__repo}/.venv
if [[ $? -ne 0 ]]; then
echo "Cannot create Python virtualenv! Ensure virtualenv is available in your python environment"
exit 1
fi
# From here on out, bail on failure
set -e
. ${__repo}/.venv/bin/activate
pip install ansible==5.1.0 docker requests
ansible-galaxy install -r ${__repo}/ansible/requirements.yml
ansible-playbook ${__repo}/ansible/local.yml \
-e REPO=${__repo} \
-e DD_API_KEY=${DD_API_KEY:-changeme} \
-e DOCKER_USERS=${DOCKER_USERS:-ubuntu} \
-e MANAGE_DATADOG=${MANAGE_DATADOG:-false} \
-e MANAGE_DOCKER=${MANAGE_DOCKER:-true} \
-e vm_frontend_version=${VM_IMAGE_TAG:-${VM_BRANCH}} \
-e vm_frontend_port=${VM_PORT:-3000} \
-e ansible_python_interpreter=${__repo}/.venv/bin/python3 \
--diff \
-c local \
--inventory 127.0.0.1, # this trailing comma is required
# Don't fail on errors, we're going to clean container images, there may be none
set +e
# Find images from our repo tagged as <none> (orphaned layers)
echo "Cleaning up leftover Docker images"
docker images | grep '<none>' | grep 'ghcr.io/blinklabs-io/discoin-vm-frontend' | awk '{print $3}' | xargs docker rmi &>/dev/null
# Don't exit w/ 1 if above fails
exit 0