-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·81 lines (69 loc) · 3.8 KB
/
setup.sh
File metadata and controls
executable file
·81 lines (69 loc) · 3.8 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
#!/usr/bin/env bash
set -euo pipefail
# Export host UID/GID so docker-compose can run test containers as the host user.
# Prevents root-owned files in ./shared (e.g. api_test.log) that would break cleanup.
# (We don't export UID + GID since they are used in bash as read only vars)
export HOST_UID="$(id -u)"
export HOST_GID="$(id -g)"
# ==============================================================================
# Docker Exam Pipeline Runner
# - Project: docker-exam
# - Purpose: one-command, reproducible run for the exam submission artifacts
#
# What this script does (high level):
# 1) Resets to a clean state (stops compose project, removes stray "api", frees port 8000)
# 2) Starts the compose stack (API + test container(s))
# 3) Waits for the auth test container to finish
# 4) Prints auth test logs to the terminal (for quick verification)
# 5) Copies the aggregated shared log to ./log.txt (exam requirement)
# 6) Shuts everything down again (avoids port/container conflicts on rerun)
# ==============================================================================
PROJECT_NAME="docker-exam"
TIMESTAMP_FMT="+%Y-%m-%d %H:%M:%S"
printf '\n========================================================================================\n'
printf ' *** Docker Exam Pipeline (project: %s) — START %s ***\n' "${PROJECT_NAME}" "$(date "${TIMESTAMP_FMT}")"
printf '========================================================================================\n'
# ------------------------------------------------------------------------------
# 1) Clean start (idempotent)
# - make reset:
# - stops compose project (if running)
# - removes stray container named "api" (if it exists)
# - frees host port 8000 (if any container publishes it)
# ------------------------------------------------------------------------------
make reset
# ------------------------------------------------------------------------------
# 2) Start stack (detached) + show status
# - make start-project: docker compose up -d
# - make ps: docker compose ps
# ------------------------------------------------------------------------------
make start-project
make ps
# ------------------------------------------------------------------------------
# 3) Run + wait for authentication tests + show logs
# - make wait-auth: blocks until auth_test exits (exit code drives pipeline)
# - make logs-auth: prints last lines of auth_test logs for visibility
# ------------------------------------------------------------------------------
make wait-auth
make logs-auth
# ------------------------------------------------------------------------------
# 3) Run + wait for authorization tests + show logs
# ------------------------------------------------------------------------------
make wait-authz
make logs-authz
# ------------------------------------------------------------------------------
# 4) Run + wait for content tests + show logs
# ------------------------------------------------------------------------------
make wait-content
make logs-content
# ------------------------------------------------------------------------------
# 4) Create submission snapshot log.txt (exam requirement)
# - shared/api_test.log is written by the test container when LOG=1
# ------------------------------------------------------------------------------
make snapshot-log
# ------------------------------------------------------------------------------
# 5) Shutdown (keeps reruns conflict-free)
# ------------------------------------------------------------------------------
make stop-all
printf '========================================================================================\n'
printf ' *** Docker Exam Pipeline (project: %s) — END %s ***\n' "${PROJECT_NAME}" "$(date "${TIMESTAMP_FMT}")"
printf '========================================================================================\n\n'