-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
91 lines (81 loc) · 2.93 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
91 lines (81 loc) · 2.93 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
#!/bin/bash
# Docker entrypoint script for Registry services
# Determines which service to start based on SERVICE_TYPE environment variable
set -e
# Function to deploy database schema (only for web service)
deploy_schema() {
echo "Deploying database schema..."
# Use SQITCH_TARGET if set, otherwise derive from DB_URL.
# Sqitch requires db:pg:// URIs, not postgresql:// — convert if needed.
local target="${SQITCH_TARGET:-$DB_URL}"
target="${target/#postgresql:/db:pg:}"
if [ -n "$target" ]; then
# Log the target with the password masked. The previous form
# (${target%%@*}@****) kept everything *before* the @, leaking
# user:password into the deploy logs. Mask just the password.
echo "Using sqitch target: $(echo "$target" | sed -E 's#(://[^:/@]+):[^@]*@#\1:****@#')"
if sqitch deploy "$target"; then
echo "Database schema deployed successfully"
else
echo "Warning: Database schema deployment failed"
fi
else
echo "Error: SQITCH_TARGET environment variable not set"
return 1
fi
echo "Importing workflows and templates..."
if ./registry workflow import registry; then
echo "Workflows imported successfully"
else
echo "Warning: Workflow import failed"
fi
if ./registry template import registry; then
echo "Templates imported successfully"
else
echo "Warning: Template import failed"
fi
}
case "${SERVICE_TYPE:-web}" in
"web")
echo "Starting web service..."
deploy_schema
# Start the server in the background
./registry daemon -l "http://*:${PORT:-10000}" &
SERVER_PID=$!
# Wait for the server to be ready
echo "Waiting for server to be ready..."
for i in $(seq 1 30); do
if curl -sf "http://localhost:${PORT:-10000}/health" > /dev/null 2>&1; then
echo "Server is ready"
break
fi
sleep 1
done
# Run post-deploy smoke test against the live URL
# Failure kills the server so Render rolls back the deploy
if [ -f bin/post-deploy-smoke-test.sh ] && [ -n "$BASE_URL" ]; then
echo "Running post-deploy smoke test..."
if ! bash bin/post-deploy-smoke-test.sh; then
echo "FATAL: Smoke test failed -- killing server to trigger rollback"
kill $SERVER_PID
exit 1
fi
fi
# Wait for the server process
wait $SERVER_PID
;;
"worker")
echo "Starting worker service..."
exec ./registry minion worker
;;
"scheduler")
echo "Starting scheduler tasks..."
./registry job attendance_check
./registry job waitlist_expiration
;;
*)
echo "Unknown SERVICE_TYPE: ${SERVICE_TYPE}"
echo "Valid options: web, worker, scheduler"
exit 1
;;
esac