Skip to content

Commit c80c414

Browse files
committed
Refactor CI workflow for end-to-end tests; streamline steps, enhance readability, and improve health check logic.
1 parent 38a93e1 commit c80c414

1 file changed

Lines changed: 21 additions & 37 deletions

File tree

.github/workflows/ci_week7.yml

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,50 @@ on:
77

88
jobs:
99
e2e:
10-
name: Run Docker Compose End-to-End Tests
1110
runs-on: ubuntu-latest
1211

1312
steps:
14-
- name: Checkout repository
13+
- name: 📥 Checkout code
1514
uses: actions/checkout@v4
1615

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: .
1919

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: .
3323

34-
- name: Wait for services to be healthy
24+
- name: 💤 Wait for DB to become healthy
3525
run: |
36-
set -e
3726
timeout=30
38-
echo "Waiting up to $timeout seconds for services to become healthy..."
3927
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
4531
sleep 1
4632
done
33+
working-directory: .
4734

48-
- name: Run health check and test endpoint
35+
- name: 🔍 Test health endpoint
4936
run: |
50-
echo "Testing health endpoint..."
5137
curl --fail http://localhost:3000/health
52-
53-
echo "Testing user GET (expecting empty array or success)..."
5438
curl --fail http://localhost:3000/api/users
39+
working-directory: .
5540

56-
- name: Handle failed services
41+
- name: 🧾 Save logs if failed
5742
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: .
6245

63-
- name: Upload logs as artifact
46+
- name: 📤 Upload logs
6447
if: always()
6548
uses: actions/upload-artifact@v4
6649
with:
6750
name: docker-compose-logs
6851
path: full_logs.txt
6952

70-
- name: Shut down containers
53+
- name: 🧹 Tear down
7154
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

Comments
 (0)