Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend versioning script instead of using configmap 📝 #791

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 16 additions & 43 deletions recommendations.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,49 +174,22 @@ maintain it in-line. Because you have already avoided interpolation
in the script, there is no real need for the script to be in-lined
into the Task.
Use a ConfigMap for your script, and mount the configmap in the task.
Use a single _command:_ that executes your script (optionally with
environment variables and with parameters):
```
volumes:
- name: scripts
configMap:
name: my-task-scripts
defaultMode: 0755
steps:
- name: foo
image: myimage
volumeMounts:
- name: scripts
mountPath: /mnt/scripts
volume
command:
- /mnt/scripts/my-command.sh
```
This allows you to create and update your configmap from a real
script. An external script-file allows you to edit it stand-alone as
a proper script file, rather than in-lined into a tekton task yaml
file. This gives you better completion, syntax checking, and many
other benefits. You can even run the script locally.
```
#!/bin/bash
# my-command.sh
echo "${PARAM_ONE-Hello world}"
```
To create the configmap:
```
kubectl create configmap my-task-scripts --from-file=my-command.sh
```
For bonus points, use a kustomize generator to create your task; this
allows you simple "kubectl apply -k".
As with all configuration and code that you write as part of software
development, it is important to treat the Tasks and embedded scripts
with the same care you use for your other code.
Scripts should be maintained such that they can be versioned and tested;
therefore as a script grows beyond a few simple lines, you should store
the script in version control, and use tests and code review to maintain
it over time. At this point you may want to consider switching from a
language which does not naturally support tasking, such as bash, to one
that does, such as Python.
At this point, the best option we have to offer is to build and publish
an image which contains your tested, versioned script, and use that image
from within your Task. This may seem like a big ask, but another way of
looking at it is that your script has graduated from just being a script
to being a tool.
Comment on lines +188 to +192
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another option, but it's not merged in catalog yet, so we might update this section once it is - see #740
FYI @chmouel

## Test and verify your task code
Expand Down