-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·97 lines (89 loc) · 3.41 KB
/
gke-prod.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
92
93
94
95
96
97
name: Build and Deploy to GKE Prod
on:
release:
types: [released]
# Environment variables available to all jobs and steps in this workflow
env:
GITHUB_SHA: ${{ github.sha }}
K8S_ENVIRONMENT: prod
GIT_USER: lmquang
GIT_EMAIL: quanglm.ops@gmail.com
REGISTRY_HOSTNAME: gcr.io
GKE_PROJECT: df-infrastructure
APP: go-api
IMAGE: go-api
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get files that have changed
id: changed-files-yaml
uses: tj-actions/changed-files@v39
with:
files_yaml: |
code:
- cmd/**
- migrations/**
- mocks/**
- pkg/**
k8s:
- k8s/**
# Setup gcloud CLI
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v0"
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
- name: "Set up Cloud SDK"
if: steps.changed-files-yaml.outputs.code_any_changed == 'true'
uses: "google-github-actions/setup-gcloud@v0"
# Setup Docker
- name: Setup Docker
run: |
gcloud auth configure-docker gcr.io
- name: Cache Docker images
if: steps.changed-files-yaml.outputs.code_any_changed == 'true'
uses: ScribeMD/docker-cache@0.3.6
with:
key: docker-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Build and push
if: steps.changed-files-yaml.outputs.code_any_changed == 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY_HOSTNAME }}/${{ env.GKE_PROJECT }}/${{ env.APP }}/${{ env.IMAGE }}:${{ github.sha }}
- uses: imranismail/setup-kustomize@v2
if: steps.changed-files-yaml.outputs.code_any_changed == 'true' || steps.changed-files-yaml.outputs.k8s_any_changed == 'true'
with:
kustomize-version: "5.1.1"
github-token: ${{ secrets.GH_PAT }}
- name: Generate kustomize resources
if: steps.changed-files-yaml.outputs.code_any_changed == 'true' || steps.changed-files-yaml.outputs.k8s_any_changed == 'true'
run: |
cd ./k8s/$K8S_ENVIRONMENT
kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$APP/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$APP/$IMAGE:${GITHUB_SHA}
kustomize build > /tmp/resources.yaml
# Make sure the infrastructure repo is set up
- name: Checkout dwarvesf/infrastructure
if: steps.changed-files-yaml.outputs.code_any_changed == 'true' || steps.changed-files-yaml.outputs.k8s_any_changed == 'true'
uses: actions/checkout@master
with:
repository: dwarvesf/infrastructure
token: ${{ secrets.GH_PAT }}
path: ./infrastructure
ref: main
- name: Update app version
if: steps.changed-files-yaml.outputs.code_any_changed == 'true' || steps.changed-files-yaml.outputs.k8s_any_changed == 'true'
run: |
cd ./infrastructure/$APP/$K8S_ENVIRONMENT
git config user.name $GIT_USER
git config user.email $GIT_EMAIL
mv /tmp/resources.yaml .
git commit -am "[skip ci] ${APP} ${K8S_ENVIRONMENT} image update"
git push origin main