Update Docker commands in CI workflow to use 'docker compose' syntax #15
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: End-to-End Tests | |
| on: | |
| push: | |
| branches: [week7] | |
| jobs: | |
| e2e: | |
| name: Run Docker Compose End-to-End Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Set up Docker cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Build Docker containers | |
| run: docker compose build | |
| - name: Run Docker Compose (detached) | |
| run: docker compose up -d | |
| - name: Wait for services to be healthy | |
| run: | | |
| set -e | |
| timeout=30 | |
| echo "Waiting up to $timeout seconds for services to become healthy..." | |
| for i in $(seq 1 $timeout); do | |
| unhealthy=$(docker inspect --format='{{.State.Health.Status}}' $(docker compose ps -q db || true) || echo "unhealthy") | |
| if [ "$unhealthy" == "healthy" ]; then | |
| echo "DB is healthy." | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| - name: Run health check and test endpoint | |
| run: | | |
| echo "Testing health endpoint..." | |
| curl --fail http://localhost:3000/health | |
| echo "Testing user GET (expecting empty array or success)..." | |
| curl --fail http://localhost:3000/api/users | |
| - name: Handle failed services | |
| if: failure() | |
| run: | | |
| echo "One or more steps failed. Showing logs..." | |
| docker compose logs > full_logs.txt | |
| cat full_logs.txt | |
| - name: Upload logs as artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-compose-logs | |
| path: full_logs.txt | |
| - name: Shut down containers | |
| if: always() | |
| run: docker compose down --volumes |