-
Notifications
You must be signed in to change notification settings - Fork 2
127 lines (122 loc) · 5.23 KB
/
ci.yml
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: CI
on:
push:
branches:
- main
tags:
- '*'
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
timeout-minutes: 1
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Build with Gradle
run: ./gradlew --build-cache build -x test
timeout-minutes: 30
- name: Test with Gradle
run: ./gradlew --build-cache test
timeout-minutes: 30
build-docker:
runs-on: ubuntu-latest
environment: gitlab-docker-registry
needs:
- build
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Create Docker layers
run: ./gradlew buildLayers dockerfile
timeout-minutes: 10
- name: Build Docker Image
run: docker build . -t registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }}
timeout-minutes: 30
working-directory: backend/build/docker/main
- name: Login to GitLab Registry
if: github.event_name == 'push' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
run: echo ${{ secrets.DOCKER_PUSH_TOKEN }} | docker login -u ${{ secrets.DOCKER_PUSH_TOKEN_NAME }} --password-stdin registry.gitlab.com
timeout-minutes: 1
- name: Push Docker Image
if: github.event_name == 'push' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
run: docker push registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }}
timeout-minutes: 30
- name: Tag & Push latest Docker Image
if: github.ref_name == 'main' || github.ref_type == 'tag'
run: |
docker image tag registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} registry.gitlab.com/taucher2003-group/devmarkt-backend:latest
docker push registry.gitlab.com/taucher2003-group/devmarkt-backend:latest
- name: Tag & Push tag Docker Image
if: github.ref_type == 'tag'
run: |
docker image tag registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.ref_name }}
docker push registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.ref_name }}
- name: Store Image as artifact if running as fork
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')
run: docker save registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }} > qa-image.tar
- name: Upload stored Images as artifact
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')
uses: actions/upload-artifact@v4
with:
name: qa-image
path: qa-image.tar
qa:
runs-on: ubuntu-latest
needs:
- build-docker
services:
postgres:
image: postgres:14.2
env:
POSTGRES_PASSWORD: devmarkt-qa
POSTGRES_USER: devmarkt-qa
POSTGRES_DB: devmarkt-qa
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- name: Download stored image as artifact
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')
uses: actions/download-artifact@v4
with:
name: qa-image
path: qa-image.tar
- name: Load stored image if running as fork
if: github.event_name != 'push' && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]')
run: docker load -i qa-image.tar/qa-image.tar
- name: Start backend
run: |
docker network create --subnet=172.16.0.0/16 backend-network
docker run -d --name backend -p 8080:8080 -e MICRONAUT_ENVIRONMENTS=qa -e DEVMARKT_POSTGRES_HOST=172.16.0.1 -e DEVMARKT_POSTGRES_DATABASE=devmarkt-qa -e DEVMARKT_POSTGRES_USER=devmarkt-qa -e DEVMARKT_POSTGRES_PASSWORD=devmarkt-qa registry.gitlab.com/taucher2003-group/devmarkt-backend:${{ github.sha }}
docker network connect --ip 172.16.0.2 backend-network backend
- name: Install dependencies
run: yarn install
working-directory: qa
- name: Check if backend is reachable
run: curl --fail -sv --retry 3 --retry-delay 3 --retry-connrefused http://172.16.0.2:8080/health
- name: Run Tests
run: BACKEND_HOST=http://172.16.0.2:8080 yarn test:ci
working-directory: qa
- name: Stop backend
if: always()
run: |
docker stop backend
docker logs backend
docker rm backend
docker network rm backend-network