-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
69 lines (61 loc) · 1.43 KB
/
docker-entrypoint.sh
File metadata and controls
69 lines (61 loc) · 1.43 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
#!/bin/sh
set -e
# Determine Caddy listen address
if [ -n "$TLS_DOMAIN" ]; then
CADDY_ADDRESS="$TLS_DOMAIN"
else
CADDY_ADDRESS=":3000"
fi
# Log format: compact by default, full headers with LOG_VERBOSE=true
if [ "$LOG_VERBOSE" = "true" ]; then
LOG_FORMAT="format json"
else
LOG_FORMAT="format filter {
wrap json
fields {
request>headers delete
resp_headers delete
}
}"
fi
# Generate Caddyfile
cat > /etc/caddy/Caddyfile <<EOF
$CADDY_ADDRESS {
reverse_proxy localhost:3001
encode gzip
log {
output stderr
$LOG_FORMAT
}
}
EOF
# Defaults for zero-config trial — override these at runtime
: "${ADMIN_USERNAME:=admin}"
: "${ADMIN_PASSWORD:=admin}"
export ADMIN_USERNAME ADMIN_PASSWORD
# Default ORIGIN for SvelteKit CSRF protection
if [ -z "$ORIGIN" ]; then
if [ -n "$TLS_DOMAIN" ]; then
export ORIGIN="https://$TLS_DOMAIN"
else
export ORIGIN="http://localhost:3000"
fi
fi
# Start Caddy
caddy run --config /etc/caddy/Caddyfile --adapter caddyfile &
CADDY_PID=$!
# Trap signals for clean shutdown
cleanup() {
kill "$NODE_PID" "$CADDY_PID" 2>/dev/null
wait "$CADDY_PID" 2>/dev/null
exit 0
}
trap cleanup TERM INT
# Start Node.js with restart loop (inline, not a subshell, so NODE_PID is visible to trap)
while true; do
PORT=3001 HOST=127.0.0.1 node build &
NODE_PID=$!
wait "$NODE_PID" || true
echo "[entrypoint] Node.js exited, restarting in 2s..." >&2
sleep 2
done