Skip to content

chore(infra): Fix frontend healthchecks #7

chore(infra): Fix frontend healthchecks

chore(infra): Fix frontend healthchecks #7

Workflow file for this run

name: Docker Image CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Ensure .env exists from example
# If a .env is missing in the runner, copy example.env -> .env so docker-compose can read it
run: |
if [ -f .env ]; then
echo ".env already exists"
elif [ -f example.env ]; then
cp example.env .env
echo "Copied example.env -> .env"
else
echo "No example.env found; continuing without .env"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and run services with Docker Compose
# This builds both frontend and backend (assuming docker-compose.yml defines both)
run: |
docker compose -f docker-compose.yml up -d --build
docker compose -f docker-compose.yml ps
- name: Wait for services to initialize
run: |
echo "Waiting for services to become ready..."
docker compose -f docker-compose.yml ps
# Wait for backend health endpoint with retries
MAX_RETRIES=30
SLEEP=2
attempt=0
until curl --fail --silent --show-error http://localhost:8000/health >/dev/null 2>&1; do
attempt=$((attempt+1))
echo "backend not healthy yet (attempt $attempt/$MAX_RETRIES)"
if [ $attempt -ge $MAX_RETRIES ]; then
echo "Backend did not become healthy after $MAX_RETRIES attempts"
echo "---- docker compose ps ----"
docker compose -f docker-compose.yml ps
echo "---- logs (tail 500) ----"
docker compose -f docker-compose.yml logs --no-color --tail=500 || true
exit 1
fi
sleep $SLEEP
done
echo "Backend health check passed"
- name: Robust smoke test + container-internal checks
run: |
echo "=== Robust smoke tests against nginx and backend ==="
set -o pipefail
# Try to curl nginx from the runner first
echo "Trying to curl http://localhost/ from runner (host)"
if curl --fail --silent --show-error http://localhost/ -o /dev/null; then
echo "Runner can reach nginx on localhost"
else
echo "Runner could NOT reach nginx on localhost. Will gather debug info and try container-internal checks."
echo "---- docker compose ps ----"
docker compose -f docker-compose.yml ps
echo "---- docker compose ls ----"
docker compose -f docker-compose.yml ls || true
echo "---- nginx logs (tail 200) ----"
docker compose -f docker-compose.yml logs nginx --no-color --tail=200 || true
echo "---- full logs (tail 200) ----"
docker compose -f docker-compose.yml logs --no-color --tail=200 || true
# Inspect nginx container port mapping
echo "Inspecting nginx container network/ports"
docker inspect nginx --format='{{json .NetworkSettings.Ports}}' || true
# Fallback: run checks from backend container (backend image includes curl)
echo "Attempting checks from backend container (container network)"
# Use -T to avoid tty allocation issues in CI
docker compose -f docker-compose.yml exec -T backend sh -c "curl -sS -o /dev/null -w '%{http_code}' http://nginx:80 || true" || true
docker compose -f docker-compose.yml exec -T backend sh -c "curl -sS -o /dev/null -w '%{http_code}' http://backend:8000/health || true" || true
echo "Container-internal checks finished. Failing job to surface the issue."
exit 1
fi
# If runner-based curl succeeded, also validate openapi.json proxy and backend health via container network
echo "Validating /openapi.json via nginx proxy"
curl --fail --silent --show-error http://localhost/openapi.json -o /dev/null || {
echo "openapi.json check failed; printing logs"
docker compose -f docker-compose.yml logs --no-color --tail=500 || true
exit 1
}
echo "Validating backend /health via backend container"
docker compose -f docker-compose.yml exec -T backend sh -c "curl --fail --silent --show-error http://localhost:8000/health" || {
echo "backend health inside container failed; printing logs"
docker compose -f docker-compose.yml logs --no-color --tail=500 || true
exit 1
}
echo "Smoke tests passed"
- name: Tear down compose
if: always()
run: |
echo "Tearing down docker-compose"
docker compose -f docker-compose.yml down -v || true