-
Notifications
You must be signed in to change notification settings - Fork 58
381 lines (321 loc) · 12.1 KB
/
build-test-deploy.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# build-executable-{arch} job builds the gprofiler executable by running build_{arch}_executable.sh scripts, then uploads it as a job artifact
# test-executable-{arch} job downloads gprofiler exe artifact and then runs test_executable.py tests from tests dir
# deploy-executable job runs only on tagged commits and it deploys gprofiler executables as release assets
# build-container-{arch} job downloads gprofiler exe artifact, produces gprofiler docker image from it, exports it into the file, and uploads image as a job artifact
# test-container-{arch} job downloads gprofiler image artifact and runs tests/test.sh script
# deploy-container job runs only on tagged commits and it deploys gprofiler images to dockerhub
name: Build, test and deploy
on:
pull_request:
push:
tags:
- '**'
jobs:
build-executable-x64:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
# TODO: Add docker layer caching when GitHub Actions cache is stabilized and works good with "satackey/[email protected]"
- name: Build gProfiler executable
# Using BuildKit although it has another cache mechanism which is not supported by satackey/[email protected]
# We tried to cache using buildx cache (cache-from, cache-to flags) and got strange behavior when caching,
# decided not to use buildkit here to get nice caches.
run: |
mkdir -p output
./scripts/build_x86_64_executable.sh
mv build/x86_64/gprofiler output/gprofiler_x86_64
cp output/gprofiler_x86_64 output/gprofiler # for backwards compatibility, we upload both with arch suffix and without
- name: Upload the executables as job artifacts
uses: actions/upload-artifact@v4
with:
name: gprofiler_x86_64
path: output/
retention-days: 1
test-executable-x64:
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-20.04 # the tests which use ruby/node/python etc and run at non-root privs, fail to read the files when running
# on ubuntu-22.04/ubuntu-latest:
# stderr: ruby: Permission denied -- /home/runner/work/gprofiler/gprofiler/tests/containers/ruby/fibonacci.rb (LoadError)
needs: build-executable-x64
strategy:
fail-fast: false
matrix:
containers:
- alpine
- ubuntu:14.04
- ubuntu:16.04
- ubuntu:18.04
- ubuntu:20.04
- ubuntu:20.10
- ubuntu:22.04
- centos:6
- centos:7
- centos:8
- debian:8
- debian:9
- debian:10
- debian:11
steps:
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install Java
uses: actions/setup-java@v1
with:
java-version: '8.0.275'
java-package: jdk
architecture: x64
- name: Install Node.JS
uses: actions/setup-node@v2
with:
# same version as used in tests/containers/nodejs/Dockerfile
node-version: 10.x
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: true
- name: Download the executable from previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_x86_64
path: dist/
- name: Run gProfiler tests
run: |
mv dist/gprofiler_x86_64 dist/gprofiler
chmod +x dist/gprofiler
NO_APT_INSTALL=1 ./tests/test.sh --exec-container-image ${{ matrix.containers }} --executable dist/gprofiler -k test_executable
build-executable-aarch64:
if: startsWith(github.ref, 'refs/tags/')
runs-on:
- self-hosted
- public
- ARM64
- gprofiler
- EC2
- linux
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
- name: Set up requirements
run: scripts/setup_runner_requirements.sh
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build gProfiler executable
run: |
mkdir -p output
./scripts/build_aarch64_executable.sh
mv build/aarch64/gprofiler output/gprofiler_aarch64
- name: Upload the executables as job artifacts
uses: actions/upload-artifact@v4
with:
name: gprofiler_aarch64
path: output/
retention-days: 1
deploy-executable:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
needs:
- build-executable-x64
- build-executable-aarch64
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
# verification before we deploy
- name: Verify release tag matches gProfiler version
run: ./scripts/verify_tag.sh
- name: Download x86_64 executable from a previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_x86_64
path: output/
- name: Download aarch64 executable from a previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_aarch64
path: output/
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
output/gprofiler_x86_64
output/gprofiler_aarch64
output/gprofiler
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-container-x64:
runs-on: ubuntu-latest
needs:
- build-executable-x64
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Download executables from the previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_x86_64
path: output/
# the tests need the gprofiler image built (from Dockerfile). I run it separately here, because "docker build" prints the build logs
# more nicely. the tests will then be able to use the built image.
- name: Build gProfiler image
# see https://github.com/docker/buildx/issues/1507 about the --provenance flag, I decided to go safe without the extra manifest.
# --skip-exe-build needs to be first!
run: ./scripts/build_x86_64_container.sh --skip-exe-build --provenance=false --build-arg EXE_PATH=output/gprofiler_x86_64 -t gprofiler_x86_64
- name: Export gProfiler image
run: mkdir -p output && docker image save gprofiler_x86_64 > output/gprofiler_x86_64.img
- name: Upload the image artifact
uses: actions/upload-artifact@v4
with:
name: gprofiler_x86_64.img
path: output/
retention-days: 1
test-container-x64:
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
needs: build-container-x64
runs-on: ubuntu-20.04 # for 3.10.0 python tag
strategy:
fail-fast: false # helps detecting flakiness / errors specific to one Python version
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10.0" # see https://github.com/Granulate/gprofiler/issues/502, we need 3.10.0, others fail PyPerf tests.
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Java
uses: actions/setup-java@v1
with:
java-version: '8.0.275'
java-package: jdk
architecture: x64
- name: Install Node.JS
uses: actions/setup-node@v2
with:
# same version as used in tests/containers/nodejs/Dockerfile
node-version: 10.x
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: true
- name: Download the executable from previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_x86_64
path: output/
- name: Download the image from previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_x86_64.img
path: output/
- name: Add +x to gprofiler
run: chmod +x ./output/gprofiler_x86_64
- name: Extract resources from gProfiler executable
run: sudo ./output/gprofiler_x86_64 extract-resources --resources-dest=./gprofiler/resources
# used in the tests
- name: Import gProfiler image
run: docker image load < output/gprofiler_x86_64.img
# TODO: Add docker layer caching when GitHub Actions cache is stabilized and works good with "satackey/[email protected]"
- name: Run gProfiler tests
run: NO_APT_INSTALL=1 ./tests/test.sh --ignore=tests/test_executable.py
build-container-aarch64:
if: startsWith(github.ref, 'refs/tags/')
needs: build-executable-aarch64
runs-on:
- self-hosted
- public
- ARM64
- gprofiler
- EC2
- linux
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
- name: Set up runner requirements
run: scripts/setup_runner_requirements.sh
# this gets GH_REPO and RELEASE_VERSION
- name: Get and verify tag value
run: ./scripts/verify_tag.sh
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Download executables from the previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_aarch64
path: output/
# TODO: Add docker layer caching when GitHub Actions cache is stabilized and works good with "satackey/[email protected]"
- name: Build and push
run: |
set -x
BASE_IMAGE="${{ env.GH_REPO }}:${{ env.RELEASE_VERSION }}"
AARCH64_IMAGE="$BASE_IMAGE-aarch64"
# build & push Aarch64
# --skip-exe-build needs to be first!
./scripts/build_aarch64_container.sh --skip-exe-build --provenance=false --build-arg EXE_PATH=output/gprofiler_aarch64 -t "$AARCH64_IMAGE" --push
deploy-container:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs:
- build-container-x64
- build-container-aarch64
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
# this gets GH_REPO and RELEASE_VERSION
- name: Verify release tag matches gProfiler version
run: ./scripts/verify_tag.sh
# build-container-x64 has uploaded the image as an artifact, we donwload it here.
# build-container-aarch64 has pushed the image to DockerHub, so we'll pull it later when creating
# the manifest.
- name: Download the x86_64 image from previous job
uses: actions/download-artifact@v4
with:
name: gprofiler_x86_64.img
path: output/
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Push manifest
run: |
set -x
BASE_IMAGE="${{ env.GH_REPO }}:${{ env.RELEASE_VERSION }}"
LATEST_IMAGE="${{ env.GH_REPO }}:latest"
AARCH64_IMAGE="$BASE_IMAGE-aarch64"
X86_64_IMAGE="$BASE_IMAGE-x86_64"
docker pull --platform=linux/aarch64 $AARCH64_IMAGE
docker image load < output/gprofiler_x86_64.img
docker tag gprofiler_x86_64 $X86_64_IMAGE
docker push $X86_64_IMAGE
# create manifests for the tag + for 'latest'
docker buildx imagetools create -t "$BASE_IMAGE" "$X86_64_IMAGE" "$AARCH64_IMAGE"
docker buildx imagetools create -t "$LATEST_IMAGE" "$X86_64_IMAGE" "$AARCH64_IMAGE"