Refactor Docker Compose commands in CI workflow to specify file path #4
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
| # 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: Wait for backend healthcheck | |
| run: | | |
| for i in {1..10}; do | |
| STATUS=$(docker inspect --format='{{json .State.Health.Status}}' week7-backend-1 || 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 |