-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (67 loc) · 2.11 KB
/
build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Build App
on:
pull_request:
branches: [ "main" ]
env:
SHA: ${{ github.sha }}
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push todo-api
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/todo-api:${{ env.SHA }}
- name: Build and push todo-db
uses: docker/build-push-action@v6
with:
file: Dockerfile.db
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/todo-db:${{ env.SHA }}
api-tests:
runs-on: ubuntu-latest
needs: build-docker-image
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run API tests
run: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/todo-db:${{ env.SHA }}
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/todo-api:${{ env.SHA }}
- name: Start containers
uses: hoverkraft-tech/[email protected]
env:
SHA: ${{ env.SHA }}
- name: Run API tests
run: |
docker-compose up -d
max_attempts=3
attempt=1
while [ $attempt -le $max_attempts ]; do
if curl -s http://localhost:8080/health | grep -q '"status":"OK"'; then
echo "Container is up and healthy!"
break
else
echo "Attempt $attempt/$max_attempts: Waiting for container..."
attempt=$((attempt + 1))
if [ $attempt -le $max_attempts ]; then
sleep 60 # Wait for 60 seconds before the next attempt
fi
fi
done
if [ $attempt -gt $max_attempts ]; then
echo "Container failed to become healthy after $max_attempts attempts."
fi
- name: Test
run: go test -v ./...