-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
87 lines (76 loc) · 2.77 KB
/
action.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
77
78
79
80
81
82
83
84
85
86
87
name: GKE Deploy via Artifact Registry
description: "Deploys containers to GKE via Google Artifact Registry"
inputs:
GOOGLE_CLOUD_PROJECT_ID:
description: "Google Cloud Project ID you want to use."
required: true
GOOGLE_CLOUD_SERVICE_ACCOUNT_KEY:
description: "Google Cloud Service Account KEY"
required: true
DOCKER_BUILD_ARGS:
description: If you want to inject build params to docker build step.
required: true
GKE_ZONE:
description: "GKE Zone"
required: true
GKE_CLUSTER:
description: "Name of the cluster"
required: true
ARTIFACT_REGISTRY_REGION:
description: "Google Artifact Registry region you want to use"
required: true
ARTIFACT_REGISTRY_REPO:
description: "Google artifact Registry repository you want to store your build image in"
required: true
ARTIFACT_REGISTRY_IMAGE:
description: "Google Artifact Registry image"
required: true
IMAGE_TAG:
description: "Tag for your image"
required: true
GKE_CONFIG_DIR:
description: "K8S config file directory."
required: true
GKE_IMAGE_TEMPLATE:
description: "GKE Deployment Image Template"
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Auth Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ inputs.GOOGLE_CLOUD_SERVICE_ACCOUNT_KEY }}"
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ inputs.GOOGLE_CLOUD_PROJECT_ID }}
- name: Setup Docker Auth
shell: bash
run: |-
gcloud --quiet auth configure-docker ${{ inputs.ARTIFACT_REGISTRY_REGION }}-docker.pkg.dev
- name: Setup AR image tag url
shell: bash
run: echo "ar_image_tag=${{ inputs.ARTIFACT_REGISTRY_REGION }}-docker.pkg.dev/${{ inputs.GOOGLE_CLOUD_PROJECT_ID }}/${{ inputs.ARTIFACT_REGISTRY_REPO }}/${{ inputs.ARTIFACT_REGISTRY_IMAGE }}:${{ inputs.IMAGE_TAG }}" >> $GITHUB_ENV
- name: Building the Docker Image
shell: bash
run: |-
docker build --tag "${{ env.ar_image_tag }}" --build-arg version="${{ inputs.IMAGE_TAG }}" ${{ inputs.DOCKER_BUILD_ARGS }} .
- name: Push the Image to Google Artifact Registry
shell: bash
run: |-
docker push ${{ env.ar_image_tag }}
- name: Setup GKE Credentials
uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: ${{ inputs.GKE_CLUSTER }}
location: ${{ inputs.GKE_ZONE }}
- name: Deploy image from AR to GKE
shell: bash
run: |-
cd ${{ inputs.GKE_CONFIG_DIR }}
kustomize edit set image ${{ inputs.GKE_IMAGE_TEMPLATE }}=${{ env.ar_image_tag }}
kubectl apply -k .