-
Notifications
You must be signed in to change notification settings - Fork 0
/
athena-docker.sh
149 lines (124 loc) · 4.2 KB
/
athena-docker.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
# check if environment variable configuration exists
if [ ! -d athena-env ]; then
echo "No athena-env directory found. Please create a copy of https://github.com/ls1intum/Athena/tree/develop/env_example with real secrets called "athena-env" and try again."
exit 1
fi
# heavily inspired by https://github.com/ls1intum/artemis-ansible-collection/blob/20b000d7601735e6916e225b5cea41b960d51197/roles/artemis/templates/artemis-docker.sh.j2#L4
# Function: Print general usage information
function general_help {
cat << HELP
Usage:
./$(basename "$0") <command> [options]
Commands:
start <pr_tag> <pr_branch> <domain> Start Athena
stop Stop the Athena server.
restart <pr_tag> <pr_branch> <domain> Restart the Athena server.
run <docker compose cmd> Run any docker compose subcommand of your choice
cleanup Remove old docker images
HELP
}
function download_docker_compose {
local pr_branch=$1
echo "Downloading docker compose files..."
for file in docker-compose.prod.yml docker-compose.cofee.yml docker-compose.playground.prod.yml; do
echo " Downloading $file..."
curl -sSL -o "$file" https://raw.githubusercontent.com/ls1intum/Athena/"$pr_branch"/"$file"
done
}
function download_cofee_config {
local pr_branch=$1
echo "Downloading Cofee config files into ./module_text_cofee..."
mkdir -p ./module_text_cofee
for file in traefik.docker.yml node_config.docker.yml; do
echo " Downloading $file..."
curl -sSL -o ./module_text_cofee/$file https://raw.githubusercontent.com/ls1intum/Athena/"$pr_branch"/modules/text/module_text_cofee/"$file"
done
}
function download_caddyfile {
local pr_branch=$1
echo "Downloading Caddyfile..."
curl -sSL -o Caddyfile https://raw.githubusercontent.com/ls1intum/Athena/"$pr_branch"/Caddyfile
}
function download_postgres_init {
local pr_branch=$1
echo "Downloading postgres-init.sql..."
curl -sSL -o postgres-init.sql https://raw.githubusercontent.com/ls1intum/Athena/"$pr_branch"/postgres-init.sql
}
function start {
local pr_tag=$1
local pr_branch=$2
local domain=$3
download_docker_compose "$pr_branch"
download_cofee_config "$pr_branch"
download_caddyfile "$pr_branch"
download_postgres_init "$pr_branch"
echo "Starting Athena with PR tag: $pr_tag and branch: $pr_branch"
export ATHENA_ENV_DIR="$(pwd)/athena-env"
export ATHENA_TAG="$pr_tag"
export ATHENA_DOMAIN="$domain"
docker compose -f docker-compose.prod.yml -f docker-compose.playground.prod.yml -f docker-compose.cofee.yml up -d --pull always --no-build
}
function stop {
local pr_tag=$1
local pr_branch=$2
local domain=$3
echo "Stopping Athena"
export ATHENA_ENV_DIR="$(pwd)/athena-env"
export ATHENA_TAG="$pr_tag"
export ATHENA_DOMAIN="$domain"
docker compose -f docker-compose.prod.yml -f docker-compose.playground.prod.yml -f docker-compose.cofee.yml stop
}
function restart {
stop "$@"
start "$@"
}
function short_logs {
docker compose -f docker-compose.prod.yml -f docker-compose.playground.prod.yml -f docker-compose.cofee.yml logs -f --tail 1000
}
function all_logs {
docker compose -f docker-compose.prod.yml -f docker-compose.playground.prod.yml -f docker-compose.cofee.yml logs -f
}
function cleanup {
docker image prune -a -f # remove all unused images
}
function run_docker_compose_cmd {
export ATHENA_ENV_DIR="$(pwd)/athena-env"
export ATHENA_TAG="$pr_tag"
docker compose -f docker-compose.prod.yml -f docker-compose.playground.prod.yml -f docker-compose.cofee.yml "$@"
}
# read subcommand `athena-docker subcommand server` in variable and remove base command from argument list
subcommand=$1; shift
# Handle empty subcommand
if [ -z "$subcommand" ]; then
general_help
exit 1
fi
case "$subcommand" in
start)
start "$@"
;;
stop)
stop "$@"
;;
restart)
restart "$@"
;;
logs-short)
short_logs "$@"
;;
logs)
all_logs "$@"
;;
cleanup)
cleanup "$@"
;;
run)
run_docker_compose_cmd "$@"
;;
*)
printf "Invalid Command: $subcommand\n\n" 1>&2
general_help
exit 1
;;
esac