-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (86 loc) · 3.06 KB
/
gar-deploy-template.yml
File metadata and controls
99 lines (86 loc) · 3.06 KB
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
92
93
94
95
96
97
98
99
name: Deploy to infra
on:
workflow_call:
inputs:
INFRASTRUCTURE_REPO:
required: true
type: string
ARGO_APP_NAME:
required: true
type: string
ENVIRONMENT:
required: true
type: string
GAR_REPO_DOMAIN:
required: false
type: string
GAR_REPO_PATH:
required: false
type: string
SERVICE_ACCOUNT:
required: false
type: string
WORKLOAD_IDENTITY_PROVIDER:
required: false
type: string
INFRASTRUCTURE_BRANCH:
required: false
type: string
default: 'main'
IMAGE_PATH:
required: false
type: string
default: '.image.tag'
secrets:
INFRA_SSH_PRIVATE_KEY:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set IMAGE_TAG
run: |-
echo "IMAGE_TAG=$GITHUB_SHA" >> $GITHUB_ENV
- name: Set IMAGE_ID
if: startsWith(github.ref, 'refs/tags/')
run: |-
echo "IMAGE_ID=${{ inputs.GAR_REPO_DOMAIN }}/${{ inputs.GAR_REPO_PATH }}" >> $GITHUB_ENV
- id: 'auth'
if: startsWith(github.ref, 'refs/tags/')
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1.1.1'
with:
workload_identity_provider: ${{ inputs.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ inputs.SERVICE_ACCOUNT }}
- name: Docker configuration
if: startsWith(github.ref, 'refs/tags/')
run: |-
gcloud --quiet auth configure-docker ${{ inputs.GAR_REPO_DOMAIN }}
- name: Pull and tag Docker image
if: startsWith(github.ref, 'refs/tags/')
run: |
docker pull ${{ env.IMAGE_ID }}:${{ env.IMAGE_TAG }}
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_TAG }} ${{ env.IMAGE_ID }}:${{ github.ref_name}}
docker push ${{ env.IMAGE_ID }}:${{ github.ref_name}}
- name: Set new IMAGE_TAG
if: startsWith(github.ref, 'refs/tags/')
run: |-
echo "IMAGE_TAG=$(echo ${{ github.ref_name}})" >> $GITHUB_ENV
- name: Clone infrastructure repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.INFRASTRUCTURE_REPO }}
ref: ${{ inputs.INFRASTRUCTURE_BRANCH }}
ssh-key: ${{ secrets.INFRA_SSH_PRIVATE_KEY }}
- name: Update image tag in values file
run:
yq eval -i '${{ inputs.IMAGE_PATH }}="${{ env.IMAGE_TAG }}"' 'kubernetes/helm/${{ inputs.ARGO_APP_NAME }}/${{ inputs.ENVIRONMENT }}.values.yaml'
- name: commit changes to image tag
run: |
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config user.name "${GITHUB_ACTOR}"
git add kubernetes/helm/${{ inputs.ARGO_APP_NAME }}/${{ inputs.ENVIRONMENT }}.values.yaml
git commit -m "github-action: update image tag to ${{ env.IMAGE_TAG }} by ${GITHUB_ACTOR}"
git push origin ${{ inputs.INFRASTRUCTURE_BRANCH }}