-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose-stack.sh
More file actions
executable file
·281 lines (251 loc) · 8.96 KB
/
Copy pathcompose-stack.sh
File metadata and controls
executable file
·281 lines (251 loc) · 8.96 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/env bash
# Wrapper for docker compose: correct --env-file, -f paths, and project name from repo root.
# See run/README.md and per-stack READMEs under run/docker-compose/.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
TRAEFIK_OVERLAY=0
WITH_OBS=0
WITH_AUTH=0
DATA_DIR=""
usage() {
cat <<EOF
Usage: $(basename "$0") [options] <stack> <compose-subcommand> [arguments...]
Run from any directory; paths are resolved relative to the repository clone.
Stacks:
minimal run/docker-compose/minimal/docker-compose.yml
traefik run/docker-compose/traefik/docker-compose.yml (project: gghstats-edge)
observability run/docker-compose/observability/docker-compose.observability.yml (project: gghstats-obs)
authelia run/docker-compose/authelia/docker-compose.authelia.yml (project: gghstats-auth)
prod Traefik + gghstats only: up | down | restart (no ordering puzzle for a single compose file)
full Same as --with-obs prod: Traefik + gghstats, then observability
Add --with-auth for Authelia on top of Traefik + gghstats (portal at /auth)
Add --with-obs --with-auth for all three stacks (Traefik + gghstats + observability + Authelia)
For Traefik + gghstats + observability on the shared Docker network (gghstats_edge):
start the traefik stack first, then observability. The observability stack does not
start Traefik or gghstats; the observability Traefik overlay adds Grafana behind your edge.
Order-safe shortcuts (subcommands: up | down | restart only):
prod up -d → traefik up -d
prod restart → traefik restart
full up -d → traefik up -d, then observability (+ Traefik overlay) up -d
full down → observability down, then traefik down
full restart → traefik restart, then observability restart
--with-obs prod … → same as full … (for users who prefer a flag over the "full" name)
Options:
--data-dir DIR Set GGHSTATS_HOST_DATA for this invocation (otherwise use env GGHSTATS_HOST_DATA)
--with-obs (prod only; place before "prod") Same as stack "full" — include observability in the ordered steps
--with-auth (prod only; place before "prod") Include Authelia SSO (portal at /auth)
--traefik (observability only) Also load docker-compose.observability.traefik.yml (Grafana via Traefik)
-h, --help Show this help
Environment:
GGHSTATS_HOST_DATA Host directory for operator files (required):
- minimal, traefik: \${GGHSTATS_HOST_DATA}/.env
- observability: \${GGHSTATS_HOST_DATA}/.env.observability
Examples:
export GGHSTATS_HOST_DATA=/home/gghstats/gghstats-data
$(basename "$0") minimal up -d
$(basename "$0") traefik down
$(basename "$0") traefik restart
# Traefik only, or Traefik + observability (typical production with metrics stack):
$(basename "$0") prod restart
$(basename "$0") full restart
$(basename "$0") full up -d
$(basename "$0") --with-obs prod up -d # equivalent to: full up -d
# Manual order (same as "full"):
$(basename "$0") traefik up -d
$(basename "$0") --traefik observability up -d
$(basename "$0") observability logs grafana -f
Note: After changing GGHSTATS_VERSION in .env — pull the image from GHCR, then traefik up -d (not restart). restart does not apply a new tag.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--with-obs)
WITH_OBS=1
shift
;;
--with-auth)
WITH_AUTH=1
shift
;;
--traefik)
TRAEFIK_OVERLAY=1
shift
;;
--data-dir)
[[ -n "${2:-}" ]] || {
echo "error: --data-dir requires a path" >&2
exit 1
}
DATA_DIR="$2"
shift 2
;;
-h | --help)
usage
exit 0
;;
*)
break
;;
esac
done
if [[ -n "$DATA_DIR" ]]; then
export GGHSTATS_HOST_DATA="$DATA_DIR"
fi
if [[ -z "${GGHSTATS_HOST_DATA:-}" ]]; then
echo "error: set GGHSTATS_HOST_DATA or pass --data-dir DIR" >&2
usage >&2
exit 1
fi
if [[ $# -lt 2 ]]; then
echo "error: expected <stack> <compose-subcommand> [...]" >&2
usage >&2
exit 1
fi
STACK="$1"
shift
if [[ "$STACK" == "full" ]]; then
WITH_OBS=1
STACK=prod
fi
if [[ "$WITH_OBS" -eq 1 && "$STACK" != "prod" ]]; then
echo "error: --with-obs applies only to stack prod (or use stack: full for Traefik + observability)" >&2
exit 1
fi
COMPOSE_SUBCMD="$1"
shift
MAIN_ENV="${GGHSTATS_HOST_DATA}/.env"
OBS_ENV="${GGHSTATS_HOST_DATA}/.env.observability"
TRAEFIK_COMPOSE_FILE="$ROOT/run/docker-compose/traefik/docker-compose.yml"
TRAEFIK_PROJECT=gghstats-edge
compose_traefik() {
docker compose --env-file "$MAIN_ENV" -p "$TRAEFIK_PROJECT" \
-f "$TRAEFIK_COMPOSE_FILE" "$@"
}
compose_authelia() {
docker compose --env-file "$MAIN_ENV" -p gghstats-auth \
-f "$ROOT/run/docker-compose/authelia/docker-compose.authelia.yml" "$@"
}
# Pre-0.1.20 stacks used Compose project "traefik" (directory name) and/or container_name traefik|gghstats.
compose_traefik_legacy_teardown() {
local down_args=("$@")
local legacy_projects=(traefik gghstats-selfhosted)
local proj
for proj in "${legacy_projects[@]}"; do
if docker compose --env-file "$MAIN_ENV" -p "$proj" -f "$TRAEFIK_COMPOSE_FILE" ps -q 2>/dev/null | grep -q .; then
echo "Stopping legacy Compose project: $proj"
docker compose --env-file "$MAIN_ENV" -p "$proj" -f "$TRAEFIK_COMPOSE_FILE" \
down --remove-orphans "${down_args[@]}"
fi
done
local c
for c in traefik gghstats; do
if docker ps -a --format '{{.Names}}' | grep -Fxq "$c"; then
echo "Removing legacy container: $c (pre-${TRAEFIK_PROJECT} fixed container_name)"
docker rm -f "$c" || true
fi
done
}
compose_obs_traefik_overlay() {
docker compose --env-file "$OBS_ENV" -p gghstats-obs \
-f "$ROOT/run/docker-compose/observability/docker-compose.observability.yml" \
-f "$ROOT/run/docker-compose/observability/docker-compose.observability.traefik.yml" "$@"
}
COMPOSE_ARGS=()
case "$STACK" in
prod)
[[ -f "$MAIN_ENV" ]] || {
echo "error: missing main env file: $MAIN_ENV" >&2
exit 1
}
case "$COMPOSE_SUBCMD" in
up | down | restart) ;;
*)
echo "error: stack prod only supports compose subcommands up, down, restart (got: $COMPOSE_SUBCMD)" >&2
exit 1
;;
esac
if [[ "$WITH_OBS" -eq 1 ]]; then
[[ -f "$OBS_ENV" ]] || {
echo "error: missing observability env file: $OBS_ENV (required for --with-obs / stack full)" >&2
exit 1
}
fi
cd "$ROOT"
case "$COMPOSE_SUBCMD" in
up)
compose_traefik up "$@"
if [[ "$WITH_OBS" -eq 1 ]]; then
compose_obs_traefik_overlay up "$@"
fi
if [[ "$WITH_AUTH" -eq 1 ]]; then
compose_authelia up "$@"
fi
;;
down)
if [[ "$WITH_AUTH" -eq 1 ]]; then
compose_authelia down "$@"
fi
if [[ "$WITH_OBS" -eq 1 ]]; then
compose_obs_traefik_overlay down "$@"
fi
compose_traefik down "$@"
compose_traefik_legacy_teardown "$@"
;;
restart)
compose_traefik restart "$@"
if [[ "$WITH_OBS" -eq 1 ]]; then
compose_obs_traefik_overlay restart "$@"
fi
if [[ "$WITH_AUTH" -eq 1 ]]; then
compose_authelia restart "$@"
fi
;;
esac
exit 0
;;
minimal)
[[ -f "$MAIN_ENV" ]] || {
echo "error: missing main env file: $MAIN_ENV" >&2
exit 1
}
COMPOSE_ARGS+=(--env-file "$MAIN_ENV" -f "$ROOT/run/docker-compose/minimal/docker-compose.yml")
;;
traefik)
[[ -f "$MAIN_ENV" ]] || {
echo "error: missing main env file: $MAIN_ENV" >&2
exit 1
}
COMPOSE_ARGS+=(--env-file "$MAIN_ENV" -p "$TRAEFIK_PROJECT" -f "$TRAEFIK_COMPOSE_FILE")
;;
observability)
[[ -f "$OBS_ENV" ]] || {
echo "error: missing observability env file: $OBS_ENV" >&2
exit 1
}
COMPOSE_ARGS+=(--env-file "$OBS_ENV" -p gghstats-obs -f "$ROOT/run/docker-compose/observability/docker-compose.observability.yml")
if [[ "$TRAEFIK_OVERLAY" -eq 1 ]]; then
COMPOSE_ARGS+=(-f "$ROOT/run/docker-compose/observability/docker-compose.observability.traefik.yml")
fi
;;
authelia)
[[ -f "$MAIN_ENV" ]] || {
echo "error: missing main env file: $MAIN_ENV" >&2
exit 1
}
COMPOSE_ARGS+=(--env-file "$MAIN_ENV" -p gghstats-auth -f "$ROOT/run/docker-compose/authelia/docker-compose.authelia.yml")
;;
*)
echo "error: unknown stack: $STACK (use minimal, traefik, observability, authelia, prod, or full)" >&2
usage >&2
exit 1
;;
esac
if [[ "$STACK" != "observability" && "$TRAEFIK_OVERLAY" -eq 1 ]]; then
echo "error: --traefik applies only to the observability stack" >&2
exit 1
fi
cd "$ROOT"
docker compose "${COMPOSE_ARGS[@]}" "$COMPOSE_SUBCMD" "$@"
if [[ "$STACK" == "traefik" && "$COMPOSE_SUBCMD" == "down" ]]; then
compose_traefik_legacy_teardown "$@"
fi