-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.sh
More file actions
executable file
·108 lines (95 loc) · 3.24 KB
/
run_test.sh
File metadata and controls
executable file
·108 lines (95 loc) · 3.24 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
#!/usr/bin/env bash
set -euo pipefail
# Convenience wrapper to run the isolated test stack under tests/docker-compose.yml.
# Usage: ./run_test.sh [--ci] [--fix-puppeteer] [extra docker compose args]
# Env flags:
# BUILD=0 skip rebuilding images (default: 1)
# KEEP_STACK=1 leave containers/volumes running after tests (default: 0)
# Flags:
# --ci Use CI compose overlay (no source mounts, inline configs) - matches GitHub Actions
# --fix-puppeteer Use linux/amd64 platform for workers (fixes Puppeteer on Apple Silicon)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE_FILE="${ROOT_DIR}/tests/docker-compose.yml"
COMPOSE_CI_FILE="${ROOT_DIR}/tests/docker-compose.ci.yml"
BUILD="${BUILD:-1}"
KEEP_STACK="${KEEP_STACK:-0}"
FIX_PUPPETEER=0
CI_MODE=0
# Parse arguments
EXTRA_ARGS=()
for arg in "$@"; do
case "$arg" in
--ci)
CI_MODE=1
;;
--fix-puppeteer)
FIX_PUPPETEER=1
;;
*)
EXTRA_ARGS+=("$arg")
;;
esac
done
# Build the compose command based on mode
build_compose_files() {
local files="-f ${COMPOSE_FILE}"
if [[ "${CI_MODE}" == "1" ]]; then
files="${files} -f ${COMPOSE_CI_FILE}"
fi
if [[ -n "${COMPOSE_OVERRIDE:-}" ]]; then
files="${files} -f ${COMPOSE_OVERRIDE}"
fi
echo "${files}"
}
compose_cmd() {
eval "docker compose $(build_compose_files)" "$@"
}
UP_ARGS=(up --abort-on-container-exit --force-recreate)
if [[ "${BUILD}" != "0" ]]; then
UP_ARGS+=(--build)
fi
if [[ ${#EXTRA_ARGS[@]} -gt 0 ]]; then
UP_ARGS+=("${EXTRA_ARGS[@]}")
fi
# If --fix-puppeteer is set, use an override compose file for platform
COMPOSE_OVERRIDE=""
if [[ "${FIX_PUPPETEER}" == "1" ]]; then
COMPOSE_OVERRIDE="${ROOT_DIR}/tests/docker-compose.puppeteer-fix.yml"
# Create the override file if it doesn't exist
if [[ ! -f "${COMPOSE_OVERRIDE}" ]]; then
cat > "${COMPOSE_OVERRIDE}" << 'EOF'
# Override file to fix Puppeteer on Apple Silicon (M1/M2/M3)
# Forces workers service to run under linux/amd64 emulation
services:
workers:
platform: linux/amd64
EOF
echo "Created ${COMPOSE_OVERRIDE}"
fi
fi
echo "Using compose file: ${COMPOSE_FILE}"
[[ "${CI_MODE}" == "1" ]] && echo "Using CI overlay: ${COMPOSE_CI_FILE}"
[[ -n "${COMPOSE_OVERRIDE:-}" ]] && echo "Using override file: ${COMPOSE_OVERRIDE}"
echo "BUILD=${BUILD} KEEP_STACK=${KEEP_STACK} FIX_PUPPETEER=${FIX_PUPPETEER} CI_MODE=${CI_MODE}"
# Generate SSL certificates if in CI mode (matches .github/workflows/test.yml)
if [[ "${CI_MODE}" == "1" ]]; then
CERT_DIR="${ROOT_DIR}/tests/fixtures/nginx/certs"
mkdir -p "${CERT_DIR}"
if [[ ! -f "${CERT_DIR}/server.crt" ]] || [[ ! -f "${CERT_DIR}/server.key" ]]; then
echo "Generating test SSL certificates..."
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout "${CERT_DIR}/server.key" -out "${CERT_DIR}/server.crt" \
-subj "/CN=localhost/O=Test/C=US" \
-addext "subjectAltName=DNS:localhost,DNS:nginx-ssl,IP:127.0.0.1" 2>/dev/null || true
fi
fi
echo "Running: docker compose $(build_compose_files) ${UP_ARGS[*]}"
compose_cmd "${UP_ARGS[@]}"
status=$?
if [[ "${KEEP_STACK}" == "0" ]]; then
echo "Bringing down test stack..."
compose_cmd down -v
else
echo "KEEP_STACK=1 set; leaving containers/volumes running."
fi
exit "${status}"