Repository navigation
Expand file tree
/
Copy pathcheck-server-image.sh
More file actions
executable file
·96 lines (87 loc) · 3 KB
/
Copy pathcheck-server-image.sh
File metadata and controls
executable file
·96 lines (87 loc) · 3 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
#!/usr/bin/env bash
# Builds the sync server's image through the Dokploy compose file, then
# starts it three ways and waits for its `healthcheck` to pass each time: as
# the image's own user, started as root on a root-owned mount, and through the
# compose file on its named volume. The server must run as a user other than
# root, stop cleanly on a terminate signal, and keep its data across a restart
# of the compose project.
#
# scripts/check-server-image.sh
set -euo pipefail
root="$(cd "$(dirname "$0")/.." && pwd)"
compose_file="$root/.dokploy/docker-compose.sync-v2.yml"
image=noura-sync-server
name="noura-sync-check-$$"
project="noura-sync-check-$$"
export NOURA_PUBLIC_ORIGIN=https://sync.example.com
compose() {
docker compose -p "$project" -f "$compose_file" "$@"
}
cleanup() {
docker rm -f "$name" > /dev/null 2>&1 || true
compose down -v > /dev/null 2>&1 || true
}
trap cleanup EXIT
compose config --quiet
compose build
# Waits for the container $1 to pass its health check, as a user other than
# root.
wait_healthy() {
local container="$1" status
for _ in $(seq 1 60); do
status="$(docker inspect --format '{{.State.Health.Status}}' "$container")"
if [ "$status" = healthy ]; then
break
fi
if [ "$status" = unhealthy ]; then
docker logs "$container"
echo "error: the image's health check failed." >&2
exit 1
fi
sleep 1
done
if [ "$status" != healthy ]; then
docker logs "$container"
echo "error: the image never passed its health check." >&2
exit 1
fi
local uid
uid="$(docker exec "$container" awk '/^Uid:/ { print $2 }' /proc/1/status)"
if [ "$uid" = 0 ]; then
echo "error: the server runs as root." >&2
exit 1
fi
docker exec "$container" sync-server healthcheck
}
origin="NOURA_PUBLIC_ORIGIN=$NOURA_PUBLIC_ORIGIN"
docker run -d --name "$name" -e "$origin" "$image" > /dev/null
wait_healthy "$name"
if ! docker exec "$name" grep -q 'webauthn-rs 0.5.5' /usr/share/noura/THIRD_PARTY_NOTICES.txt; then
echo "error: the image lacks the server's notice file." >&2
exit 1
fi
docker rm -f "$name" > /dev/null
docker run -d --name "$name" -e "$origin" --user 0 \
--mount type=tmpfs,destination=/data "$image" > /dev/null
wait_healthy "$name"
docker rm -f "$name" > /dev/null
compose up -d --no-build
container="$(compose ps -q sync-server)"
wait_healthy "$container"
before="$(docker exec "$container" sha256sum /data/server-secret)"
compose stop
exit_code="$(docker inspect --format '{{.State.ExitCode}}' "$container")"
if [ "$exit_code" != 0 ]; then
docker logs "$container"
echo "error: the server exited with $exit_code on a terminate signal." >&2
exit 1
fi
compose down
compose up -d --no-build
container="$(compose ps -q sync-server)"
wait_healthy "$container"
if [ "$(docker exec "$container" sha256sum /data/server-secret)" != "$before" ]; then
echo "error: the data volume lost the server secret across a restart." >&2
exit 1
fi
echo "The image starts on an empty data directory and on the compose volume, as a user other than root."