-
Notifications
You must be signed in to change notification settings - Fork 78
341 lines (309 loc) · 10.4 KB
/
deploy-prod.yaml
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
name: deploy-production
on:
push:
tags:
- "v*.*.*"
jobs:
verify-tag:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Verify version tag
run: |
export VERSION_TAG=$GITHUB_REF_NAME
./bin/verify-tag.sh "${VERSION_TAG}"
kurl-util-image:
runs-on: ubuntu-20.04
needs:
- verify-tag
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- run: |
export VERSION_TAG=$GITHUB_REF_NAME
export KURL_UTIL_IMAGE=replicated/kurl-util:${VERSION_TAG}
make -C kurl_util build-and-push-kurl-util-image
docker tag replicated/kurl-util:${VERSION_TAG} replicated/kurl-util
docker push replicated/kurl-util
build-go-bins-matrix:
runs-on: ubuntu-20.04
needs:
- kurl-util-image
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
name: Build image matrix
run: |
export VERSION_TAG=$GITHUB_REF_NAME
export KURL_UTIL_IMAGE=replicated/kurl-util:${VERSION_TAG}
export KURL_BIN_UTILS_FILE=kurl-bin-utils-${VERSION_TAG}.tar.gz
export FILTER_GO_BINS_ONLY="1"
OUTPUT=`bin/list-all-packages-actions-matrix.sh "${{ github.event.inputs.index }}"`
echo "matrix=$OUTPUT" >> $GITHUB_OUTPUT
build-upload-packages:
runs-on: ubuntu-20.04
needs:
- build-go-bins-matrix
strategy:
matrix: ${{fromJSON(needs.build-go-bins-matrix.outputs.matrix)}}
fail-fast: false
max-parallel: 20
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: setup env
id: env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: build and upload packages
run: |
export VERSION_TAG=$GITHUB_REF_NAME
export KURL_UTIL_IMAGE=replicated/kurl-util:${VERSION_TAG}
export KURL_BIN_UTILS_FILE=kurl-bin-utils-${VERSION_TAG}.tar.gz
bin/upload-dist-versioned.sh "${{ matrix.batch }}"
env:
S3_BUCKET: kurl-sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PROD_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PROD_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
get-staging-release:
runs-on: ubuntu-20.04
needs:
- verify-tag
outputs:
staging_release: ${{ steps.get_staging_release.outputs.staging_release }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: find corresponding staging release for commit
id: get_staging_release
run: |
version_commit="$(git rev-list "${GITHUB_REF_NAME}" -n 1 | xargs git rev-parse --short)"
# Grab the release asset directory name in s3. Should look like this:
# PRE v2023.01.03-0-1cee33ec/
staging_release_dir="$(aws s3 ls s3://"${S3_BUCKET}/${STAGING_PREFIX}/" | grep "${version_commit}[0-9a-f]*/" | awk '{print $2}')"
if [ -z "${staging_release_dir}" ]; then
echo "Could not find staging release for commit ${GITHUB_REF_NAME} (${version_commit})"
exit 1
fi
echo "staging_release=${staging_release_dir%/}" >> $GITHUB_OUTPUT
env:
S3_BUCKET: kurl-sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PROD_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PROD_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
STAGING_PREFIX: "staging"
verify-staging-release-testgrid-result:
runs-on: ubuntu-20.04
needs:
- get-staging-release
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify Testgrid Run
run: |
bin/verify-testgrid-run.sh
env:
STAGING_RELEASE: ${{ needs.get-staging-release.outputs.staging_release }}
build-stage-packages-matrix:
runs-on: ubuntu-22.04
needs:
- get-staging-release
- verify-staging-release-testgrid-result
outputs:
package: ${{ steps.set-matrix.outputs.package }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Package Matrix
id: set-matrix
run: |
export LIST_FROM_STAGE_S3="1"
BATCH_S3_PACKAGES=$(./bin/list-all-packages-actions-matrix.sh)
echo "${BATCH_S3_PACKAGES}" | jq
echo "package=${BATCH_S3_PACKAGES}" >> $GITHUB_OUTPUT
env:
S3_BUCKET: kurl-sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PROD_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PROD_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
STAGING_PREFIX: "staging"
STAGING_RELEASE: ${{ needs.get-staging-release.outputs.staging_release }}
copy-stage-packages-to-prod:
runs-on: ubuntu-22.04
needs:
- get-staging-release
- build-stage-packages-matrix
strategy:
matrix: ${{ fromJSON(needs.build-stage-packages-matrix.outputs.package) }}
fail-fast: false
max-parallel: 20
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Copy packages to Prod
run: |
VERSION_TAG=$GITHUB_REF_NAME
batch="${{ matrix.batch }}"
for pkg in ${batch}; do
aws s3api copy-object --copy-source "${S3_BUCKET}/${STAGING_PREFIX}/${STAGING_RELEASE}/${pkg}" --bucket "${S3_BUCKET}" --key "${PACKAGE_PREFIX}/${VERSION_TAG}/${pkg}"
done
env:
S3_BUCKET: kurl-sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PROD_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PROD_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
PACKAGE_PREFIX: "dist"
STAGING_PREFIX: "staging"
STAGING_RELEASE: ${{ needs.get-staging-release.outputs.staging_release }}
generate-kurl-release-notes-pr:
runs-on: ubuntu-20.04
needs:
- set-current-version
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate kURL Release Notes PR
env:
GH_PAT: ${{ secrets.AUTOMATED_PR_GH_PAT }}
run: |
export VERSION_TAG=$GITHUB_REF_NAME
curl -H "Authorization: token $GH_PAT" \
-H 'Accept: application/json' \
-d "{\"event_type\": \"kubernetes-installer-release-notes\", \"client_payload\": {\"version\": \"${VERSION_TAG}\" }}" \
"https://api.github.com/repos/replicatedhq/replicated-docs/dispatches"
github-release:
runs-on: ubuntu-20.04
needs:
- set-current-version
steps:
- name: Checkout
uses: actions/checkout@v4
# Node and Go are needed by the SBOM generator
- uses: actions/setup-node@v3
with:
node-version: '14'
- name: setup-go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Get the version
id: get_tag
shell: bash
run: echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_OUTPUT"
- name: Generate Changelog
run: |
git fetch --tags -f
lastTag=$(git tag | grep '^v20' | grep -v 'v2022\.09\.04' | grep -v "$GIT_TAG" | sort | tail -1)
docker run --rm \
--env CHANGELOG_GITHUB_TOKEN \
-v `pwd`:/usr/local/src/your-app \
ferrarimarco/github-changelog-generator \
--user=replicatedhq \
--project=kurl \
--release-branch=main \
--since-tag="$lastTag" \
--no-issues \
--no-author
sed -i '/This Changelog was automatically generated/d' ./CHANGELOG.md
env:
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_TAG: ${{ steps.get_tag.outputs.GIT_TAG }}
- name: Read Changelog
id: read-changelog
uses: juliangruber/read-file-action@v1
with:
path: ./CHANGELOG.md
- name: GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_TAG: ${{ steps.get_tag.outputs.GIT_TAG }}
with:
tag_name: ${{ env.GIT_TAG }}
release_name: Release ${{ env.GIT_TAG }}
body: ${{ steps.read-changelog.outputs.content }}
draft: false
prerelease: false
- name: Get Cosign Key
run: |
echo $COSIGN_KEY | base64 -d > ./cosign.key
env:
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
- uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.2.1'
- name: Generate SBOM
run: |
make sbom
env:
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
- uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: sbom/assets/*
set-current-version:
runs-on: ubuntu-20.04
needs:
- build-upload-packages
- copy-stage-packages-to-prod
steps:
- name: Set VERSION file in s3
run: |
export VERSION_TAG=$GITHUB_REF_NAME
echo -n "$VERSION_TAG" | aws s3 cp - s3://$S3_BUCKET/$DIST_FOLDER/VERSION
env:
S3_BUCKET: kurl-sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PROD_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PROD_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: "us-east-1"
DIST_FOLDER: "dist"
testgrid-run:
runs-on: ubuntu-20.04
needs:
- set-current-version
steps:
- name: Sleep for 3 minutes
uses: juliangruber/sleep-action@v1
with:
time: "3m"
- name: Checkout
uses: actions/checkout@v4
- name: Get the version
id: get_tag
shell: bash
run: echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_OUTPUT"
- name: Tgrun Queue
id: queue
env:
TESTGRID_API_TOKEN: ${{ secrets.TESTGRID_PROD_API_TOKEN }}
GIT_TAG: ${{ steps.get_tag.outputs.GIT_TAG }}
run: |
REF="PROD-release-${GIT_TAG}-$(date '+%Y%m%d%H%M%S')"
docker pull replicated/tgrun:latest
docker run --rm -e TESTGRID_API_TOKEN -v `pwd`:/wrk -w /wrk \
replicated/tgrun:latest queue \
--ref "${REF}" \
--spec ./testgrid/specs/deploy.yaml \
--os-spec ./testgrid/specs/os-latest.yaml \
--priority 1
MSG="Testgrid Run(s) Executing @ https://testgrid.kurl.sh/run/${REF}"
echo "msg=$MSG" >> "$GITHUB_OUTPUT"
echo "::notice ::${MSG}"