|
7 | 7 |
|
8 | 8 | jobs: |
9 | 9 | e2e: |
10 | | - name: Run Docker Compose End-to-End Tests |
11 | 10 | runs-on: ubuntu-latest |
12 | 11 |
|
13 | 12 | steps: |
14 | | - - name: Checkout repository |
| 13 | + - name: 📥 Checkout code |
15 | 14 | uses: actions/checkout@v4 |
16 | 15 |
|
17 | | - - name: Set up Docker Buildx |
18 | | - uses: docker/setup-buildx-action@v3 |
| 16 | + - name: 🔧 Build services |
| 17 | + run: docker compose -f DevOps-Linux/week7/docker-compose.yml build |
| 18 | + working-directory: . |
19 | 19 |
|
20 | | - - name: Set up Docker cache |
21 | | - uses: actions/cache@v4 |
22 | | - with: |
23 | | - path: /tmp/.buildx-cache |
24 | | - key: ${{ runner.os }}-buildx-${{ github.sha }} |
25 | | - restore-keys: | |
26 | | - ${{ runner.os }}-buildx- |
27 | | -
|
28 | | - - name: Build Docker containers |
29 | | - run: docker compose build |
30 | | - |
31 | | - - name: Run Docker Compose (detached) |
32 | | - run: docker compose up -d |
| 20 | + - name: 🚀 Start containers |
| 21 | + run: docker compose -f DevOps-Linux/week7/docker-compose.yml up -d |
| 22 | + working-directory: . |
33 | 23 |
|
34 | | - - name: Wait for services to be healthy |
| 24 | + - name: 💤 Wait for DB to become healthy |
35 | 25 | run: | |
36 | | - set -e |
37 | 26 | timeout=30 |
38 | | - echo "Waiting up to $timeout seconds for services to become healthy..." |
39 | 27 | for i in $(seq 1 $timeout); do |
40 | | - unhealthy=$(docker inspect --format='{{.State.Health.Status}}' $(docker compose ps -q db || true) || echo "unhealthy") |
41 | | - if [ "$unhealthy" == "healthy" ]; then |
42 | | - echo "DB is healthy." |
43 | | - break |
44 | | - fi |
| 28 | + status=$(docker inspect --format='{{.State.Health.Status}}' $(docker compose -f DevOps-Linux/week7/docker-compose.yml ps -q db)) |
| 29 | + echo "DB health: $status" |
| 30 | + [ "$status" = "healthy" ] && break |
45 | 31 | sleep 1 |
46 | 32 | done |
| 33 | + working-directory: . |
47 | 34 |
|
48 | | - - name: Run health check and test endpoint |
| 35 | + - name: 🔍 Test health endpoint |
49 | 36 | run: | |
50 | | - echo "Testing health endpoint..." |
51 | 37 | curl --fail http://localhost:3000/health |
52 | | -
|
53 | | - echo "Testing user GET (expecting empty array or success)..." |
54 | 38 | curl --fail http://localhost:3000/api/users |
| 39 | + working-directory: . |
55 | 40 |
|
56 | | - - name: Handle failed services |
| 41 | + - name: 🧾 Save logs if failed |
57 | 42 | if: failure() |
58 | | - run: | |
59 | | - echo "One or more steps failed. Showing logs..." |
60 | | - docker compose logs > full_logs.txt |
61 | | - cat full_logs.txt |
| 43 | + run: docker compose -f DevOps-Linux/week7/docker-compose.yml logs > full_logs.txt |
| 44 | + working-directory: . |
62 | 45 |
|
63 | | - - name: Upload logs as artifact |
| 46 | + - name: 📤 Upload logs |
64 | 47 | if: always() |
65 | 48 | uses: actions/upload-artifact@v4 |
66 | 49 | with: |
67 | 50 | name: docker-compose-logs |
68 | 51 | path: full_logs.txt |
69 | 52 |
|
70 | | - - name: Shut down containers |
| 53 | + - name: 🧹 Tear down |
71 | 54 | if: always() |
72 | | - run: docker compose down --volumes |
| 55 | + run: docker compose -f DevOps-Linux/week7/docker-compose.yml down --volumes |
| 56 | + working-directory: . |
0 commit comments