-
Notifications
You must be signed in to change notification settings - Fork 2
251 lines (211 loc) · 8.21 KB
/
build-image.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: Build image
on:
workflow_call:
inputs:
run-docker-acm:
required: true
type: boolean
run-docker-wiremock:
required: true
type: boolean
run-docker-db:
required: true
type: boolean
run-docker-elasticsearch:
required: true
type: boolean
run-docker-localstack:
required: true
type: boolean
pre-gen-marten:
type: boolean
image-file: #ar-acm-api-image.tar
required: true
type: string
image-name: #acm-api
required: true
type: string
test-project: #AssociationRegistry.Test.Acm.Api
required: false
type: string
build-project: #AssociationRegistry.Acm.Api/
required: true
type: string
semver:
required: true
type: string
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Check version
shell: bash
run: echo $SEMVER
env:
SEMVER: ${{ inputs.semver }}
- name: Display disk space
run: |
df -h
- name: Delete huge unnecessary tools folder
run: rm -rf /opt/hostedtoolcache
- name: Display disk space
run: |
df -h
- name: Checkout Code
uses: actions/checkout@v4
- name: Run localstack container
shell: bash
if: ${{ inputs.run-docker-localstack }}
run: |
docker run -d --name localstack -v ${{ github.workspace }}/.localstack/init:/etc/localstack/init -p 4566:4566 -p 4510-4559:4510-4559 -e SERVICES=sqs -e DOCKER_HOST=unix:///var/run/docker.sock -e DEFAULT_REGION=eu-west-1 -e DEBUG=1 -e PORT_WEB_UI=8080 localstack/localstack
- name: Run es container
shell: bash
if: ${{ inputs.run-docker-elasticsearch }}
run: |
docker run -d --name elasticsearch -p 9200:9200 -e ELASTIC_PASSWORD=local_development -e discovery.type=single-node -e xpack.security.transport.ssl.enabled=false docker.elastic.co/elasticsearch/elasticsearch:8.4.3
- name: Run wiremock container
shell: bash
if: ${{ inputs.run-docker-wiremock }}
run: |
docker run -d --name wiremock -v ${{ github.workspace }}/wiremock:/home/wiremock -p 8080:8080 wiremock/wiremock:2.35.0-1 --global-response-templating --verbose
- name: Run ACM container
shell: bash
if: ${{ inputs.run-docker-acm }}
run: |
docker run -d --name acm -p 5051:80 -v ${{ github.workspace }}/identityserver:/home/identityserver ghcr.io/informatievlaanderen/identity-server-fake:1284967
- name: Run db container
shell: bash
if: ${{ inputs.run-docker-db }}
run: |
docker run -d --name db -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -e POSTGRES_DB=verenigingsregister postgres:15.0
- name: Cache Paket
uses: actions/cache@v4
env:
cache-name: cache-paket
with:
path: packages
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('paket.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Parse repository name
run: echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV
shell: bash
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ vars.VBR_DOTNET_VERSION_8 }}
- name: .NET version
shell: bash
run: dotnet --info
- name: Clean
run: dotnet nuget locals all --clear
- name: Restore dotnet tools
shell: bash
run: |
dotnet tool restore
- name: Paket install
shell: bash
run: dotnet paket install
- name: Paket restore
shell: bash
run: dotnet paket restore
- name: Dotnet restore tests
if: ${{ inputs.test-project != '' && inputs.test-project != 'none' }}
shell: bash
run: dotnet restore test/${{ inputs.test-project }} --runtime linux-x64
- name: Dotnet build tests
if: ${{ inputs.test-project != '' && inputs.test-project != 'none' }}
shell: bash
run: dotnet build --no-restore --runtime 'linux-x64' test/${{ inputs.test-project }}
- name: Wait for db container
shell: bash
run: |
timeout 90s bash -c "until docker exec db pg_isready ; do sleep 5 ; done"
- name: Run all tests
if: ${{ inputs.test-project != '' && inputs.test-project != 'none' }}
env:
LIVEMAGDAOPTIONS__CLIENTCERTIFICATE: ${{ secrets.LIVEMAGDAOPTIONS_CLIENTCERTIFICATE }}
LIVEMAGDAOPTIONS__CLIENTCERTIFICATEPASSWORD: ${{ secrets.LIVEMAGDAOPTIONS_CLIENTCERTIFICATEPASSWORD }}
LIVEMAGDAOPTIONS__GEEFONDERNEMINGENDPOINT: ${{ secrets.LIVEMAGDAOPTIONS_GEEFONDERNEMINGENDPOINT }}
LIVEMAGDAOPTIONS__AFZENDER: ${{ secrets.LIVEMAGDAOPTIONS_AFZENDER }}
LIVEMAGDAOPTIONS__HOEDANIGHEID: ${{ secrets.LIVEMAGDAOPTIONS_HOEDANIGHEID }}
LIVEMAGDAOPTIONS__ONTVANGER: ${{ secrets.LIVEMAGDAOPTIONS_ONTVANGER }}
run: dotnet test test/${{ inputs.test-project }} --logger html
- name: Archive code coverage results
if: ${{ always() && inputs.test-project != '' && inputs.test-project != 'none' }}
uses: actions/upload-artifact@v4
with:
name: test-report-${{matrix.projects}}
path: ${{matrix.projects}}/TestResults/*.html
- name: Dotnet restore
shell: bash
run: dotnet restore src/${{ inputs.build-project }} --runtime linux-x64
- name: Set solution info
shell: bash
if: inputs.semver != 'none'
run: |
docker run --network host -e CI_BUILD_NUMBER -e GIT_HASH --rm -v $(pwd):/app -w /app/ mcr.microsoft.com/dotnet/sdk:8.0.300 /bin/sh .github/build-scripts/set-solution-info.sh
env:
BUILD_DOCKER_REGISTRY: ${{ secrets.BUILD_DOCKER_REGISTRY_IK4 }}
CI_BUILD_NUMBER: ${{ inputs.semver }}
- name: Pre-build Marten models
if: ${{ inputs.pre-gen-marten }}
shell: bash
run: dotnet run -c Release --project src/${{ inputs.build-project }} -- codegen write
- name: Dotnet build
shell: bash
run: dotnet build -c Release --no-restore --runtime 'linux-x64' --self-contained -f net8.0 src/${{ inputs.build-project }}
- name: Dotnet publish
shell: bash
run: |
pushd src/${{ inputs.build-project }}
dotnet publish -c Release -o ../../dist/${{ inputs.build-project }}/linux --no-build --no-restore --runtime 'linux-x64' --self-contained -f net8.0
popd
- name: Containerize Api
shell: bash
run: |
.github/build-scripts/build-docker.sh ${{ inputs.build-project }} ${{ inputs.image-name}}
env:
BUILD_DOCKER_REGISTRY: ${{ secrets.BUILD_DOCKER_REGISTRY_IK4 }}
CI_BUILD_NUMBER: ${{ inputs.semver }}
- name: Show images
shell: bash
run: docker images
- name: Save Api Image
if: inputs.semver != 'none'
shell: bash
run: docker image save $BUILD_DOCKER_REGISTRY/${{ inputs.image-name }}:$SEMVER -o ~/${{ inputs.image-file}}
env:
BUILD_DOCKER_REGISTRY: ${{ secrets.BUILD_DOCKER_REGISTRY_IK4 }}
SEMVER: ${{ inputs.semver }}
- name: Upload Api artifact
if: inputs.semver != 'none'
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.image-name }}
path: ~/${{ inputs.image-file }}
- name: Shows logs ACM container
if: ${{ failure() }}
shell: bash
run: |
docker logs acm
- name: Shows logs elasticsearch container
if: ${{ failure() }}
shell: bash
run: |
docker logs elasticsearch
- name: Shows logs localstack container
if: ${{ failure() }}
shell: bash
run: |
docker logs localstack
- name: Shows logs wiremock container
if: ${{ failure() }}
shell: bash
run: |
docker logs wiremock
- name: Shows logs db container
if: ${{ failure() }}
shell: bash
run: |
docker logs db