Skip to content

Commit 070d7e4

Browse files
committed
ci: wait for container health in smoke test
1 parent a6ecd05 commit 070d7e4

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

.github/workflows/verify.yml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ jobs:
5656
5757
- name: Smoke-test image
5858
run: |
59+
set -Eeuo pipefail
60+
61+
cleanup() {
62+
status=$?
63+
if [ "$status" -ne 0 ]; then
64+
echo "::group::Atomic Sync smoke-test diagnostics"
65+
docker ps --all --filter name=atomic-sync-ci || true
66+
docker inspect --format 'state={{.State.Status}} exit={{.State.ExitCode}} error={{json .State.Error}} health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' atomic-sync-ci || true
67+
docker inspect --format '{{range .State.Health.Log}}{{println .Start "exit=" .ExitCode "output=" .Output}}{{end}}' atomic-sync-ci || true
68+
docker logs --timestamps atomic-sync-ci || true
69+
echo "::endgroup::"
70+
fi
71+
docker rm --force atomic-sync-ci >/dev/null 2>&1 || true
72+
exit "$status"
73+
}
74+
trap cleanup EXIT
75+
5976
docker run --detach --name atomic-sync-ci \
6077
--read-only \
6178
--tmpfs /tmp:rw,nosuid,nodev,noexec,size=64m \
@@ -64,11 +81,40 @@ jobs:
6481
--publish 127.0.0.1:18088:8080 \
6582
--env ATOMIC_API_TOKEN=${{ github.sha }} \
6683
atomic-sync:test
67-
trap 'docker logs atomic-sync-ci; docker rm --force atomic-sync-ci' EXIT
68-
for attempt in $(seq 1 30); do
69-
if curl --fail --silent http://127.0.0.1:18088/api/ready; then break; fi
84+
85+
ready_status=unavailable
86+
health_status=starting
87+
container_status=created
88+
for attempt in $(seq 1 90); do
89+
if curl --fail --silent --show-error --max-time 2 http://127.0.0.1:18088/api/ready >/dev/null 2>&1; then
90+
ready_status=ready
91+
else
92+
ready_status=unavailable
93+
fi
94+
container_status="$(docker inspect --format '{{.State.Status}}' atomic-sync-ci)"
95+
health_status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' atomic-sync-ci)"
96+
97+
if [ "$ready_status" = ready ] && [ "$health_status" = healthy ]; then
98+
echo "Atomic Sync became ready and healthy after ${attempt}s"
99+
break
100+
fi
101+
case "$container_status" in
102+
dead|exited|removing)
103+
echo "::error::Atomic Sync container entered terminal state: $container_status"
104+
break
105+
;;
106+
esac
107+
if [ "$attempt" -eq 1 ] || [ $((attempt % 10)) -eq 0 ]; then
108+
echo "Waiting for Atomic Sync: attempt=$attempt ready=$ready_status health=$health_status container=$container_status"
109+
fi
70110
sleep 1
71111
done
112+
113+
if [ "$ready_status" != ready ] || [ "$health_status" != healthy ]; then
114+
echo "::error::Atomic Sync did not become ready and healthy within 90 seconds (ready=$ready_status health=$health_status container=$container_status)"
115+
exit 1
116+
fi
117+
72118
curl --fail --silent http://127.0.0.1:18088/api/health | grep '"status":"ok"'
73119
test "$(docker inspect --format '{{.State.Health.Status}}' atomic-sync-ci)" = healthy
74120
test "$(docker exec atomic-sync-ci id -u)" = 1000

0 commit comments

Comments
 (0)