-
Notifications
You must be signed in to change notification settings - Fork 37
/
orb.yml
106 lines (97 loc) · 4.15 KB
/
orb.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
98
99
100
101
102
103
104
105
106
version: 2.1
description: "Deploy images to Argo-managed cluster using Kustomize"
commands:
deploy-service:
description: "Updates the image tag for a service."
parameters:
environment:
description: "[Description] Environment in which service is being deployed (e.g. prod/non-prod)."
type: string
service-name:
description: "[Description] Service name being deployed (e.g. Public API Bookings)."
type: string
service-image-new-name:
description: "URI of service image to deploy (excluding tag)."
type: string
service-image-current-name:
description: "Text specified in image name field for deploying service."
type: string
service-image-new-tag:
description: "Image Registry tag of service to be deployed"
type: string
gitops-repo:
description: "URL for repository containing kubernetes manifests."
type: string
gitops-username:
description: "Username to associate with git actions."
type: string
gitops-email:
description: "Email to associate with git actions."
type: string
gitops_overlay_path:
description: "Path to overlay with kustomization.yaml to be updated."
type: string
gitops-deploy-branch:
description: "Branch in which to update image tag"
type: string
default: "main"
gitops-repo-ssh-key-fingerprint:
description: "The github SSH key that will be used to update the repository."
type: string
default: ""
gitops-repo-ssh-key-host:
description: 'A host identifier to be set if multiple "Additional SSH keys" require a custom host to be set for the gitops repository, so as not to confict with another host.'
type: string
default: ""
gitops-repo-ssh-key-hostname:
description: "Optional HostName to update ssh config with, if gitops-repo-host is set."
type: string
default: github.com
steps:
- attach_workspace:
at: /tmp/workspace
- when:
condition: << parameters.gitops-repo-ssh-key-fingerprint >>
steps:
- add_ssh_keys:
fingerprints:
- << parameters.gitops-repo-ssh-key-fingerprint >>
- when:
condition: << parameters.gitops-repo-ssh-key-host >>
steps:
- run:
name: Update SSH config hostnames
command: |
sed -i -e 's/Host << parameters.gitops-repo-ssh-key-host >>/Host << parameters.gitops-repo-ssh-key-host >>\n HostName << parameters.gitops-repo-ssh-key-hostname >>/g' ~/.ssh/config
- run:
name: Clone repo
command: |
git clone << parameters.gitops-repo >> /tmp/gitops
- run:
name: Install Kustomize CLI tool
command: |
KUSTOMIZE_VERSION=4.0.2
KUSTOMIZE_DL_FILE=kustomize_v${KUSTOMIZE_VERSION}_linux_amd64.tar.gz
curl -L -O https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/${KUSTOMIZE_DL_FILE}
tar -xzf ${KUSTOMIZE_DL_FILE}
sudo mv kustomize /usr/local/bin/kustomize
sudo chmod u+x /usr/local/bin/kustomize
kustomize version
- run:
name: Update image tag
command: |
cd /tmp/gitops/<< parameters.gitops_overlay_path >>
kustomize edit set image << parameters.service-image-current-name >>=<< parameters.service-image-new-name >>:<< parameters.service-image-new-tag >>
- run:
name: Commit and push changes
command: |
cd /tmp/gitops
git config user.email "<< parameters.gitops-email >>"
git config user.name "<< parameters.gitops-username >>"
git add --all
if [ -z "$(git status --porcelain)" ]; then
echo "No changes detected."
else
git commit -m "Set << parameters.service-name >> << parameters.environment >> image tag to << parameters.service-image-new-tag >>"
git push origin << parameters.gitops-deploy-branch >>
fi