Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 34b2128

Browse files
authored
Update stage.yml
1 parent 9c2713c commit 34b2128

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

.github/workflows/stage.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,50 @@ jobs:
3636
docker build -t ${{ secrets.DOCKER_HUB_IP }}:${{ secrets.DOCKER_HUB_PORT}}/wheels-dev-stage .
3737
docker push ${{ secrets.DOCKER_HUB_IP }}:${{ secrets.DOCKER_HUB_PORT}}/wheels-dev-stage
3838
39-
- name: Run container and verify it starts
40-
id: Run-Container-Test
39+
- name: Run container and check health
40+
id: Run-Container-Health-Test
4141
run: |
4242
IMAGE=${{ secrets.DOCKER_HUB_IP }}:${{ secrets.DOCKER_HUB_PORT }}/wheels-dev-stage
4343
CONTAINER_NAME=wheels-dev-stage-test
4444
4545
echo "Running test container from image: $IMAGE"
4646
docker run -d --name $CONTAINER_NAME $IMAGE
4747
48-
echo "Waiting for container to reach 'running' state..."
48+
echo "Waiting for container to become healthy..."
4949
5050
TIMEOUT=60
5151
INTERVAL=5
5252
elapsed=0
5353
5454
while [ $elapsed -lt $TIMEOUT ]; do
55-
status=$(docker inspect -f '{{.State.Status}}' $CONTAINER_NAME)
56-
if [ "$status" = "running" ]; then
57-
echo "✅ Container is running."
55+
health=$(docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME 2>/dev/null || echo "no-health")
56+
echo "Health status: $health"
57+
58+
if [ "$health" = "healthy" ]; then
59+
echo "✅ Container is healthy."
5860
docker rm -f $CONTAINER_NAME
5961
exit 0
62+
elif [ "$health" = "unhealthy" ]; then
63+
echo "❌ Container is unhealthy."
64+
docker logs $CONTAINER_NAME || true
65+
docker rm -f $CONTAINER_NAME || true
66+
exit 1
67+
elif [ "$health" = "no-health" ]; then
68+
echo "❌ HEALTHCHECK not defined in image. Cannot proceed."
69+
docker rm -f $CONTAINER_NAME || true
70+
exit 1
6071
fi
72+
6173
sleep $INTERVAL
6274
elapsed=$((elapsed + INTERVAL))
6375
done
6476
65-
echo "❌ Container failed to reach 'running' state within $TIMEOUT seconds."
66-
echo "::error::Image did not produce a healthy container."
77+
echo "❌ Container health status stuck at 'starting' for more than $TIMEOUT seconds."
6778
docker logs $CONTAINER_NAME || true
6879
docker rm -f $CONTAINER_NAME || true
6980
exit 1
7081
82+
7183
- name: Deploy to Docker Swarm
7284
id: Deploy-to-Docker-Swarm
7385
run: |

0 commit comments

Comments
 (0)