-
Notifications
You must be signed in to change notification settings - Fork 742
240 lines (211 loc) · 10.6 KB
/
build.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
on:
push:
branches:
- main
pull_request:
schedule:
- cron: "0 0 * * *"
concurrency:
group: build-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }}
cancel-in-progress: true
env:
BUILDKIT_PROGRESS: plain
DISCOURSE_TURBO_RSPEC_RETRY_AND_LOG_FLAKY_TESTS: true
jobs:
timestamp:
runs-on: ubuntu-latest
outputs:
timestamp: ${{ steps.timestamp.outputs.timestamp }}
steps:
- id: timestamp
run: |
timestamp=`date +%Y%m%d-%H%M`
echo "timestamp=$timestamp"
echo "timestamp=$timestamp" >> $GITHUB_OUTPUT
base:
# `unbuntu-22.04-8core` for arch amd64 non-scheduled builds
# `unbuntu-22.04` for arch amd64 scheduled builds
# `unbuntu-22.04-8core-arm` for arch arm64 non-scheduled builds
# `unbuntu-22.04-2core-arm` for arch arm64 scheduled builds
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule') && '-8core') || (( matrix.arch == 'arm64' && '-2core' ) || '') }}${{ (matrix.arch == 'arm64') && '-arm' || '' }}
strategy:
matrix:
arch: [amd64, arm64]
timeout-minutes: ${{ (github.event_name == 'schedule' && 90) || ((matrix.arch == 'arm64' && 45) || 30) }}
needs: timestamp
env:
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: build deps image
working-directory: image
run: |
ruby auto_build.rb base_deps_${{ matrix.arch }}
- name: build slim image for `main` branch
working-directory: image
run: |
ruby auto_build.rb base_slim_main_${{ matrix.arch }}
- name: tag slim image for `main` branch
run: |
docker tag discourse/base:build_slim_main_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
- name: build slim image for `stable` branch
working-directory: image
run: |
ruby auto_build.rb base_slim_stable_${{ matrix.arch }}
- name: build release images for `main` branch
working-directory: image
run: |
ruby auto_build.rb base_release_main_${{ matrix.arch }}
- name: build release images for `stable` branch
working-directory: image
run: |
ruby auto_build.rb base_release_stable_${{ matrix.arch }}
- name: tag release images
run: |
docker tag discourse/base:build_release_main_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
docker tag discourse/base:build_release_stable_${{ matrix.arch }} discourse/base:2.0.${{ env.TIMESTAMP }}-stable-${{ matrix.arch }}
- name: build test_build image for `main` branch
working-directory: image
run: |
ruby auto_build.rb discourse_test_build_${{ matrix.arch }}
- name: run specs for `main` branch
run: |
docker run --rm -e RUBY_ONLY=1 -e USE_TURBO=1 -e SKIP_PLUGINS=1 -e SKIP_LINT=1 discourse/discourse_test:build_${{ matrix.arch }}
- name: build & tag dev image for `main` branch
working-directory: image
run: |
ruby auto_build.rb discourse_dev_${{ matrix.arch }}
docker tag discourse/discourse_dev:build_${{ matrix.arch }} discourse/discourse_dev:${{ env.TIMESTAMP }}-${{ matrix.arch }}
- name: Print summary
run: |
docker images discourse/base
- name: Print `docker history` summary for main branch image
run: |
docker history discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
- name: Print compressed summary
if: github.event_name == 'pull_request' && matrix.arch == 'amd64'
run: |
# Push to local repo to compare sizes
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} localhost:5000/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} localhost:5000/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
docker push --quiet localhost:5000/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
docker push --quiet localhost:5000/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
# multiarch manifest is an array of schemas - [0] is amd64, [1] is arch64: Compare amd64.
CURRENT_SLIM=$(docker manifest inspect -v discourse/base:slim | jq -r '.[0].SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
CURRENT_RELEASE=$(docker manifest inspect -v discourse/base:release | jq -r '.[0].SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
NEW_SLIM=$(docker manifest inspect -v --insecure localhost:5000/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | jq -r '.SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
NEW_RELEASE=$(docker manifest inspect -v --insecure localhost:5000/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | jq -r '.SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
echo "current slim: ${CURRENT_SLIM}MB release: ${CURRENT_RELEASE}MB. new slim: ${NEW_SLIM}MB release: ${NEW_RELEASE}MB"
- name: push to dockerhub
if: github.ref == 'refs/heads/main'
env:
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
docker login --username discoursebuild --password $DOCKERHUB_PASSWORD
docker push discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
docker push discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
docker push discourse/base:2.0.${{ env.TIMESTAMP }}-stable-${{ matrix.arch }}
docker push discourse/discourse_dev:${{ env.TIMESTAMP }}-${{ matrix.arch }}
- name: Push discourse/base:aarch64 image for backwards compatibility
if: (github.ref == 'refs/heads/main') && (matrix.arch == 'arm64')
run: |
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} discourse/base:aarch64
docker push discourse/base:aarch64
push_multiarch_manifests:
runs-on: ubuntu-latest
needs: [base, timestamp]
env:
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
if: github.ref == 'refs/heads/main'
steps:
- name: create and push multiarch manifests
run: |
docker login --username discoursebuild --password ${{ secrets.DOCKERHUB_PASSWORD }}
# Slim timestamped
docker manifest create discourse/base:2.0.${{ env.TIMESTAMP }}-slim \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-arm64
# Slim release
docker manifest create discourse/base:slim \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-slim-arm64
# Full Discourse `main` branch timestamped
docker manifest create discourse/base:2.0.${{ env.TIMESTAMP }} \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64
# Full Discourse `stable` branch timestamped
docker manifest create discourse/base:2.0.${{ env.TIMESTAMP }}-stable \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-arm64
# Full Discourse `main` branch release
docker manifest create discourse/base:release \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-main-arm64
# Full Discourse `stable` branch release
docker manifest create discourse/base:release-stable \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-amd64 \
-a discourse/base:2.0.${{ env.TIMESTAMP }}-stable-arm64
# Dev timestamped
docker manifest create discourse/discourse_dev:${{ env.TIMESTAMP }} \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-amd64 \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-arm64
# Dev release
docker manifest create discourse/discourse_dev:release \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-amd64 \
-a discourse/discourse_dev:${{ env.TIMESTAMP }}-arm64
docker manifest push discourse/base:2.0.${{ env.TIMESTAMP }}-slim
docker manifest push discourse/base:slim
docker manifest push discourse/base:2.0.${{ env.TIMESTAMP }}
docker manifest push discourse/base:2.0.${{ env.TIMESTAMP }}-stable
docker manifest push discourse/base:release
docker manifest push discourse/base:release-stable
docker manifest push discourse/discourse_dev:${{ env.TIMESTAMP }}
docker manifest push discourse/discourse_dev:release
test:
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule') && '-8core') || '' }}
timeout-minutes: 30
needs: base
defaults:
run:
working-directory: image/discourse_test
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: build discourse_test:slim
run: |
docker buildx build . --load \
--build-arg from_tag=slim \
--target base \
--tag discourse/discourse_test:slim
- name: build discourse_test:slim-browsers
run: |
docker buildx build . --load \
--build-arg from_tag=slim \
--target with_browsers \
--tag discourse/discourse_test:slim-browsers
- name: build discourse_test:release
run: |
docker buildx build . --load \
--build-arg from_tag=release \
--target release \
--tag discourse/discourse_test:release
- name: Print summary
run: |
docker images discourse/discourse_test
- name: push to dockerhub
if: success() && (github.ref == 'refs/heads/main')
env:
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
docker login --username discoursebuild --password $DOCKERHUB_PASSWORD
docker push discourse/discourse_test:slim
docker push discourse/discourse_test:slim-browsers
docker push discourse/discourse_test:release