-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (101 loc) · 3.55 KB
/
Copy pathkustomize-deploy-commit.yml
File metadata and controls
108 lines (101 loc) · 3.55 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
100
101
102
103
104
105
106
107
108
name: Kustomize Deploy Commit
on:
workflow_call:
inputs:
KUBERNETES_REPO:
required: true
description: 'The GitHub repository to deploy to'
type: string
KUBERNETES_REPO_REF:
required: false
description: 'The GitHub repository reference to deploy to'
type: string
default: 'master'
GITHUB_EMAIL:
required: true
type: string
APPLICATION:
description: 'The name of the application directory where manifests are stored'
required: true
type: string
APPLICATION_IMAGE:
description: 'The name of the application you want the image digest updated for'
required: false
type: string
APPLICATION_TYPE:
required: false
description: 'The type of application to deploy, e.g. applications, platform'
type: string
default: 'applications'
KUSTOMIZE_PATH:
required: false
type: string
default: kustomize/overlays/instances
CLUSTERS:
required: true
description: 'The list of cluster instances to deploy to'
type: string
ENVIRONMENT:
required: true
type: string
IMAGE_DIGEST:
required: true
type: string
REGISTRY:
required: false
default: ""
type: string
secrets:
IS_CICD_GITHUB_ACTION_TOKEN:
required: true
jobs:
kustomize-deploy-commit:
runs-on: ubuntu-24.04
name: kustomize-deploy-commit
steps:
- name: Check out code
uses: actions/checkout@v3
with:
repository: ${{ inputs.KUBERNETES_REPO }}
fetch-depth: 0
ref: ${{ inputs.KUBERNETES_REPO_REF }}
token: ${{ secrets.IS_CICD_GITHUB_ACTION_TOKEN }}
- name: Update kubernetes resources
uses: stefanprodan/kube-tools@v1
- name: Setup git
run: |
git config --global user.name "github-action-bot"
git config --global user.email "${{ inputs.GITHUB_EMAIL }}"
- name: Update image digest for each cluster
run: |
if [ -z "${{ inputs.APPLICATION_IMAGE }}" ]; then
APPLICATION_IMAGE="${{ inputs.APPLICATION }}"
else
APPLICATION_IMAGE="${{ inputs.APPLICATION_IMAGE }}"
fi
clusters="${{ inputs.CLUSTERS }}"
a=($(echo "$clusters" | tr ',' '\n'))
for i in "${a[@]}"
do
echo "Updating image digest for $i"
(set -eux; cd ${{ inputs.APPLICATION_TYPE }}/${{ inputs.APPLICATION }}/${{ inputs.KUSTOMIZE_PATH }}/$i && kustomize edit set image ${{inputs.REGISTRY}}expedient/$APPLICATION_IMAGE@${{ inputs.IMAGE_DIGEST }})
if [ $? -ne 0 ]; then
echo "Instance $i not found"
exit 1
fi
done
- name: Update the deployed app version
if: ${{ github.event.inputs.version != '' }}
uses: mikefarah/yq@v4.18.1
with:
cmd: yq -i '.spec.template.spec.containers[1].env[0].value = "$(date -u +"%Y.%m.%d %H:%M UTC")"' applications/${{ inputs.APPLICATION }}/kustomize/overlays/environments/${{ inputs.ENVIRONMENT }}/deployment.yaml
- name: Git commit the updated image tag
# Only commits if there are changes.
run: |
git add .
git update-index --refresh
git diff-index --quiet HEAD || git commit -m "Set ${{ inputs.APPLICATION }} ${{ inputs.ENVIRONMENT }} image digest to ${{ inputs.IMAGE_DIGEST }}"
- name: Git push changes
run: |
git status
git push