-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (53 loc) · 1.81 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
# Build and push Docker image to docker hub
name: Build
on:
push:
# Sequence of patterns matched against refs/heads
branches:
- master
tags:
- "*"
jobs:
build-and-push:
name: BuildAndPush
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
env:
IMAGE_NAME: prometheus-sleeker
GCP_PROJECT_ID: quortex-registry-public
steps:
# This step uses Github's checkout-action: https://github.com/actions/checkout
- name: Check out code
uses: actions/checkout@v3
# Deduced the appropriate tag for the image (inspired by the docker action https://github.com/actions-hub/docker)
- name: Set env
run: |
IMAGE_TAG=${TAG} && \
if [[ -z "${IMAGE_TAG}" ]]; then \
IMAGE_TAG=${GITHUB_REF#*/}; \
IMAGE_TAG=${IMAGE_TAG#*/}; \
IMAGE_TAG=$(echo $IMAGE_TAG | sed -e "s#^v##"); \
if [[ "$IMAGE_TAG" == "master" || "$IMAGE_TAG" == "main" ]]; then \
IMAGE_TAG=latest; \
fi \
fi && \
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
# Setup gcloud CLI
- uses: google-github-actions/auth@v1
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_POOL }}
service_account: ${{ vars.SERVICE_ACCOUNT }}
# Build docker image
- name: Build
run: |-
docker build -t eu.gcr.io/${{ env.GCP_PROJECT_ID }}/$IMAGE_NAME:$IMAGE_TAG .
# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
gcloud auth configure-docker -q
# Push image to Google Container Registry
- name: Push
run: |-
docker push eu.gcr.io/${{ env.GCP_PROJECT_ID }}/$IMAGE_NAME:$IMAGE_TAG