chore(infra): Add Docker Image CI workflow #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Smoke test / show logs (customize endpoints as needed) | |
run: | | |
echo "=== Performing smoke tests against nginx and backend proxy ===" | |
set -e | |
# Check nginx root (will proxy to frontend) | |
echo "Checking nginx root (http://localhost/)" | |
curl --fail --silent --show-error http://localhost/ -o /dev/null || { | |
echo "nginx root check failed" | |
docker compose -f docker-compose.yml logs --no-color --tail=500 || true | |
exit 1 | |
} | |
# Check openapi.json proxied through nginx | |
echo "Checking OpenAPI at http://localhost/openapi.json" | |
curl --fail --silent --show-error http://localhost/openapi.json -o /dev/null || { | |
echo "openapi.json check failed" | |
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 |