Skip to content

Update healthcheck interval to 10s and timeout to 5s for backend service #7

Update healthcheck interval to 10s and timeout to 5s for backend service

Update healthcheck interval to 10s and timeout to 5s for backend service #7

Workflow file for this run

# GitHub Actions CI for Docker Compose (Week 7)
name: CI - Docker Compose Week 7
on:
push:
branches:
- week7
workflow_dispatch:
jobs:
e2e-tests:
runs-on: ubuntu-latest
services:
docker:
image: docker:24.0.5-dind
options: --dns 8.8.8.8
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Compose
uses: docker/setup-buildx-action@v3
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Build and start services
run: |
docker-compose -f week7/docker-compose.yml up --build -d
- name: Get running containers
run: |
docker ps -a
- name: Wait for backend healthcheck
run: |
CONTAINER_ID=$(docker ps -qf "name=backend")
echo "Backend container ID: $CONTAINER_ID"
for i in {1..10}; do
STATUS=$(docker inspect --format='{{json .State.Health.Status}}' $CONTAINER_ID || echo "none")
echo "Backend health: $STATUS"
if [ "$STATUS" = '"healthy"' ]; then exit 0; fi
sleep 5
done
echo "Backend did not become healthy in time" && docker-compose -f week7/docker-compose.yml logs backend && exit 1
- name: Run end-to-end tests
run: |
curl -f http://localhost:3000/health
- name: Show logs on failure
if: failure()
run: |
docker-compose -f week7/docker-compose.yml logs > week7/compose-logs.txt || true
- name: Upload logs as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: compose-logs
path: week7/compose-logs.txt
- name: Tear down
if: always()
run: |
docker-compose -f week7/docker-compose.yml down -v