-
Notifications
You must be signed in to change notification settings - Fork 7
/
pipeline.yaml
349 lines (347 loc) · 10.2 KB
/
pipeline.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: git-clone
spec:
description: "GIT clone a repository."
workspaces:
- name: output
description: The git repo will be cloned onto the volume backing this workspace
params:
- name: url
description: git url to clone
type: string
- name: revision
description: git revision to checkout (branch, tag, sha, ref…)
type: string
default: master
- name: submodules
description: defines if the resource should initialize and fetch the submodules
type: string
default: "true"
- name: depth
description: performs a shallow clone where only the most recent commit(s) will be fetched
type: string
default: "1"
- name: sslVerify
description: defines if http.sslVerify should be set to true or false in the global git config
type: string
default: "true"
- name: subdirectory
description: subdirectory inside the "output" workspace to clone the git repo into
type: string
default: ""
- name: deleteExisting
description: clean out the contents of the repo's destination directory (if it already exists) before trying to clone the repo there
type: string
default: "false"
results:
- name: commit
description: The precise commit SHA that was fetched by this Task
steps:
- name: clone
image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:latest
script: |
CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)"
cleandir() {
# Delete any existing contents of the repo directory if it exists.
#
# We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/"
# or the root of a mounted volume.
if [[ -d "$CHECKOUT_DIR" ]] ; then
# Delete non-hidden files and directories
rm -rf "$CHECKOUT_DIR"/*
# Delete files and directories starting with . but excluding ..
rm -rf "$CHECKOUT_DIR"/.[!.]*
# Delete files and directories starting with .. plus any other character
rm -rf "$CHECKOUT_DIR"/..?*
fi
}
if [[ "$(params.deleteExisting)" == "true" ]] ; then
cleandir
fi
/ko-app/git-init \
-url "$(params.url)" \
-revision "$(params.revision)" \
-path "$CHECKOUT_DIR" \
-sslVerify="$(params.sslVerify)" \
-submodules="$(params.submodules)" \
-depth="$(params.depth)"
cd "$CHECKOUT_DIR"
RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')"
EXIT_CODE="$?"
if [ "$EXIT_CODE" != 0 ]
then
exit $EXIT_CODE
fi
# Make sure we don't add a trailing newline to the result!
echo -n "$RESULT_SHA" > $(results.commit.path)
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: rt-config-task
spec:
description: "Configure the JFrog CLI for the Artifactory server."
workspaces:
- name: output
params:
- name: rturl
type: string
- name: username
type: string
- name: apikey
type: string
- name: serverid
type: string
steps:
- name: "jfrog-rt-config"
image: docker.io/jefferyfry/jfrog-cli-npm-docker:latest
workingDir: "$(workspaces.output.path)"
env:
- name: JFROG_CLI_HOME_DIR
value: "$(workspaces.output.path)"
- name: JFROG_CLI_TEMP_DIR
value: "$(workspaces.output.path)/tmp"
command: ["jfrog"]
args: ["rt","config","$(inputs.params.serverid)","--url=$(inputs.params.rturl)","--user=$(inputs.params.username)","--apikey=$(inputs.params.apikey)"]
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: npm-config-task
spec:
description: "Configure the JFrog CLI for the NPM repositories."
workspaces:
- name: output
params:
- name: serverid
type: string
steps:
- name: "jfrog-rt-npmc"
image: docker.io/jefferyfry/jfrog-cli-npm-docker:latest
workingDir: "$(workspaces.output.path)"
env:
- name: JFROG_CLI_HOME_DIR
value: "$(workspaces.output.path)"
- name: JFROG_CLI_TEMP_DIR
value: "$(workspaces.output.path)/tmp"
command: ["jfrog"]
args: ["rt","npmc","--repo-resolve=swampup-npm","--repo-deploy=swampup-npm","--server-id-resolve=$(inputs.params.serverid)","--server-id-deploy=$(inputs.params.serverid)"]
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: npm-install-task
spec:
description: "Use the JFrog CLI to run NPM install and collect build-info."
workspaces:
- name: output
steps:
- name: "jfrog-rt-npm-install"
image: docker.io/jefferyfry/jfrog-cli-npm-docker:latest
workingDir: "$(workspaces.output.path)"
env:
- name: JFROG_CLI_HOME_DIR
value: "$(workspaces.output.path)"
- name: JFROG_CLI_TEMP_DIR
value: "$(workspaces.output.path)/tmp"
command: ["jfrog"]
args: ["rt","npm-install","--build-name=npm_build", "--build-number=1"]
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: npm-publish-task
spec:
description: "Use the JFrog CLI to run NPM publish and collect build-info."
workspaces:
- name: output
steps:
- name: "jfrog-rt-npm-publish"
image: docker.io/jefferyfry/jfrog-cli-npm-docker:latest
workingDir: "$(workspaces.output.path)"
env:
- name: JFROG_CLI_HOME_DIR
value: "$(workspaces.output.path)"
- name: JFROG_CLI_TEMP_DIR
value: "$(workspaces.output.path)/tmp"
command: ["jfrog"]
args: ["rt","npm-publish","--build-name=npm_build", "--build-number=1"]
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-publish-task
spec:
description: "Use the JFrog CLI to publish the build-info."
workspaces:
- name: output
steps:
- name: "jfrog-rt-build-publish"
image: docker.io/jefferyfry/jfrog-cli-npm-docker:latest
workingDir: "$(workspaces.output.path)"
env:
- name: JFROG_CLI_HOME_DIR
value: "$(workspaces.output.path)"
- name: JFROG_CLI_TEMP_DIR
value: "$(workspaces.output.path)/tmp"
command: ["jfrog"]
args: ["rt","build-publish","npm_build", "1"]
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: deploy-image-task
spec:
description: "Deploy the new image."
workspaces:
- name: output
params:
- name: image
type: string
- name: server
type: string
- name: username
type: string
- name: apikey
type: string
steps:
- name: "create-secret"
image: bitnami/kubectl:latest
script: |
#!/usr/bin/env bash
kubectl create secret docker-registry regcred --namespace demo --docker-server=$(inputs.params.server) --docker-username=$(inputs.params.username) --docker-password=$(inputs.params.apikey) || true
- name: "deployment-substitution"
image: bash:latest
workingDir: "$(workspaces.output.path)"
script: |
#!/usr/bin/env bash
sed "s|imageName|$(inputs.params.image)|g" deployment.yaml > my-deployment.yaml
- name: "apply-deployment"
image: bitnami/kubectl:latest
workingDir: "$(workspaces.output.path)"
script: |
#!/usr/bin/env bash
kubectl apply -f my-deployment.yaml --namespace demo
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: npm-docker-rt-pipeline
spec:
description: "This is pipeline to build the demo NPM package, build the Docker image and deploy."
params:
- name: rturl
type: string
- name: server
type: string
- name: username
type: string
- name: apikey
type: string
- name: serverid
type: string
- name: image
type: string
workspaces:
- name: shared-workspace
tasks:
- name: git-clone
taskRef:
name: git-clone
params:
- name: url
value: https://github.com/jfrogtraining/red-hat-openshift-tekton
- name: revision
value: master
workspaces:
- name: output
workspace: shared-workspace
- name: rt-config
taskRef:
name: rt-config-task
runAfter:
- git-clone
params:
- name: rturl
value: "$(params.rturl)"
- name: username
value: "$(params.username)"
- name: apikey
value: "$(params.apikey)"
- name: serverid
value: "$(params.serverid)"
workspaces:
- name: output
workspace: shared-workspace
- name: npm-config
taskRef:
name: npm-config-task
runAfter:
- rt-config
params:
- name: serverid
value: "$(params.serverid)"
workspaces:
- name: output
workspace: shared-workspace
- name: npm-install
taskRef:
name: npm-install-task
runAfter:
- npm-config
workspaces:
- name: output
workspace: shared-workspace
- name: npm-publish
taskRef:
name: npm-publish-task
runAfter:
- npm-install
workspaces:
- name: output
workspace: shared-workspace
- name: build-publish
taskRef:
name: build-publish-task
runAfter:
- npm-publish
workspaces:
- name: output
workspace: shared-workspace
- name: build-push-image
taskRef:
name: buildah
kind: ClusterTask
runAfter:
- build-publish
params:
- name: DOCKERFILE
value: "./Dockerfile"
- name: TLSVERIFY
value: "false"
- name: PUSH_EXTRA_ARGS
value: "--creds $(params.username):$(params.apikey)"
- name: IMAGE
value: "$(params.image)"
workspaces:
- name: source
workspace: shared-workspace
- name: deploy-image
taskRef:
name: deploy-image-task
runAfter:
- build-push-image
params:
- name: server
value: "$(params.server)"
- name: username
value: "$(params.username)"
- name: apikey
value: "$(params.apikey)"
- name: image
value: "$(params.image)"
workspaces:
- name: output
workspace: shared-workspace