-
Notifications
You must be signed in to change notification settings - Fork 1
219 lines (187 loc) · 7.01 KB
/
docker-test.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
name: Docker Test
on:
push:
branches-ignore:
- "main"
tags-ignore:
- "**"
jobs:
container-test-builds:
name: Build ${{matrix.tag}} Container
runs-on: ubuntu-latest
strategy:
matrix:
include:
- dockerfile: ConsumerApi/Dockerfile
tag: consumer-api
- dockerfile: AdminApi/src/AdminApi/Dockerfile
tag: admin-ui
- dockerfile: Modules/Devices/src/Devices.AdminCli/Dockerfile
tag: seed-client
- dockerfile: DatabaseMigrator/Dockerfile
tag: database-migrator
- dockerfile: EventHandlerService/src/EventHandlerService/Dockerfile
tag: event-handler-service
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
check-latest: true
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Setup Docker
uses: docker/setup-buildx-action@v3
- name: Setup NuGet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
#cache: true
- name: Cache Image
uses: actions/cache@v3
with:
path: /tmp/.buildx-${{ matrix.tag }}-cache
key: buildx-${{ matrix.tag }}-cache-${{ hashFiles(matrix.dockerfile) }}
restore-keys: |
buildx-${{ matrix.tag }}-cache-
# - id: cache
# name: Cache Docker
# uses: actions/cache@v3
# with:
# path: /tmp/docker-registry
# key: ${{ runner.os }}-registry-${{ hashFiles('**/Dockerfile', './.ci/docker-compose.test*.yml') }}
# restore-keys: |
# ${{ runner.os }}-registry-
#- name: Cache npm dependencies
# uses: actions/cache@v3
# with:
# path: |
# ./runtime/node_modules
# key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-npm-
- name: Install script dependencies
run: npm install --prefix ./.ci
#- name: Clear Docker Container
# run: python .ci/integrationTest.py postgres down
#- name: Build Docker
# run: python .ci/integrationTest.py postgres build
#- name: Startup Docker
# run: python .ci/integrationTest.py postgres up -d
#- name: Build Docker
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ./.ci/docker-compose.postgres.yml
# push: false
# cache-from: type=gha
# cache-to: type=gha,mode=max
#- name: Run Tests
# run: python .ci/integrationTest.py build
# - name: Run local registry
# run: docker run -d -p 6000:5000 --restart=always --name registry -v /tmp/docker-registry:/var/lib/registry registry:2 && npx wait-on tcp:6000
- name: Build Container
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
cache-from: type=local,src=/tmp/.buildx-${{ matrix.tag }}-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-${{ matrix.tag }}-cache-new
#cache-from: type=gha
#cache-to: type=gha,mode=max
tags: ${{ matrix.tag }}
load: false
outputs: type=docker,dest=/tmp/${{ matrix.tag }}.tar
#outputs: type=registry,dest=localhost:6000/consumer-api
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: docker-${{ matrix.tag }}
path: /tmp/${{ matrix.tag }}.tar
retention-days: 1
# - name: Build Admin Api
# uses: docker/build-push-action@v5
# with:
# context: .
# file: AdminApi/src/AdminApi/Dockerfile
# cache-from: type=gha
# cache-to: type=gha,mode=min
# tags: admin-ui
# load: true
# #outputs: type=registry,dest=localhost:6000/admin-ui
#
# - name: Build Seed Client
# uses: docker/build-push-action@v5
# with:
# context: .
# file: Modules/Devices/src/Devices.AdminCli/Dockerfile
# cache-from: type=gha
# cache-to: type=gha,mode=min
# tags: seed-client
# load: true
# #outputs: type=registry,dest=localhost:6000/seed-client
#
# - name: Run integration tests
# run: ./.ci/integrationTest.postgres.sh
# - name: Push ConsumerAPI to local registry
# run: docker tag consumer-api localhost:6000/consumer-api && docker push localhost:6000/consumer-api || true
#if: steps.cache.outputs.cache-hit != 'true'
# - name: Push AdminUI to local registry
# run: docker tag admin-ui localhost:6000/admin-ui && docker push localhost:6000/admin-ui || true
#if: steps.cache.outputs.cache-hit != 'true'
# - name: Push Seed Client to local registry
# run: docker tag seed-client localhost:6000/seed-client && docker push localhost:6000/seed-client || true
#if: steps.cache.outputs.cache-hit != 'true'
- name: Save Docker Logs
if: failure()
run: docker compose -f ./.ci/docker-compose.test.yml -f ./.ci/docker-compose.test.postgres.yml logs > docker-log.txt
- name: Archive logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: integration-test-postgres-docker-logs
path: docker-log.txt
env:
DOTNET_CONSOLE_ANSI_COLOR: true
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-${{ matrix.tag }}-cache
mv /tmp/.buildx-${{ matrix.tag }}-cache-new /tmp/.buildx-${{ matrix.tag }}-cache
run-tests:
name: Run tests
runs-on: ubuntu-latest
needs: container-test-builds
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
check-latest: true
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Setup NuGet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Install script dependencies
run: npm install --prefix ./.ci
- name: Download Docker images
uses: actions/download-artifact@v4
with:
path: /tmp
pattern: docker-*
merge-multiple: true
- name: Load Docker images
run: |
docker load --input /tmp/consumer-api.tar
docker load --input /tmp/admin-ui.tar
docker load --input /tmp/seed-client.tar
docker load --input /tmp/database-migrator.tar
docker load --input /tmp/event-handler-service.tar
- name: Run integration tests
run: ./.ci/integrationTest.postgres.sh