Skip to content

Commit 03f033f

Browse files
committed
chore: make health checks robuster
1 parent f42f218 commit 03f033f

3 files changed

Lines changed: 45 additions & 13 deletions

File tree

.github/workflows/docker-compose-integration.yml

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,32 @@ jobs:
2424
- name: Wait for services to be healthy
2525
run: |
2626
echo "Waiting for all services to be healthy..."
27-
# Wait for services with health checks to be healthy (4 services) and all services to be up
28-
timeout 300 bash -c 'until [ $(docker compose ps --format "{{.Health}}" | grep -c "healthy") -ge 4 ] && [ $(docker compose ps --format "{{.Status}}" | grep -c "Up") -ge 5 ]; do sleep 5; done'
27+
# Wait for services with health checks to be healthy (7 services) and all services to be up
28+
# Increased timeout to 10 minutes for CI environment
29+
timeout 600 bash -c 'while true; do
30+
echo "=== Detailed Service Status ==="
31+
docker compose ps --format "table {{.Name}}\t{{.Status}}\t{{.Health}}"
32+
echo "=== Unhealthy Services ==="
33+
unhealthy_services=$(docker compose ps --format "{{.Name}} {{.Health}}" | grep -v healthy | grep -v "^[[:space:]]*$" || echo "")
34+
if [ -n "$unhealthy_services" ]; then
35+
echo "$unhealthy_services"
36+
echo "=== Logs for unhealthy services ==="
37+
for service in $(echo "$unhealthy_services" | awk "{print \$1}"); do
38+
echo "--- Logs for $service ---"
39+
docker compose logs --tail=10 "$service" || echo "No logs for $service"
40+
done
41+
else
42+
echo "All services healthy or no health check"
43+
fi
44+
healthy_count=$(docker compose ps --format "{{.Health}}" | grep -c "healthy" || echo "0")
45+
up_count=$(docker compose ps --format "{{.Status}}" | grep -c "Up" || echo "0")
46+
echo "Progress: $healthy_count/7 healthy, $up_count services up"
47+
if [ "$healthy_count" -ge 7 ] && [ "$up_count" -ge 7 ]; then
48+
echo "All services are healthy!"
49+
break
50+
fi
51+
sleep 10
52+
done'
2953
docker compose ps
3054
3155
- name: Test dashboard endpoints
@@ -45,15 +69,12 @@ jobs:
4569
run: |
4670
echo "=== Docker Compose Services Status ==="
4771
docker compose ps
48-
echo "=== Traefik Logs ==="
49-
docker compose logs traefik
50-
echo "=== Sticker Award Logs ==="
51-
docker compose logs sticker-award
52-
echo "=== User Management Logs ==="
53-
docker compose logs user-management
54-
echo "=== Database Logs ==="
55-
docker compose logs sticker-award-db
56-
docker compose logs user-management-db
72+
echo "=== All Service Logs ==="
73+
docker compose logs --tail=50
74+
echo "=== Health Check Details ==="
75+
docker compose ps --format "table {{.Name}}\t{{.Status}}\t{{.Health}}"
76+
echo "=== Resource Usage ==="
77+
docker stats --no-stream
5778
5879
- name: Cleanup
5980
if: always()

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ services:
185185
QUARKUS_S3_AWS_CREDENTIALS_STATIC_PROVIDER_SECRET_ACCESS_KEY: minioadmin
186186
QUARKUS_S3_PATH_STYLE_ACCESS: "true"
187187
STICKER_IMAGES_BUCKET: sticker-images
188+
healthcheck:
189+
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
190+
interval: 10s
191+
timeout: 5s
192+
retries: 5
188193
labels:
189194
- "traefik.enable=true"
190195
- "traefik.http.routers.sticker-award.rule=PathPrefix(`/api/award`)"
@@ -210,6 +215,11 @@ services:
210215
KAFKA__BOOTSTRAPSERVERS: "redpanda:9092"
211216
KAFKA__SCHEMAREGISTRY: "http://redpanda:8082"
212217
KAFKA__GROUPID: "stickerlandia-user-management"
218+
healthcheck:
219+
test: ["CMD", "curl", "-f", "http://localhost:8080/api/users/v1/health"]
220+
interval: 10s
221+
timeout: 5s
222+
retries: 5
213223
labels:
214224
- "traefik.enable=true"
215225
- "traefik.http.routers.user-management.rule=PathPrefix(`/api/users`)"

user-management/src/Stickerlandia.UserManagement.Api/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ RUN dotnet restore src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManage
1010
COPY . ./
1111

1212
# Publish the application
13-
RUN dotnet publish src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj -o out -c Release -r linux-arm64
13+
RUN dotnet publish src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj -o out -c Release
1414

15-
FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled AS runtime
15+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
16+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
1617
WORKDIR /App
1718
COPY --from=build /App/out .
1819
EXPOSE 80

0 commit comments

Comments
 (0)