Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@14.1.0
Use rok8s-scripts
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Use this example to build and push a docker image using rok8s-scripts. This assumes that you have a working rok8s-scripts configuration already in place.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build_and_push:
jobs:
- rok8s-scripts/docker_build_and_push:
config_file: deploy/build.config
context: org-global
docker-login: true
filters:
branches:
only: master
password-variable: quay_token
registry: quay.io
username: orgname+circleci
This is an example of how one might run an end-to-end test in Kubernetes using this Orb. There are two entrypoints for scripts here, one is a pre_script, and one is the script. The pre_script runs on the CircleCI executor itself and allows access to the repository that was checked out, as well as provides the opportunity to copy more files over to the command runner. This can be done using `docker cp <file> e2e-command-runner:<path>. The regular script is copied over to the command runner container and executed on the command runner, providing access to the Kubernetes kind cluster via kubectl and helm commands. The post_script runs on the CircleCI executor itself after the script is run on the command runner.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build:
jobs:
- rok8s-scripts/kubernetes_e2e_tests:
filters:
branches:
only: /.*/
tags:
ignore: /.*/
name: End-To-End Test on Kubernetes
post_script: e2e/post.sh
pre_script: e2e/pre.sh
script: e2e/test.sh
version: 2
This example expands upon the kubernetes e2e test example by demonstrating how you could run the same test across multiple kubernetes versions.
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
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build:
jobs:
- rok8s-scripts/kubernetes_e2e_tests:
filters:
branches:
only: /.*/
tags:
ignore: /.*/
kind_node_image: >-
kindest/node:v1.15.6@sha256:18c4ab6b61c991c249d29df778e651f443ac4bcd4e6bdd37e0c83c0d33eaae78
name: End-To-End Test Kube 1.15.6
post_script: e2e/post.sh
pre_script: e2e/pre.sh
script: e2e/test.sh
- rok8s-scripts/kubernetes_e2e_tests:
filters:
branches:
only: /.*/
tags:
ignore: /.*/
kind_node_image: >-
kindest/node:v1.16.3@sha256:70ce6ce09bee5c34ab14aec2b84d6edb260473a60638b1b095470a3a0f95ebec
name: End-To-End Test Kube 1.16.3
post_script: e2e/post.sh
pre_script: e2e/pre.sh
script: e2e/test.sh
version: 2
This is an example of how you can use a single command from the orb to perform specific actions. This particular example utilizes the executor and the set_env command from the orb. This can make utilizing existing rok8s-scripts commands that have not yet been implemented in the orb.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
jobs:
deploy-secrets:
executor: rok8s-scripts/ci-images
steps:
- checkout
- rok8s-scripts/set_env
- run: prepare-kubectl
- run: k8s-deploy-secrets -f <PATH TO YOUR CONFIG>
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build:
jobs:
- deploy-secrets:
filters:
branches:
only: /.*/
version: 2
A workflow for building and pushing a docker image using rok8s-screipts. Assumes you have a working rok8s config file.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
config_file | The location of the rok8s-scripts config file. | No | deploy/build.config | string |
docker-login | When true(default), perform a docker login before build and push. | No | true | boolean |
docker-push | When true(default), push the image when done. | No | true | boolean |
enable_docker_layer_caching | Enables docker_layer_caching on remote docker. Requires a paid plan. | No | false | boolean |
executor | The name of custom executor to use. Only recommended for development. | No | ci-images | executor |
password-variable | The environment variable name containing the password. Only used if docker-login is true. | No | '' | string |
registry | The name of the docker registry. Only used if docker-login is true. | No | quay.io | string |
username | The username to use for the registry. Only used if docker-login is true. | No | '' | string |
Create a Github Release from a git tag. Requires that GITHUB_ACCESS_TOKEN be set as an environment variable. If the tag is annotated, that will become the release notes. If the tag is not annotated, then a list of commits will become the release notes.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
executor | The name of custom executor to use. Only recommended for development. | No | ci-images | executor |
Run a Fairwinds Insights Report. Requires that a FAIRWINDS_TOKEN be set in your environment variables.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
executor | The name of custom executor to use. Only recommended for development. | No | ci-images | executor |
sets up a working e2e testing environment for Kubernetes using kind and also sets up a way to access it via the e2e-command-runner container. There are two entrypoints for scripts here, one is a pre_script, and one is the script. The pre_script runs on the CircleCI executor itself and allows access to the repository that was checked out, as well as provides the opportunity to copy more files over to the command runner. This can be done using `docker cp <file> e2e-command-runner:<path>. The regular script is copied over to the command runner container and executed on the command runner, providing access to the Kubernetes kind cluster via kubectl and helm commands. The post_script runs on the CircleCI executor itself after the script is run on the command runner.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
attach-workspace | If true, the attach_workspace step will be run before any other steps.
| No | false | boolean |
command_runner_image | The image to execute commands from against the kind cluster. Also where the script gets executed. | No | quay.io/reactiveops/ci-images:v14.1-alpine | string |
enable_docker_layer_caching | Enables docker_layer_caching on remote docker. Requires a paid plan. | No | false | boolean |
executor | The name of custom executor to use. Only recommended for development. | No | ci-images | executor |
kind_config | A Kind config file to use for the cluster | No | | kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 kubeadmConfigPatches: - | apiVersion: kubeadm.k8s.io/v1beta3 kind: ClusterConfiguration metadata: name: config apiServer: certSANs: - e2e-control-plane - 127.0.0.1 - localhost etcd: serverCertSANs: - e2e-control-plane - 127.0.0.1 - localhost peerCertSANs: - e2e-control-plane - 127.0.0.1 - localhost | string |
kind_node_image | The kind node image to use. See https://github.com/kubernetes-sigs/kind/releases | No | >- kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1 | string |
kind_version | The kind version to use. See https://github.com/kubernetes-sigs/kind/releases | No | 0.17.0 | string |
post_script | Script to run on the local machine after running script on command runner. | No | '' | string |
post_script_steps | Define and inject a set of custom steps to run in the local machine after scripts are executed on the command runner. | No | [] | steps |
pre_script | Script to run on the local machine before running script on command runner. | No | '' | string |
pre_script_steps | Define and inject a set of custom steps to run in the local machine before scripts are executed on the command runner. | No | [] | steps |
script | The script to run on the command runner. | Yes | - | string |
store-artifacts | The location to store artifacts from. This path will be used in the command runner as well as
the executor, so it is recommended that you choose something like /tmp/output
| No | '' | string |
store-test-results | The location to store test results. This path will be used in the command runner as well as
the executor, so it is recommended that you choose something like /tmp/test-results
| No | '' | string |
workspace-location | Where to mount the workspace if attach-workspace is true.
| No | /tmp/workspace | string |
Builds a docker image using rok8s-scripts
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
config | The location of the rok8s-scripts config file | No | deploy/build.config | string |
Log into a docker repo
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
password-variable | The environment variable name containing the password. | Yes | - | env_var_name |
registry | The name of the docker registry. | No | quay.io | string |
username | The username to use for the registry. | Yes | - | string |
Pushes a docker image using rok8s-scripts
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
config | The location of the rok8s-scripts config file | No | deploy/build.config | string |
Run a script in the executor.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
post_script | Script to run on the local machine after running script on command runner. | No | '' | string |
pre_script | Script to run on the local machine before running script on command runner. | No | '' | string |
script | Script to run on the command runner. | No | '' | string |
Start a command runner to execute commands against the kind cluster
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
command_runner_image | The image to execute commands from against the kind cluster. | No | quay.io/reactiveops/ci-images:v11-alpine | string |
Start a kind cluster
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
kind_config | A Kind config file to use for the cluster | No | | kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 kubeadmConfigPatches: - | apiVersion: kubeadm.k8s.io/v1beta3 kind: ClusterConfiguration metadata: name: config apiServer: certSANs: - e2e-control-plane - 127.0.0.1 - localhost etcd: serverCertSANs: - e2e-control-plane - 127.0.0.1 - localhost peerCertSANs: - e2e-control-plane - 127.0.0.1 - localhost | string |
kind_node_image | The kind node image to use. See https://github.com/kubernetes-sigs/kind/releases | No | >- kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1 | string |
kind_version | The kind version to use. See https://github.com/kubernetes-sigs/kind/releases | No | 0.17.0 | string |
Retrieves aws sts credentials from Vault and sets them as environment variables. Requires that a VAULT_TOKEN and a VAULT_ADDR be set in your environment. Also requires that the vault and yq binaries be available
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
vault_path | The kv path to pull credentials from in Vault | Yes | - | string |
Retrieves environment variables from Vault and sets them. Requires that a VAULT_TOKEN and a VAULT_ADDR be set in your environment. Also requires that the vault binary be available
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
vault_path | The kv path to pull env from in Vault | Yes | - | string |
Create a Github Release from a git tag. Requires that GITHUB_ACCESS_TOKEN be set as an environment variable. If the tag is annotated, that will become the release notes. If the tag is not annotated, then a list of commits will become the release notes.
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
commands:
docker_build:
description: Builds a docker image using rok8s-scripts
parameters:
config:
default: deploy/build.config
description: The location of the rok8s-scripts config file
type: string
steps:
- run:
command: |
docker-build -f << parameters.config >>
name: Docker Build
docker_login:
description: Log into a docker repo
parameters:
password-variable:
description: The environment variable name containing the password.
type: env_var_name
registry:
default: quay.io
description: The name of the docker registry.
type: string
username:
description: The username to use for the registry.
type: string
steps:
- run:
command: |
docker login -u="<<parameters.username>>" -p="$<<parameters.password-variable>>" <<parameters.registry>>
name: Docker Login
docker_push:
description: Pushes a docker image using rok8s-scripts
parameters:
config:
default: deploy/build.config
description: The location of the rok8s-scripts config file
type: string
steps:
- run:
command: |
docker-push -f << parameters.config >>
name: Docker Push
e2e_run_script:
description: Run a script in the executor.
parameters:
post_script:
default: ""
description: Script to run on the local machine after running script on command runner.
type: string
pre_script:
default: ""
description: Script to run on the local machine before running script on command runner.
type: string
script:
default: ""
description: Script to run on the command runner.
type: string
steps:
- run:
command: |
[ -z << parameters.pre_script >> ] || bash << parameters.pre_script >>
docker cp << parameters.script >> e2e-command-runner:/script
docker exec e2e-command-runner sh -c "chmod +x /script; /script"
[ -z << parameters.post_script >> ] || bash << parameters.post_script >>
name: Run Script
e2e_start_command_runner:
description: Start a command runner to execute commands against the kind cluster
parameters:
command_runner_image:
default: quay.io/reactiveops/ci-images:v11-alpine
description: The image to execute commands from against the kind cluster.
type: string
steps:
- run:
command: |
cat ./kind-kubeconfig
docker rm -f e2e-command-runner || true
docker run -itd \
--name "e2e-command-runner" \
--network container:e2e-control-plane \
--env KUBECONFIG=/.kube/config \
--env CI_SHA1=$CIRCLE_SHA1 \
--env CI_BRANCH=$CIRCLE_BRANCH \
--env CI_BUILD_NUM=$CIRCLE_BUILD_NUM \
--env CI_TAG=$CIRCLE_TAG \
<< parameters.command_runner_image >>
docker exec e2e-command-runner sh -c 'mkdir -p /.kube'
docker cp ./kind-kubeconfig e2e-command-runner:/.kube/config
docker inspect e2e-command-runner | jq .
docker exec e2e-command-runner sh -c 'ls -al /.kube'
docker exec e2e-command-runner sh -c "sed -i 's/https:\/\/127.0.0.1:[0-9]\+/https:\/\/127.0.0.1:6443/g' /.kube/config"
docker exec e2e-command-runner sh -c 'kubectl get nodes'
name: Setup Command Runner
e2e_start_kind_cluster:
description: Start a kind cluster
parameters:
kind_config:
default: |
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
metadata:
name: config
apiServer:
certSANs:
- e2e-control-plane
- 127.0.0.1
- localhost
etcd:
serverCertSANs:
- e2e-control-plane
- 127.0.0.1
- localhost
peerCertSANs:
- e2e-control-plane
- 127.0.0.1
- localhost
description: A Kind config file to use for the cluster
type: string
kind_node_image:
default: kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1
description: The kind node image to use. See https://github.com/kubernetes-sigs/kind/releases
type: string
kind_version:
default: 0.17.0
description: The kind version to use. See https://github.com/kubernetes-sigs/kind/releases
type: string
steps:
- run:
command: |
curl -LO https://github.com/kubernetes-sigs/kind/releases/download/v<< parameters.kind_version >>/kind-linux-amd64
chmod +x kind-linux-amd64
mkdir bin-kind && mv kind-linux-amd64 bin-kind/kind
export PATH=$(pwd)/bin-kind:$PATH
cat >/tmp/kind.config \<<EOF
<< parameters.kind_config >>
EOF
kind version
cat /tmp/kind.config
kind create cluster \
--name="e2e" \
--image << parameters.kind_node_image >> \
--config /tmp/kind.config \
--wait=120s \
--kubeconfig=./kind-kubeconfig
name: Start Kind Cluster
get_vault_aws_credentials:
description: |
Retrieves aws sts credentials from Vault and sets them as environment variables.
Requires that a VAULT_TOKEN and a VAULT_ADDR be set in your
environment. Also requires that the vault and yq binaries be available
parameters:
vault_path:
description: The kv path to pull credentials from in Vault
type: string
steps:
- run:
command: |
vault token lookup >/dev/null 2>&1
if [ $? != 0 ]; then echo "Vault token expired or not available!" && exit 1; fi
vault write << parameters.vault_path >> -ttl=10m -format=yaml > /tmp/creds.yaml
if [ $? != 0 ]; then echo "Cannot access vault path << parameters.vault_path >>" && exit 2; fi
set -e
token=$(yq e '.data.security_token' /tmp/creds.yaml)
echo "export AWS_SECURITY_TOKEN=$token" >> ${BASH_ENV}
secret_key=$(yq e '.data.secret_key' /tmp/creds.yaml)
echo "export AWS_SECRET_ACCESS_KEY=$secret_key" >> ${BASH_ENV}
access_key=$(yq e '.data.access_key' /tmp/creds.yaml)
echo "export AWS_ACCESS_KEY_ID=$access_key" >> ${BASH_ENV}
source $BASH_ENV
echo "Successfully injected credentials from Vault path << parameters.vault_path >>"
name: Get Vault AWS STS Credentials
shell: bash
get_vault_env:
description: |
Retrieves environment variables from Vault and sets them.
Requires that a VAULT_TOKEN and a VAULT_ADDR be set in your
environment. Also requires that the vault binary be available
parameters:
vault_path:
description: The kv path to pull env from in Vault
type: string
steps:
- run:
command: |
vault token lookup >/dev/null 2>&1
if [ $? != 0 ]; then echo "Vault token expired or not available!" && exit 1; fi
vault kv get -format=yaml << parameters.vault_path >> > /dev/null 2>&1
if [ $? != 0 ]; then echo "Cannot read vault path << parameters.vault_path >>" && exit 2; fi
set -e
envData=($(vault kv get -format=yaml << parameters.vault_path >> | yq e '.data.data' - | sed -nr 's/([A-Z_0-9]+): (.*)/\1=\2/ p'))
for i in "${envData[@]}"; do echo "export $i" >> ${BASH_ENV}; done
source $BASH_ENV
echo "Successfully injected env from Vault path << parameters.vault_path >>"
name: Get Vault Environment Variables
shell: bash
github_release:
description: |
Create a Github Release from a git tag. Requires that GITHUB_ACCESS_TOKEN be set as an environment variable. If the tag is annotated, that will become the release notes. If the tag is not annotated, then a list of commits will become the release notes.
steps:
- run:
command: |
#!/usr/bin/env bash
set -eo pipefail; [[ $TRACE ]] && set -x
log-fail() {
declare desc="log fail formatter"
echo "$@" 1>&2
exit 1
}
main() {
declare desc="Creates a release for the last created tag on github"
local DESCRIPTION REQUEST_BODY
[[ -z "$GITHUB_ACCESS_TOKEN" ]] && log-fail "You must specify a GITHUB_ACCESS_TOKEN environment variable"
[[ -z "$CIRCLE_PROJECT_USERNAME" ]] && log-fail "You must specify a CIRCLE_PROJECT_USERNAME environment variable"
[[ -z "$CIRCLE_PROJECT_REPONAME" ]] && log-fail "You must specify a CIRCLE_PROJECT_REPONAME environment variable"
echo "$CIRCLE_PROJECT_USERNAME"
echo "$CIRCLE_PROJECT_REPONAME"
if [[ -z "$CIRCLE_TAG" ]]; then
echo "You can only release a tag. Please see the documentation. https://circleci.com/orbs/registry/orb/fairwinds/rok8s-scripts"
exit 1
fi
echo "Releasing tag: ${CIRCLE_TAG}"
if [[ $(git cat-file -t ${CIRCLE_TAG}) == "tag" ]]; then
echo "Found annotated tag."
DESCRIPTION="$(git tag -l -n1 --format="%(contents:body)" ${CIRCLE_TAG})"
else
echo "Found a lightweight tag"
LAST_TAG=$(git describe --tags --abbrev=0 ${CIRCLE_TAG}^)
CHANGELOG=$(git log --pretty='format:%h %s' --reverse $LAST_TAG..HEAD)
DESCRIPTION="# Changelog
$CHANGELOG"
fi
echo "Release description: ${DESCRIPTION}"
REQUEST_BODY="$(jq -n --arg tag_name "$CIRCLE_TAG" --arg subject "${CIRCLE_TAG}" --arg description "${DESCRIPTION}" \
'{"tag_name": $tag_name, "target_commitish": "master", "name": $subject, "body": $description, "draft": false, "prerelease": false} ')"
echo "$REQUEST_BODY"
curl -v --data "${REQUEST_BODY}" -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/releases"
}
main "$@"
name: Github Release
set_env:
description: Sets the needed rok8s-scripts environment variables from Circle
steps:
- run:
command: |
echo 'export CI_SHA1=$CIRCLE_SHA1' >> ${BASH_ENV}
echo 'export CI_BRANCH=$CIRCLE_BRANCH' >> ${BASH_ENV}
echo 'export CI_BUILD_NUM=$CIRCLE_BUILD_NUM' >> ${BASH_ENV}
echo 'export CI_TAG=$CIRCLE_TAG' >> ${BASH_ENV}
name: Setup Rok8s-Scripts Environment Variables
description: |
"rok8s-scripts is a framework for building git-triggered workflows with Docker and Kubernetes. By adding rok8s-scripts to your CI/CD pipeline, you can build, push, and deploy your applications using the set of best practices we’ve built at Fairwinds.
In addition to building Docker images and deploying them to Kubernetes, rok8s-scripts is a great way to handle secure secrets management, environment specific configuration, Docker build caching, and much more.
display:
home_url: https://rok8s-scripts.docs.fairwinds.com
source_url: https://github.com/FairwindsOps/rok8s-scripts
examples:
docker_build_push:
description: |
Use this example to build and push a docker image using rok8s-scripts. This assumes that you have a working rok8s-scripts configuration already in place.
usage:
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build_and_push:
jobs:
- rok8s-scripts/docker_build_and_push:
config_file: deploy/build.config
context: org-global
docker-login: true
filters:
branches:
only: master
password-variable: quay_token
registry: quay.io
username: orgname+circleci
kubernetes_e2e_tests:
description: |
This is an example of how one might run an end-to-end test in Kubernetes using this Orb. There are two entrypoints for scripts here, one is a pre_script, and one is the script. The pre_script runs on the CircleCI executor itself and allows access to the repository that was checked out, as well as provides the opportunity to copy more files over to the command runner. This can be done using `docker cp <file> e2e-command-runner:<path>. The regular script is copied over to the command runner container and executed on the command runner, providing access to the Kubernetes kind cluster via kubectl and helm commands. The post_script runs on the CircleCI executor itself after the script is run on the command runner.
usage:
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build:
jobs:
- rok8s-scripts/kubernetes_e2e_tests:
filters:
branches:
only: /.*/
tags:
ignore: /.*/
name: End-To-End Test on Kubernetes
post_script: e2e/post.sh
pre_script: e2e/pre.sh
script: e2e/test.sh
version: 2
kubernetes_e2e_tests_multiple_versions:
description: |
This example expands upon the kubernetes e2e test example by demonstrating how you could run the same test across multiple kubernetes versions.
usage:
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build:
jobs:
- rok8s-scripts/kubernetes_e2e_tests:
filters:
branches:
only: /.*/
tags:
ignore: /.*/
kind_node_image: kindest/node:v1.15.6@sha256:18c4ab6b61c991c249d29df778e651f443ac4bcd4e6bdd37e0c83c0d33eaae78
name: End-To-End Test Kube 1.15.6
post_script: e2e/post.sh
pre_script: e2e/pre.sh
script: e2e/test.sh
- rok8s-scripts/kubernetes_e2e_tests:
filters:
branches:
only: /.*/
tags:
ignore: /.*/
kind_node_image: kindest/node:v1.16.3@sha256:70ce6ce09bee5c34ab14aec2b84d6edb260473a60638b1b095470a3a0f95ebec
name: End-To-End Test Kube 1.16.3
post_script: e2e/post.sh
pre_script: e2e/pre.sh
script: e2e/test.sh
version: 2
use_single_command:
description: |
This is an example of how you can use a single command from the orb to perform specific actions.
This particular example utilizes the executor and the set_env command from the orb. This can make utilizing existing rok8s-scripts commands that have not yet been implemented in the orb.
usage:
jobs:
deploy-secrets:
executor: rok8s-scripts/ci-images
steps:
- checkout
- rok8s-scripts/set_env
- run: prepare-kubectl
- run: k8s-deploy-secrets -f <PATH TO YOUR CONFIG>
orbs:
rok8s-scripts: fairwinds/rok8s-scripts@11
version: 2.1
workflows:
build:
jobs:
- deploy-secrets:
filters:
branches:
only: /.*/
version: 2
executors:
ci-images:
docker:
- image: quay.io/reactiveops/ci-images:<<parameters.version>>
parameters:
version:
default: v14.1-bullseye
type: string
default:
docker:
- image: quay.io/reactiveops/ci-images:<<parameters.version>>
parameters:
version:
default: v14.1-bullseye
type: string
jobs:
docker_build_and_push:
description: |
A workflow for building and pushing a docker image using rok8s-screipts. Assumes you have a working rok8s config file.
executor: <<parameters.executor>>
parameters:
config_file:
default: deploy/build.config
description: The location of the rok8s-scripts config file.
type: string
docker-login:
default: true
description: When true(default), perform a docker login before build and push.
type: boolean
docker-push:
default: true
description: When true(default), push the image when done.
type: boolean
enable_docker_layer_caching:
default: false
description: Enables docker_layer_caching on remote docker. Requires a paid plan.
type: boolean
executor:
default: ci-images
description: The name of custom executor to use. Only recommended for development.
type: executor
password-variable:
default: ""
description: The environment variable name containing the password. Only used if docker-login is true.
type: string
registry:
default: quay.io
description: The name of the docker registry. Only used if docker-login is true.
type: string
username:
default: ""
description: The username to use for the registry. Only used if docker-login is true.
type: string
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: <<parameters.enable_docker_layer_caching>>
- set_env
- when:
condition: <<parameters.docker-login>>
steps:
- docker_login:
password-variable: <<parameters.password-variable>>
registry: <<parameters.registry>>
username: <<parameters.username>>
- docker_build:
config: <<parameters.config_file>>
- when:
condition: <<parameters.docker-push>>
steps:
- docker_push:
config: <<parameters.config_file>>
github_release:
description: |
Create a Github Release from a git tag. Requires that GITHUB_ACCESS_TOKEN be set as an environment variable. If the tag is annotated, that will become the release notes. If the tag is not annotated, then a list of commits will become the release notes.
executor: <<parameters.executor>>
parameters:
executor:
default: ci-images
description: The name of custom executor to use. Only recommended for development.
type: executor
steps:
- checkout
- github_release
insights:
description: |
Run a Fairwinds Insights Report. Requires that a FAIRWINDS_TOKEN be set in your environment variables.
executor: <<parameters.executor>>
parameters:
executor:
default: ci-images
description: The name of custom executor to use. Only recommended for development.
type: executor
steps:
- checkout
- setup_remote_docker
- run:
command: |
curl -L https://insights.fairwinds.com/v0/insights-ci.sh | bash
name: Run Insights Checks
kubernetes_e2e_tests:
description: |
sets up a working e2e testing environment for Kubernetes using kind and also sets up a way to access it via the e2e-command-runner container. There are two entrypoints for scripts here, one is a pre_script, and one is the script. The pre_script runs on the CircleCI executor itself and allows access to the repository that was checked out, as well as provides the opportunity to copy more files over to the command runner. This can be done using `docker cp <file> e2e-command-runner:<path>. The regular script is copied over to the command runner container and executed on the command runner, providing access to the Kubernetes kind cluster via kubectl and helm commands. The post_script runs on the CircleCI executor itself after the script is run on the command runner.
executor: <<parameters.executor>>
parameters:
attach-workspace:
default: false
description: |
If true, the attach_workspace step will be run before any other steps.
type: boolean
command_runner_image:
default: quay.io/reactiveops/ci-images:v14.1-alpine
description: The image to execute commands from against the kind cluster. Also where the script gets executed.
type: string
enable_docker_layer_caching:
default: false
description: Enables docker_layer_caching on remote docker. Requires a paid plan.
type: boolean
executor:
default: ci-images
description: The name of custom executor to use. Only recommended for development.
type: executor
kind_config:
default: |
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
metadata:
name: config
apiServer:
certSANs:
- e2e-control-plane
- 127.0.0.1
- localhost
etcd:
serverCertSANs:
- e2e-control-plane
- 127.0.0.1
- localhost
peerCertSANs:
- e2e-control-plane
- 127.0.0.1
- localhost
description: A Kind config file to use for the cluster
type: string
kind_node_image:
default: kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1
description: The kind node image to use. See https://github.com/kubernetes-sigs/kind/releases
type: string
kind_version:
default: 0.17.0
description: The kind version to use. See https://github.com/kubernetes-sigs/kind/releases
type: string
post_script:
default: ""
description: Script to run on the local machine after running script on command runner.
type: string
post_script_steps:
default: []
description: Define and inject a set of custom steps to run in the local machine after scripts are executed on the command runner.
type: steps
pre_script:
default: ""
description: Script to run on the local machine before running script on command runner.
type: string
pre_script_steps:
default: []
description: Define and inject a set of custom steps to run in the local machine before scripts are executed on the command runner.
type: steps
script:
description: The script to run on the command runner.
type: string
store-artifacts:
default: ""
description: |
The location to store artifacts from. This path will be used in the command runner as well as
the executor, so it is recommended that you choose something like /tmp/output
type: string
store-test-results:
default: ""
description: |
The location to store test results. This path will be used in the command runner as well as
the executor, so it is recommended that you choose something like /tmp/test-results
type: string
workspace-location:
default: /tmp/workspace
description: |
Where to mount the workspace if attach-workspace is true.
type: string
steps:
- when:
condition: <<parameters.attach-workspace>>
steps:
- attach_workspace:
at: <<parameters.workspace-location>>
- checkout
- setup_remote_docker:
docker_layer_caching: << parameters.enable_docker_layer_caching >>
- set_env
- e2e_start_kind_cluster:
kind_config: << parameters.kind_config >>
kind_node_image: << parameters.kind_node_image >>
kind_version: << parameters.kind_version >>
- e2e_start_command_runner:
command_runner_image: << parameters.command_runner_image >>
- steps: << parameters.pre_script_steps >>
- e2e_run_script:
post_script: << parameters.post_script >>
pre_script: << parameters.pre_script >>
script: << parameters.script >>
- steps: << parameters.post_script_steps >>
- when:
condition: << parameters.store-test-results >>
steps:
- run:
command: |
mkdir -p $(dirname "<< parameters.store-test-results >>")
docker cp e2e-command-runner:<< parameters.store-test-results >> << parameters.store-test-results >>
name: Retrieve Test Output From Command Runner
when: always
- store_test_results:
path: << parameters.store-test-results >>
- when:
condition: << parameters.store-artifacts >>
steps:
- run:
command: |
mkdir -p $(dirname "<< parameters.store-artifacts >>")
docker cp e2e-command-runner:<< parameters.store-artifacts >> << parameters.store-artifacts >>
name: Retrieve Artifacts From Command Runner
when: always
- store_artifacts:
path: << parameters.store-artifacts >>
version: "2.1"