-
Notifications
You must be signed in to change notification settings - Fork 13
323 lines (316 loc) · 13 KB
/
publish.yaml
File metadata and controls
323 lines (316 loc) · 13 KB
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
name: Build and Publish Docker Containers
on:
pull_request:
branches:
- main
push:
branches:
- main
release:
types:
- released
permissions:
contents: read
id-token: write
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1 # Reduce warnings from Docker Buildx
GAR_LOCATION: us
GAR_REPOSITORY: remote-settings-prod
GCP_PROJECT_ID: moz-fx-remote-settings-prod
jobs:
server_container:
env:
DOCKERHUB_IMAGE_NAME: mozilla/remote-settings
GAR_IMAGE_NAME: remote-settings
runs-on: ubuntu-latest
environment: build
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Enable multiplatform builds
uses: docker/setup-buildx-action@v4
with:
buildkitd-flags: "--debug" # Enable detailed logging
- name: Set tag version
run: echo "LATEST_TAG=$(git describe --tags --abbrev=4)" >> "$GITHUB_ENV"
- name: Create version.json
run: |
# create a version.json per https://github.com/mozilla-services/Dockerflow/blob/main/docs/version_object.md
printf '{\n "commit": "%s",\n "version": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \
"$GITHUB_SHA" \
"$LATEST_TAG" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json
# Show complete version.json for debugging
cat ./version.json
- name: Extract metadata for Google Artifact Registry
id: metagar
uses: docker/metadata-action@v6
with:
flavor:
# don't automatically tag with `latest`; we do this conditionally in the `tags` section
latest=false
images: |
${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.GAR_IMAGE_NAME }}
tags: |
type=raw,value=${{ env.LATEST_TAG }},enable=${{ github.event_name == 'push' }}
type=sha,format=long,enable=${{ github.event_name == 'push' }}
type=semver,pattern={{raw}},enable=${{ github.event_name == 'release' }}
- name: Docker Metadata for Docker Hub
id: metahub
uses: docker/metadata-action@v6
with:
flavor:
# don't automatically tag with `latest`; we do this conditionally in the `tags` section
latest=false
images: |
${{ env.DOCKERHUB_IMAGE_NAME }}
tags: |
type=semver,pattern={{raw}},enable=${{ github.event_name == 'release' }}
type=raw,value=latest,enable=${{ github.event_name == 'push' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Authenticate on GCP
id: gcp_auth
uses: google-github-actions/auth@v3
with:
token_format: access_token
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}
- name: Login to GAR
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push to GAR
if: ${{ github.event_name == 'push' }}
uses: docker/build-push-action@v7
with:
context: .
file: RemoteSettings.Dockerfile
sbom: true
target: production # See multi-stage build
push: true
tags: ${{ steps.metagar.outputs.tags }}
labels: ${{ steps.metagar.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha # Load cache from GitHub Actions
cache-to: type=gha,mode=max # Save cache to GitHub Actions
- name: Build and push release to GAR
if: ${{ github.event_name == 'release' }}
uses: docker/build-push-action@v7
with:
context: .
file: Release.Dockerfile
sbom: true
push: true
tags: ${{ steps.metagar.outputs.tags }}
labels: ${{ steps.metagar.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha # Load cache from GitHub Actions
cache-to: type=gha,mode=max # Save cache to GitHub Actions
build-args: BASE_IMG=${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY}}/remote-settings:sha-${{ github.sha }}
- name: Copy from Google Artifact Registry to Docker Hub
if: github.event_name != 'pull_request'
env:
TAGS: |
${{ steps.metahub.outputs.tags }}
SRC: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY}}/remote-settings:${{ env.LATEST_TAG }}
run: |
for tag in $TAGS; do
docker buildx imagetools create --tag "${tag}" "${SRC}"
done
- name: Notify DEVs of build failure
if: failure()
uses: slackapi/slack-github-action@v3.0.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "⚠️ Build of ${{ env.GAR_IMAGE_NAME }}:${{ env.LATEST_TAG }} failed. Please review logs and correct issues."
cronjobs_container:
env:
GAR_IMAGE_NAME: remote-settings-core-cronjobs
LATEST_TAG: "" # Set after checkout step
runs-on: ubuntu-latest
environment: build
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set tag version
run: echo "LATEST_TAG=$(git describe --tags --abbrev=4)" >> "$GITHUB_ENV"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.GAR_IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.LATEST_TAG }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Authenticate on GCP
id: gcp_auth
uses: google-github-actions/auth@v3
with:
token_format: access_token
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}
- name: Login to GAR
if: github.event_name == 'push'
uses: docker/login-action@v4
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: cronjobs/
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha # Load cache from GitHub Actions
cache-to: type=gha,mode=max # Save cache to GitHub Actions
- name: Notify DEVs of build failure
if: failure()
uses: slackapi/slack-github-action@v3.0.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "⚠️ Build of ${{ env.GAR_IMAGE_NAME }}:${{ env.LATEST_TAG }} failed. Please review logs and correct issues."
browser_test_container:
env:
GAR_IMAGE_NAME: remote-settings-browser-tests
LATEST_TAG: "" # Set after checkout step
runs-on: ubuntu-latest
environment: build
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set tag version
run: echo "LATEST_TAG=$(git describe --tags --abbrev=4)" >> "$GITHUB_ENV"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.GAR_IMAGE_NAME }}
tags: |
type=raw,value=${{ env.LATEST_TAG }}
type=raw,value=latest
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Authenticate on GCP
id: gcp_auth
uses: google-github-actions/auth@v3
with:
token_format: access_token
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}
- name: Login to GAR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v4
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: browser-tests/
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha # Load cache from GitHub Actions
cache-to: type=gha,mode=max # Save cache to GitHub Actions
- name: Notify DEVs of build failure
if: failure()
uses: slackapi/slack-github-action@v3.0.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "⚠️ Build of ${{ env.GAR_IMAGE_NAME }}:${{ env.LATEST_TAG }} failed. Please review logs and correct issues."
git_reader_container:
env:
GAR_IMAGE_NAME: remote-settings-git-reader
LATEST_TAG: "" # Set after checkout step
runs-on: ubuntu-latest
environment: build
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set tag version
run: echo "LATEST_TAG=$(git describe --tags --abbrev=4)" >> "$GITHUB_ENV"
- name: Create version.json
run: |
# create a version.json per https://github.com/mozilla-services/Dockerflow/blob/main/docs/version_object.md
printf '{\n "commit": "%s",\n "version": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \
"$GITHUB_SHA" \
"$LATEST_TAG" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./git-reader/version.json
# Show complete version.json for debugging
cat ./git-reader/version.json
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: |
${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.GAR_IMAGE_NAME }}
tags: |
type=raw,value=${{ env.LATEST_TAG }},enable=${{ github.event_name == 'push' }}
type=sha,format=long,enable=${{ github.event_name == 'push' }}
type=semver,pattern={{raw}},enable=${{ github.event_name == 'release' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Authenticate on GCP
id: gcp_auth
uses: google-github-actions/auth@v3
with:
token_format: access_token
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}
- name: Login to GAR
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v4
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: git-reader/
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha # Load cache from GitHub Actions
cache-to: type=gha,mode=max # Save cache to GitHub Actions
- name: Notify DEVs of build failure
if: failure()
uses: slackapi/slack-github-action@v3.0.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
text: "⚠️ Build of ${{ env.GAR_IMAGE_NAME }}:${{ env.LATEST_TAG }} failed. Please review logs and correct issues."