-
Notifications
You must be signed in to change notification settings - Fork 1
83 lines (74 loc) · 2.51 KB
/
build.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
name: Build image and push to GAR
on:
push:
branches:
- main
tags:
- v[0-9]+.[0-9]+.[0-9]+
env:
GAR_LOCATION: us
GAR_REPOSITORY: ctms-prod
GCP_PROJECT_ID: moz-fx-ctms-prod
IMAGE: ctms
IMAGE_PLATFORMS: linux/amd64,linux/arm64
jobs:
build:
name: build
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- id: determine_tag
name: determine tag
run: |-
TAG=$(git describe --tags)
printf "\e[1;36m[INFO]\e[0m \$TAG=\"${TAG}\"\n"
echo TAG=${TAG} >> ${GITHUB_OUTPUT}
- id: meta
name: generate Docker image metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE }}
# https://github.com/marketplace/actions/docker-metadata-action#tags-input
tags: |
type=raw,value=${{ steps.determine_tag.outputs.TAG }}
type=raw,value=latest
- id: generate_version_json
name: generate version.json
run: |-
printf '{"commit":"%s","version":"%s","source":"%s","build":"%s"}\n' \
"$(git rev-parse HEAD)" \
"${{ steps.determine_tag.outputs.TAG }}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | tee version.json
- id: gcp_auth
name: gcp auth
uses: google-github-actions/auth@v2
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 }}
- id: docker_login
name: docker login
uses: docker/login-action@v3
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- id: build_and_push
name: build and push
uses: docker/build-push-action@v6
with:
platforms: ${{ env.IMAGE_PLATFORMS }}
context: .
tags: ${{ steps.meta.outputs.tags }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max