-
Notifications
You must be signed in to change notification settings - Fork 18
277 lines (266 loc) · 9.57 KB
/
docker-v2-release.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
name: Docker v2 release
on:
pull_request: # TODO: Remove after testing the PR
release:
types: [published]
push:
branches:
- release\/*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
env:
TMP_LOCAL_IMAGE: localhost:5000/radixdlt/babylon-node-test
REGISTRY_IMAGE: radixdlt/babylon-node-test # TODO: Rename to babylon-node after testing the PR
jobs:
setup_version_properties:
name: Setup version properties
runs-on: ubuntu-latest
outputs:
VERSION_BRANCH: ${{ steps.setup_version_properties.outputs.VERSION_BRANCH }}
VERSION_BUILD: ${{ steps.setup_version_properties.outputs.VERSION_BUILD }}
VERSION_COMMIT: ${{ steps.setup_version_properties.outputs.VERSION_COMMIT }}
VERSION_DISPLAY: ${{ steps.setup_version_properties.outputs.VERSION_DISPLAY }}
VERSION_TAG: ${{ steps.setup_version_properties.outputs.VERSION_TAG }}
VERSION_LAST_TAG: ${{ steps.setup_version_properties.outputs.VERSION_LAST_TAG }}
steps:
- uses: RDXWorks-actions/checkout@main
with:
fetch-depth: 0
- name: Setup version properties
id: setup_version_properties
uses: ./.github/actions/setup-version-properties
setup_tags:
name: Setup Docker tags
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.setup_tags.outputs.tag }}
steps:
- uses: RDXWorks-actions/checkout@main
with:
fetch-depth: 0
- id: setup_tags
run: echo "tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
build_deb:
name: Build debian package
runs-on: ubuntu-latest-8-cores
needs:
- setup_version_properties
env:
VERSION_BRANCH: ${{ needs.setup_version_properties.outputs.VERSION_BRANCH }}
VERSION_COMMIT: ${{ needs.setup_version_properties.outputs.VERSION_COMMIT }}
VERSION_DISPLAY: ${{ needs.setup_version_properties.outputs.VERSION_DISPLAY }}
VERSION_BUILD: ${{ needs.setup_version_properties.outputs.VERSION_BUILD }}
VERSION_TAG: ${{ needs.setup_version_properties.outputs.VERSION_TAG }}
VERSION_LAST_TAG: ${{ needs.setup_version_properties.outputs.VERSION_LAST_TAG }}
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: RDXWorks-actions/checkout@main
with:
fetch-depth: 0
- uses: RDXWorks-actions/toolchain@master
with:
toolchain: stable
- name: Set up JDK 17
uses: RDXWorks-actions/setup-java@main
with:
distribution: 'zulu'
java-version: '17'
- name: Cache Gradle packages
uses: RDXWorks-actions/cache@main
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}-deb
restore-keys: ${{ runner.os }}-gradle-deb
- name: Restore cached image-cache
id: cache-image-restore
uses: RDXWorks-actions/cache/restore@main
with:
path: /tmp/outputs/cache/docker
key: babylon-node-default-${{ hashFiles('./Dockerfile') }}
- name: Set up Docker Context for Buildx
run: |
docker context create builders | true
- name: Set up Docker Buildx
uses: RDXWorks-actions/setup-buildx-action@master
with:
version: latest
endpoint: builders
- name: Create deb package
run: |
sudo apt-get update && sudo apt-get install -y make
cd core && make build-core
- name: Upload generated debian package
uses: RDXWorks-actions/upload-artifact@main
with:
name: deb4docker
path: "${{ github.workspace }}/docker/*.deb"
build_docker:
strategy:
matrix:
os: ["ubuntu-latest-8-cores", "ubuntu-latest-arm-8-cores"]
arch: ["amd64", "arm64"]
exclude:
- os: ubuntu-latest-8-cores
arch: arm64
- os: ubuntu-latest-arm-8-cores
arch: amd64
name: Build docker image
runs-on: ${{ matrix.os }}
needs:
- setup_version_properties
steps:
- name: Checkout
uses: RDXWorks-actions/checkout@main
- name: Set up Docker Buildx
uses: RDXWorks-actions/setup-buildx-action@master
- name: Prepare build
run: |
mkdir -p /tmp/images
platform=${{ matrix.arch }}
echo "TARFILE=${platform}.tar" >> $GITHUB_ENV
echo "TAG=${{ env.TMP_LOCAL_IMAGE }}:${platform}" >> $GITHUB_ENV
- name: Build
uses: RDXWorks-actions/build-push-action@v6
with:
file: ./Dockerfile.v2
context: .
platforms: linux/${{ matrix.arch }}
tags: ${{ env.TAG }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=docker,dest=/tmp/images/${{ env.TARFILE }}
push: false
build-args: |
VERSION_BRANCH=${{ needs.setup_version_properties.outputs.VERSION_BRANCH }}
VERSION_COMMIT=${{ needs.setup_version_properties.outputs.VERSION_COMMIT }}
VERSION_DISPLAY=${{ needs.setup_version_properties.outputs.VERSION_DISPLAY }}
VERSION_BUILD=${{ needs.setup_version_properties.outputs.VERSION_BUILD }}
VERSION_TAG=${{ needs.setup_version_properties.outputs.VERSION_TAG }}
VERSION_LAST_TAG=${{ needs.setup_version_properties.outputs.VERSION_LAST_TAG }}
- name: Upload images
uses: RDXWorks-actions/upload-artifact-v4@main
with:
name: images-${{ matrix.arch }}
path: /tmp/images/${{ env.TARFILE }}
if-no-files-found: error
retention-days: 1
push_docker:
name: Push combined docker image
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
needs:
- build_docker
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- name: Docker meta
id: meta
uses: RDXWorks-actions/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=sha,event=pr
type=sha,event=branch
type=semver,pattern={{version}}
- uses: RDXWorks-actions/download-artifact-v4@main
name: Download images (amd64)
with:
name: images-amd64
path: /tmp/images
- uses: RDXWorks-actions/download-artifact-v4@main
name: Download images (arm64)
with:
name: images-arm64
path: /tmp/images
- name: Load images
run: |
for image in /tmp/images/*.tar; do
docker load -i $image
done
- name: Configure AWS credentials
uses: RDXWorks-actions/configure-aws-credentials@main
with:
role-to-assume: ${{ secrets.COMMON_SECRETS_ROLE_ARN }}
aws-region: eu-west-2
- name: Setup dockerhub credentials
uses: RDXWorks-actions/aws-secretsmanager-get-secrets@main
with:
secret-ids: |
DOCKERHUB_PRIVATE, github-actions/common/dockerhub-credentials
parse-json-secrets: true
- name: Login to Docker Hub
uses: RDXWorks-actions/login-action@master
with:
username: ${{env.DOCKERHUB_PRIVATE_USERNAME}}
password: ${{env.DOCKERHUB_PRIVATE_TOKEN}}
- name: Set up Docker Buildx
uses: RDXWorks-actions/setup-buildx-action@master
- name: Push images to local registry
run: |
docker push -a ${{ env.TMP_LOCAL_IMAGE }}
docker images
- name: Create manifest list and push
run: |
docker buildx imagetools create -t ${{ env.REGISTRY_TAG }} \
$(docker image ls --format '{{.Repository}}:{{.Tag}}' '${{ env.TMP_LOCAL_IMAGE }}' | tr '\n' ' ')
env:
REGISTRY_TAG: ${{ steps.meta.outputs.tags }}
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_TAG }}
env:
REGISTRY_TAG: ${{ steps.meta.outputs.tags }}
snyk_container_monitor:
name: Snyk monitor container
runs-on: ubuntu-latest
needs:
- push_docker
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
steps:
- uses: radixdlt/public-iac-resuable-artifacts/snyk-container-monitor@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'babylon-node'
dockerhub_secret_name: ${{ secrets.AWS_SECRET_NAME_DOCKERHUB }}
snyk_secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
snyk_org_id: ${{ secrets.SNYK_ORG_ID }}
image: docker.io/${{ env.REGISTRY_IMAGE }}:${{ github.event.release.tag_name }}
target_ref: ${{ github.ref_name }}
snyk_monitor:
name: Snyk monitor
runs-on: ubuntu-latest
needs:
- push_docker
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
steps:
- uses: RDXWorks-actions/checkout@main
- uses: radixdlt/public-iac-resuable-artifacts/fetch-secrets@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'babylon-node'
step_name: 'snyk-monitor'
secret_prefix: 'SNYK'
secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
parse_json: true
- name: Enable Snyk online monitoring to check for vulnerabilities
uses: RDXWorks-actions/snyk-actions/gradle-jdk17@master
with:
args: --all-projects --org=${{ env.SNYK_NETWORK_ORG_ID }} --target-reference=${{ github.ref_name }}
command: monitor