-
Notifications
You must be signed in to change notification settings - Fork 37
/
orb.yml
104 lines (91 loc) · 4.11 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
version: 2.1
description: "Update OOT deployments with gitops."
orbs:
shipit: ovotech/shipit@1
commands:
update-gitops:
description: "Updates the appropriate manifest in the given gitops repo with a new image tag."
parameters:
service:
description: "The name of the service that will be updated. This should match with the path in the gitops repo."
type: string
image-tag:
description: "The tag of the image to update the manifest with."
type: string
default: ${CIRCLE_SHA1}
account:
description: "The numeric identifier for the AWS account which will be interpolated into the manifest."
type: string
default: ${AWS_ACCOUNT}
environment:
description: "Environment string used for substitution in the manifest and matching the appropriate path in the gitops repo."
type: string
default: ${ENVIRONMENT}
extra-interpolation:
description: "Extra interpolations to do in the manifest expressed as a semi-colon-delimited sed expression. E.g. s/{{MY_PLACEHOLDER}}/12345678/g;s/{{ANOTHER}}/test/g"
type: string
default: ""
gitops-repo:
description: "git URL to the gitops github repo."
type: string
gitops-ssh-key-fingerprint:
description: "The github SSH key that will be used to update the gitops repo."
type: string
gitops-username:
description: "The username of the git user to push gitops changes as."
type: string
gitops-email:
description: "The email address of the git user to push gitops changes as."
type: string
steps:
- attach_workspace:
at: .
- add_ssh_keys:
fingerprints:
- << parameters.gitops-ssh-key-fingerprint >>
- run:
name: Prepare gitops manifest
command: |
git clone << parameters.gitops-repo >> /tmp/gitops
mkdir -p /tmp/gitops/<< parameters.environment >>/<< parameters.service >>
cd /tmp/gitops/<< parameters.environment >>/<< parameters.service >>
cp /tmp/gitops/templates/<<parameters.service>>/manifest.yaml /tmp/gitops/<< parameters.environment >>/<< parameters.service >>
- run:
name: Interpolate gitops manifest
command: |
cd /tmp/gitops/<< parameters.environment >>/<< parameters.service >>
sed -i "s/{{AWS_ACCOUNT_ID}}/<< parameters.account >>/g" manifest.yaml
sed -i "s/{{IMAGE_TAG}}/<< parameters.image-tag >>/g" manifest.yaml
sed -i "s/{{ENVIRONMENT}}/<< parameters.environment >>/g" manifest.yaml
sed -i '<< parameters.extra-interpolation >>' manifest.yaml
- run:
name: Prepare argo application manifest
command: |
mkdir -p /tmp/gitops/<< parameters.environment >>/argo-applications
cd /tmp/gitops/<< parameters.environment >>/argo-applications
cp /tmp/gitops/templates/argo-applications/manifest.yaml /tmp/gitops/<< parameters.environment >>/argo-applications/<< parameters.service >>.yaml
- run:
name: Interpolate argo application definition
command: |
cd /tmp/gitops/<< parameters.environment >>/argo-applications
sed -i "s/{{ENVIRONMENT}}/<< parameters.environment >>/g" << parameters.service >>.yaml
sed -i "s/{{SERVICE}}/<< parameters.service >>/g" << parameters.service >>.yaml
- run:
name: Push gitops manifest
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 "Bumped << parameters.service >> in << parameters.environment >> to << parameters.image-tag >>"
git push origin master
fi
jobs:
shipit:
description: "Alerts ShipIt to the fact that the service has been deployed."
executor: shipit/default
steps:
- shipit/shipit