File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed
Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 5757 labels : ${{ steps.meta.outputs.labels }}
5858 cache-from : type=gha
5959 cache-to : type=gha,mode=max
60+
61+ # Test container health with docker compose
62+ - name : Test container with docker compose
63+ run : |
64+ echo "Starting container with docker compose..."
65+ docker compose up --build -d
66+ echo "Waiting for container to be ready (60 seconds for start_period)..."
67+ sleep 60
68+
69+ echo "Monitoring container health for 30 seconds..."
70+ SECONDS_ELAPSED=0
71+ HEALTH_CHECK_INTERVAL=5
72+ TOTAL_DURATION=30
73+
74+ while [ $SECONDS_ELAPSED -lt $TOTAL_DURATION ]; do
75+ HEALTH_STATUS=$(docker inspect --format='{{.State.Health.Status}}' fredy 2>/dev/null || echo "not_found")
76+ CONTAINER_STATUS=$(docker inspect --format='{{.State.Status}}' fredy 2>/dev/null || echo "not_found")
77+ echo "[$SECONDS_ELAPSED/$TOTAL_DURATION sec] Container: $CONTAINER_STATUS, Health: $HEALTH_STATUS"
78+
79+ # Check if container is not running or unhealthy
80+ if [ "$CONTAINER_STATUS" != "running" ]; then
81+ echo "Container stopped running! Status: $CONTAINER_STATUS"
82+ docker compose logs fredy
83+ exit 1
84+ fi
85+
86+ if [ "$HEALTH_STATUS" = "unhealthy" ]; then
87+ echo "Container is unhealthy!"
88+ docker compose logs fredy
89+ docker inspect --format='{{json .State.Health}}' fredy | jq
90+ exit 1
91+ fi
92+
93+ sleep $HEALTH_CHECK_INTERVAL
94+ SECONDS_ELAPSED=$((SECONDS_ELAPSED + HEALTH_CHECK_INTERVAL))
95+ done
96+
97+ docker compose down
Original file line number Diff line number Diff line change @@ -2,9 +2,10 @@ FROM node:22-slim
22
33WORKDIR /fredy
44
5- # Install Chromium without extra recommended packages and clean apt cache
5+ # Install Chromium and curl without extra recommended packages and clean apt cache
6+ # curl is needed for the health check
67RUN apt-get update \
7- && apt-get install -y --no-install-recommends chromium \
8+ && apt-get install -y --no-install-recommends chromium curl \
89 && rm -rf /var/lib/apt/lists/*
910
1011ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
Original file line number Diff line number Diff line change @@ -11,5 +11,12 @@ services:
1111 - ./conf:/conf
1212 - ./db:/db
1313 ports :
14- - 9998:9998
14+ - " 9998:9998"
1515 restart : unless-stopped
16+ healthcheck :
17+ # The container will immediately stop when health check fails after retries
18+ test : ["CMD-SHELL", "curl --fail --silent --show-error --max-time 5 http://localhost:9998/ || exit 1"]
19+ interval : 120s
20+ timeout : 10s
21+ retries : 1
22+ start_period : 10s
You can’t perform that action at this time.
0 commit comments