-
Notifications
You must be signed in to change notification settings - Fork 1
76 lines (69 loc) · 2.38 KB
/
common-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
name: Reusable Build workflow
on:
workflow_call:
inputs:
function:
description: "KRM Function name"
required: true
type: string
image_name:
description: "Docker image name"
required: false
type: string
default: "infra/krm-functions"
secrets:
service_account_key:
description: "GCP Service Account Key"
required: true
project_id:
description: "GCP Project ID"
required: true
git_token:
description: "Git PAT for authentication"
required: true
jobs:
build:
name: docker build and push
runs-on: ['self-hosted', 'kubernetes', 'staging']
steps:
- name: checkout
uses: actions/checkout@v2
# Generating the Docker Image Tag
# gcr.io/beecash-prod/infra/krm-functions/jobs:latest
- name: Docker Image Tag creation
id: image_tag
shell: bash
run: |
GCR_PROJECT_ID=${{ secrets.project_id }}
IMAGE="gcr.io/$GCR_PROJECT_ID/${{ inputs.image_name }}/${{ inputs.function }}"
BRANCH="${GITHUB_REF#refs/heads/}"
SHA="$(git rev-parse --short HEAD)"
IMAGE_TAG_FULL="$IMAGE:$BRANCH-$SHA"
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
echo "IMAGE_TAG_FULL=$IMAGE_TAG_FULL" >> $GITHUB_OUTPUT
echo ":whale2: Image Tag: ${IMAGE_TAG_FULL} " >> $GITHUB_STEP_SUMMARY
# Login to GCR
- name: docker login
uses: "lagren/docker-gcr-action@master"
with:
SERVICE_ACCOUNT_KEY: ${{ secrets.service_account_key }}
HOST: "gcr.io"
# Build and push to GCR
- uses: docker/[email protected]
with:
driver: docker
- name: docker publish image
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
build-args: FUNCTION=${{ inputs.function }}
push: true
tags: ${{ steps.image_tag.outputs.IMAGE_TAG_FULL }}
# release krm function to the services
- name: release krm function script
if: success()
uses: addnab/docker-run-action@v3
with:
image: gcr.io/beecash-prod/infra/krm-functions/krm-release:latest
options: -e FUNCTION_NAME=${{ inputs.function }} -e NEW_TAG=${{ steps.image_tag.outputs.IMAGE_TAG_FULL }} -e GIT_TOKEN=${{ secrets.git_token }}