-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (86 loc) · 3.04 KB
/
build-publish-image-gcr.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
---
name: Build and Publish Image Workflow
on:
workflow_call:
secrets:
WORKLOAD_ID_PROVIDER:
required: true
SERVICE_ACCOUNT:
required: true
inputs:
GCP_PROJECT:
required: true
type: string
VERSION_FILE_PATH:
required: true
type: string
IMAGE_NAME:
required: true
type: string
DOCKER_PATH_CONTEXT:
required: true
type: string
DOCKER_FILE:
required: false
type: string
outputs:
version_number:
value: ${{ jobs.build.outputs.version_number }}
jobs:
build-publish-image:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
# Get version number from version file and store this
- name: Get Version Number
id: vars
shell: bash
run: |
echo "version_number=$(cat ${{ inputs.VERSION_FILE_PATH }})" >> $GITHUB_OUTPUT
# Set-up Docker Buildx
- name: Set up Docker Buildx
id: setup_buildx
uses: docker/setup-buildx-action@v2
- name: Authenticate to Google Cloud
id: gcloud_auth
uses: google-github-actions/auth@v0
with:
workload_identity_provider: ${{ secrets.WORKLOAD_ID_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}
project_id: ${{ inputs.GCP_PROJECT }}
token_format: access_token
- name: Login to GCR
id: login_to_gcr
uses: docker/login-action@v2
with:
registry: gcr.io
username: oauth2accesstoken
password: ${{ steps.gcloud_auth.outputs.access_token }}
# build docker metadata
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: |
gcr.io/${{ inputs.GCP_PROJECT }}/${{ inputs.IMAGE_NAME }}
tags: |
latest
type=ref,event=branch
type=ref,event=pr
${{ steps.vars.outputs.version_number }}
# build and push container
- name: Build and push container
id: build_push_container
uses: docker/build-push-action@v3
with:
context: ${{ inputs.DOCKER_PATH_CONTEXT }}
file: ${{ inputs.DOCKER_FILE }}
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs:
version_number: ${{ steps.vars.outputs.version_number }}