-
Notifications
You must be signed in to change notification settings - Fork 7
82 lines (74 loc) · 2.72 KB
/
publish.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
name: Publish Docker Image
on:
# TODO: When classify-client is fully cut over to Argo, remove this
# workflow_dispatch trigger
workflow_dispatch: {}
pull_request:
branches:
- master
# push:
# branches:
# - master
# tags:
# - v[0-9]+.[0-9]+.[0-9]+
jobs:
build_image:
name: Build and Publish Image
runs-on: ubuntu-latest
env:
GAR_LOCATION: us
GAR_REPOSITORY: classify-client-prod
GCP_PROJECT_ID: moz-fx-classify-client-pr-09cc
IMAGE: classify-client
permissions:
contents: read
id-token: write
steps:
- id: checkout-application-repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: build-version-json
run: |
printf '{\n "commit": "%s",\n "version": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \
"$(git rev-parse --short HEAD)" \
"$(git describe --tags --abbrev=4)" \
"$(git config --get remote.origin.url)" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json
# Show complete version.json for debugging
cat ./version.json
- uses: docker/setup-buildx-action@v3
- id: gcp_auth
uses: google-github-actions/auth@v2
if: ${{ github.event_name != 'pull_request' }}
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
uses: docker/login-action@v3
if: ${{ github.event_name != 'pull_request' }}
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- 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
# Every workflow run builds a new `latest` image
# Every semver-tagged commit builds a new image tagged with the semver version
tags: |
type=raw,value=latest
type=semver,pattern={{raw}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max