-
Notifications
You must be signed in to change notification settings - Fork 22
317 lines (309 loc) · 12.5 KB
/
build-all.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
name: Building All Containers
on:
push:
branches: [ 'main' ]
tags:
- 'v*'
pull_request:
branches: [ 'main' ]
workflow_dispatch:
jobs:
workflow_setup:
name: Setup variables
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
repo_owner: ${{ steps.repo_owner.outputs.lowercase }}
os_matrix: "{\"os_version\":[\"debian10\",\"debian11\",\"ubuntu16\",\"ubuntu18\",\"ubuntu20\"]}"
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Lowercase repo owner
id: repo_owner
run: echo "lowercase=$(echo ${{ github.repository_owner }} | tr \"[:upper:]\" \"[:lower:]\")" >>$GITHUB_OUTPUT
shell: bash
build_nodes:
name: Build node images
runs-on: ubuntu-latest
needs: workflow_setup
strategy:
matrix: ${{ fromJson(needs.workflow_setup.outputs.os_matrix) }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.os_version }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.os_version }}
${{ runner.os }}-buildx
- name: Build node image based on ${{ matrix.os_version }}
uses: docker/build-push-action@v3
with:
file: build/Dockerfile.${{ matrix.os_version }}
context: ./build
push: false
tags: indy_node:${{ matrix.os_version}}
outputs: type=docker,dest=/tmp/indy_node_${{ matrix.os_version }}.tar
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Upload docker image artifacts
uses: actions/upload-artifact@v3
with:
name: indy_node_${{ matrix.os_version }}
path: /tmp/indy_node_${{ matrix.os_version }}.tar
retention-days: 1
# Temp fix
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build_controller:
name: Build controller image
runs-on: ubuntu-latest
needs: workflow_setup
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-controler
restore-keys: |
${{ runner.os }}-buildx-controller
${{ runner.os }}-buildx
- name: Build node controller image
uses: docker/build-push-action@v3
with:
context: ./controller
push: false
tags: indy_node_controller
outputs: type=docker,dest=/tmp/indy_node_controller.tar
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Upload docker image artifacts
uses: actions/upload-artifact@v3
with:
name: indy_node_controller
path: /tmp/indy_node_controller.tar
retention-days: 1
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
test_node_and_controller:
runs-on: ubuntu-latest
needs: [workflow_setup, build_controller, build_nodes]
strategy:
matrix: ${{ fromJson(needs.workflow_setup.outputs.os_matrix) }}
fail-fast: false
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Download node artifact
uses: actions/download-artifact@v3
with:
name: indy_node_${{ matrix.os_version }}
path: /tmp
- name: Download controller artifact
uses: actions/download-artifact@v3
with:
name: indy_node_controller
path: /tmp
- name: Load node and controller image
run: |
docker load --input /tmp/indy_node_${{ matrix.os_version }}.tar
docker load --input /tmp/indy_node_controller.tar
- name: Setup test network configs
run: cd test && ./init-test-network.sh indy_node:${{ matrix.os_version }}
- name: Start test network
run: cd test && env SOCK=/var/run/docker.sock IMAGE_NAME_NODE=indy_node:${{ matrix.os_version }} IMAGE_NAME_CONTROLLER=indy_node_controller docker-compose up -d
- name: Get Ledger State
id: ledger
run: |
echo "Waiting 30 seconds for the ledger browser to start..."
sleep 30
cd test
echo "::group::ParseValidatorOutput"
./parse_validator_info.sh
echo "::endgroup::"
- name: Safe ledger_state.json for later inspection
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os_version }}-tmp-test-${{ github.sha }}-ledger_state.json
path: ledger_state.json
retention-days: 7
- name: Fail if ledger is not in sync
if: |
steps.ledger.outputs.n1_synced != 'true' ||
steps.ledger.outputs.n2_synced != 'true' ||
steps.ledger.outputs.n3_synced != 'true' ||
steps.ledger.outputs.n4_synced != 'true' ||
steps.ledger.outputs.n1_freshness != 'true' ||
steps.ledger.outputs.n2_freshness != 'true' ||
steps.ledger.outputs.n3_freshness != 'true' ||
steps.ledger.outputs.n4_freshness != 'true' ||
steps.ledger.outputs.n1_unreachable != 0 ||
steps.ledger.outputs.n2_unreachable != 0 ||
steps.ledger.outputs.n3_unreachable != 0 ||
steps.ledger.outputs.n4_unreachable != 0
uses: actions/github-script@v3
with:
script: core.setFailed('${{ matrix.os_version }} - Not all nodes are in sync!')
- name: Send node restart command
id: node-restart
run: |
echo "::set-output name=restart-time::$(date +%s)"
cd test && echo -e "indy-cli\npool create test gen_txn_file=/pool_transactions_genesis\npool connect test\nwallet create wallet key=1234\nwallet open wallet key=1234\ndid new seed=000000000000000000000000Trustee1\ndid use V4SGRU86Z58d6TV7PBUe6f\nledger pool-restart action=start" | docker-compose run indy-cli
- name: Get node restart status
id: nodes_restarted
run: |
sleep 60
OUTPUT="$(docker container ls --filter "name=node" --format="{{.Names}}" | xargs -n1 docker container inspect --format="{{.State.StartedAt}}" | xargs -I {} date -d {} +%s)"
echo "::set-output name=count::$(echo "$OUTPUT" | awk -F= '$1>${{ steps.node-restart.outputs.restart-time }}' | wc -l)"
- name: Fail if not all nodes restarted
if: steps.nodes_restarted.outputs.count != 4
uses: actions/github-script@v3
with:
script: core.setFailed('${{ matrix.os_version }} - Not all nodes have been restarted')
statusCheck:
name: statusCheck
runs-on: ubuntu-latest
needs: [workflow_setup, test_node_and_controller]
if: ${{ success() }}
steps:
- run: 'echo "Just a status Check (Always true, when executed) for branch protection rules(blocks merging while test are running and if tests fail)." '
push_node:
runs-on: ubuntu-latest
needs: [workflow_setup, test_node_and_controller]
if: ${{ github.event_name != 'pull_request' }}
strategy:
matrix: ${{ fromJson(needs.workflow_setup.outputs.os_matrix) }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: indy-node-version
id: indy-node-version
shell: bash
run: |
export nodeVersion=$(sed "s/~/-/" <<<$(grep -oP "indy-node=\"?\d+.\d+.\d+((~|.)?rc\d+)?\"?" build/Dockerfile.${{ matrix.os_version }} | grep -oP "\d+.\d+.\d+((~|.|-)?rc\d+)?"))
echo "::debug::IndyNode Version is ${nodeVersion}"
echo "::group::DEBUG"
echo "IndyNode Version is ${nodeVersion}"
echo "::endgroup::"
echo "nodeVersion=${nodeVersion}">> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.os_version }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.os_version }}
${{ runner.os }}-buildx
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Meta for indy_node
id: meta_indy_node
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ needs.workflow_setup.outputs.repo_owner }}/indy-node-container/indy_node
flavor: |
prefix=${{ steps.indy-node-version.outputs.nodeVersion }}-${{ matrix.os_version }}-
latest=auto
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
labels: |
org.opencontainers.image.title=Indy Node Container
org.opencontainers.image.description=Indy Node Container based on ${{ matrix.os_version }}
org.opencontainers.image.vendor=Hyperledger
- name: Push indy node based on ${{ matrix.os_version }}
uses: docker/build-push-action@v3
with:
file: build/Dockerfile.${{ matrix.os_version }}
context: ./build
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta_indy_node.outputs.tags }}
labels: ${{ steps.meta_indy_node.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
push_controller:
runs-on: ubuntu-latest
needs: [workflow_setup, test_node_and_controller]
if: ${{ github.event_name != 'pull_request' }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-controler
restore-keys: |
${{ runner.os }}-buildx-controller
${{ runner.os }}-buildx
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Meta for indy_node_controller
id: meta_indy_node_controller
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ needs.workflow_setup.outputs.repo_owner }}/indy-node-container/indy_node_controller
flavor: |
onlatest=true
latest=auto
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
labels: |
org.opencontainers.image.title=Indy Node Container Controller
org.opencontainers.image.description=Indy Node Container Controller
org.opencontainers.image.vendor=Hyperledger
- name: Push indy node controller
uses: docker/build-push-action@v3
with:
context: ./controller
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta_indy_node_controller.outputs.tags }}
labels: ${{ steps.meta_indy_node_controller.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache