-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcd-pipeline.yaml
More file actions
286 lines (276 loc) · 7.55 KB
/
Copy pathcd-pipeline.yaml
File metadata and controls
286 lines (276 loc) · 7.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: golang-test
spec:
params:
- name: subdir
description: subdir in the workspace containing the golang source
default: ./
- name: packages
description: packages to test
default: ./...
workspaces:
- name: source
steps:
- name: run-go-test
image: golang:1.17
workingDir: "$(workspaces.source.path)/$(params.subdir)"
script: go test -v $(packages)
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: golang-test-and-build
spec:
params:
- name: subdir
description: subdir in the workspace containing the golang source
default: ./
workspaces:
- name: source
steps:
- name: run-tests-and-build-executable
image: golang:1.17
workingDir: "$(workspaces.source.path)/$(params.subdir)"
script: |
go test -v ./api
CGO_ENABLED=1 GOOS=linux go build
---
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-env-configmap
data:
ARGOCD_SERVER: argocd-server.argocd.svc.cluster.local
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kustomize-set-image-tag
spec:
params:
- name: context
description: context relative to the workspace where kustomize should run
default: ./
- name: image
description: name of the image whose tag you want to bump
- name: tag
description: tag to set the image to
workspaces:
- name: source
steps:
- name: set-image-tag
image: line/kubectl-kustomize:latest
workingDir: "$(workspaces.source.path)/$(params.context)"
script: |
kustomize edit set image "$(params.image)=$(params.image):$(params.tag)"
# For debugging
cat kustomization.yaml
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: cd-pipeline
spec:
workspaces:
- name: cd-ws
- name: git-ssh-creds
- name: git-manifests-repo-ssh-creds
- name: docker-creds
params:
- name: sha
description: SHA of the commit we'll build an deploy
- name: short-sha
description: Truncated version of the SHA for container image tagging
tasks:
- name: clone-repo
taskRef:
name: git-cli
workspaces:
- name: ssh-directory
workspace: git-ssh-creds
- name: source
workspace: cd-ws
params:
- name: BASE_IMAGE
value: "alpine/git:v2.32.0"
- name: GIT_USER_NAME
value: "build-bot"
- name: GIT_USER_EMAIL
value: "build-bot@empapi.io"
- name: GIT_SCRIPT
value: |
git clone git@github.com:juggernaut/k8s-demo-emp-api.git
cd k8s-demo-emp-api
git checkout $(params.sha)
- name: test-and-build-app
taskRef:
name: golang-test-and-build
runAfter:
- clone-repo
workspaces:
- name: source
workspace: cd-ws
params:
- name: subdir
value: k8s-demo-emp-api
- name: build-and-push-image
taskRef:
name: kaniko
runAfter:
- test-and-build-app
workspaces:
- name: source
workspace: cd-ws
- name: dockerconfig
workspace: docker-creds
params:
- name: IMAGE
value: "juggernaut/k8s-demo-emp-api:$(params.short-sha)"
- name: DOCKERFILE
value: ./kaniko-dockerfile
- name: CONTEXT
value: ./k8s-demo-emp-api
- name: clone-manifests-repo
taskRef:
name: git-cli
runAfter:
- build-and-push-image
workspaces:
- name: ssh-directory
workspace: git-manifests-repo-ssh-creds
- name: source
workspace: cd-ws
params:
- name: BASE_IMAGE
value: "alpine/git:v2.32.0"
- name: GIT_USER_NAME
value: "build-bot"
- name: GIT_USER_EMAIL
value: "build-bot@empapi.io"
- name: GIT_SCRIPT
value: |
git clone git@github.com:juggernaut/k8s-demo-emp-api-manifests.git
- name: bump-staging-image-tag
taskRef:
name: kustomize-set-image-tag
runAfter:
- build-and-push-image
- clone-manifests-repo
workspaces:
- name: source
workspace: cd-ws
params:
- name: image
value: juggernaut/k8s-demo-emp-api
- name: context
value: ./k8s-demo-emp-api-manifests/manifests/staging
- name: tag
value: $(params.short-sha)
- name: commit-staging-image-bump
taskRef:
name: git-cli
runAfter:
- bump-staging-image-tag
workspaces:
- name: ssh-directory
workspace: git-manifests-repo-ssh-creds
- name: source
workspace: cd-ws
params:
- name: BASE_IMAGE
value: "alpine/git:v2.32.0"
- name: GIT_USER_NAME
value: "build-bot"
- name: GIT_USER_EMAIL
value: "build-bot@empapi.io"
- name: GIT_SCRIPT
value: |
#!/bin/bash
cd k8s-demo-emp-api-manifests
if [ -z $(git status -s) ]; then
echo "Nothing to commit!"
else
git commit -m "build-bot: Update staging image tag to $(params.short-sha)" manifests/staging/kustomization.yaml
git push origin main
fi
- name: sync-staging-app
taskRef:
name: argocd-task-sync-and-wait
runAfter:
- commit-staging-image-bump
params:
- name: application-name
value: k8s-demo-emp-api-staging
- name: flags
value: --insecure # since argo is locally hosted, don't use in production!
- name: argocd-version
value: v2.1.7
- name: cluster-test
taskRef:
name: golang-test
runAfter:
- sync-staging-app
workspaces:
- name: source
workspace: cd-ws
params:
- name: subdir
value: k8s-demo-emp-api
- name: packages
value: ./clustertest
- name: bump-prod-image-tag
taskRef:
name: kustomize-set-image-tag
runAfter:
- cluster-test
workspaces:
- name: source
workspace: cd-ws
params:
- name: image
value: juggernaut/k8s-demo-emp-api
- name: context
value: ./k8s-demo-emp-api-manifests/manifests/production
- name: tag
value: $(params.short-sha)
- name: commit-prod-image-bump
taskRef:
name: git-cli
runAfter:
- bump-prod-image-tag
workspaces:
- name: ssh-directory
workspace: git-manifests-repo-ssh-creds
- name: source
workspace: cd-ws
params:
- name: BASE_IMAGE
value: "alpine/git:v2.32.0"
- name: GIT_USER_NAME
value: "build-bot"
- name: GIT_USER_EMAIL
value: "build-bot@empapi.io"
- name: GIT_SCRIPT
value: |
#!/bin/bash
cd k8s-demo-emp-api-manifests
if [ -z $(git status -s) ]; then
echo "Nothing to commit!"
else
git commit -m "build-bot: Update prod image tag to $(params.short-sha)" manifests/production/kustomization.yaml
git push origin main
fi
- name: sync-prod-app
taskRef:
name: argocd-task-sync-and-wait
runAfter:
- commit-prod-image-bump
params:
- name: application-name
value: k8s-demo-emp-api-prod
- name: flags
value: --insecure # since argo is locally hosted, don't use in production!
- name: argocd-version
value: v2.1.7