-
Notifications
You must be signed in to change notification settings - Fork 128
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
Create Tekton task and Pipeline for Tekton bundles #284
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ resources: | |
- nodejs-builder | ||
- enterprise-contract.yaml | ||
- fbc-builder | ||
- tekton-bundle-builder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- ../template-build | ||
|
||
patches: | ||
# Use the template-build as a template replacing the Pipeline name and the | ||
# `build-container` step's task reference | ||
- patch: |- | ||
- op: replace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: It might be worth loading a patch from its own yaml (like the other pipelines do). It's a bit easier to edit than an embedding yaml in yaml. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, this documents the patch much better |
||
path: /metadata/name | ||
value: tekton-bundle-builder | ||
- op: replace | ||
path: /spec/tasks/4/taskRef | ||
value: | ||
name: tkn-bundle | ||
version: "0.1" | ||
target: | ||
kind: Pipeline | ||
name: template-build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# tkn-bundle - Tekton Task to push a Tekton Bundle to an image registry | ||
|
||
Tekton Task to build and push Tekton Bundles (OCI images) which contain | ||
definitions of Tekton objects, most commonly Task and Pipeline objects. | ||
|
||
Task finds all `*.yaml` or `*.yml` files within `CONTEXT`, packages and pushes | ||
them as a Tekton Bundle to the image repository, name and tag specified by the | ||
`IMAGE` parameter. | ||
|
||
## Input Parameters | ||
|
||
The task supports the following input parameters. | ||
|
||
| Name | Example | Description | | ||
|---------|-------------------------|------------------------------------------| | ||
| IMAGE | registry.io/my-task:tag | Reference of the image task will produce | | ||
| CONTEXT | my-task/0.1 | Paths to include in the bundle image | | ||
|
||
`CONTEXT` can include multiple directories or files separated by comma or space. | ||
Paths can be negated with exclamation mark to prevent inclusion of certain | ||
directories or files. Negated paths are best placed at the end as they operate | ||
on collected paths preceeding them. For example if `CONTEXT` is set to | ||
`"0.1,!0.1/spec"` for this tree: | ||
|
||
. | ||
├── 0.1 | ||
│ ├── README.md | ||
│ ├── spec | ||
│ │ ├── spec_helper.sh | ||
│ │ ├── support | ||
│ │ │ ├── jq_matcher.sh | ||
│ │ │ └── task_run_subject.sh | ||
│ │ ├── test1.yaml | ||
│ │ ├── test2.yml | ||
│ │ ├── test3.yaml | ||
│ │ └── tkn-bundle_spec.sh | ||
│ ├── TESTING.md | ||
│ └── tkn-bundle.yaml | ||
└── OWNERS | ||
|
||
Only the `0.1/tkn-bundle.yaml` file will be included in the bundle. | ||
|
||
## Results | ||
|
||
The task emits the following results. | ||
|
||
| Name | Example | Description | | ||
|--------------|-----------------------------------|---------------------------------------------------| | ||
| IMAGE_URL | registry.io/my-task@sha256-abc... | Image repository where the built image was pushed | | ||
| IMAGE_DIGEST | abc... | Digest of the image just built | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Testing tkn-bundle Tekton Task | ||
|
||
Make sure you have shellspec installed[1]. The test setup script will bring up a | ||
kind[2] cluster and installs Tekton Pipeline. The source is provided via the | ||
`source-pvc` PersistantVolumeClaim and prepopulated with the test?.y*ml files in | ||
order to not necesate the need for source checkout. | ||
|
||
For second and subsequent invocations the setup is quicker as it only applies | ||
any changes to already started and setup cluster. To delete the cluster and | ||
start afresh run: `kind delete cluster --name=test-tkn-bundle`. | ||
|
||
To run the tests run `shellspec` from this directory. | ||
|
||
## Example of a testing setup and session | ||
zregvart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```shell | ||
$ pwd | ||
.../build-definitions/task/tkn-bundle/0.1 | ||
$ shellspec --jobs 5 | ||
Running: /bin/sh [bash 5.2.15(1)-release] | ||
namespace/tekton-pipelines created | ||
clusterrole.rbac.authorization.k8s.io/tekton-pipelines-controller-cluster-access created | ||
... | ||
pod "setup-1674815473" deleted | ||
deployment.apps/registry created | ||
service/registry created | ||
deployment.apps/registry condition met | ||
deployment.apps/tekton-pipelines-controller condition met | ||
deployment.apps/tekton-pipelines-webhook condition met | ||
..... | ||
|
||
Finished in 119.59 seconds (user 7.37 seconds, sys 4.03 seconds) | ||
2 examples, 0 failures | ||
``` | ||
|
||
[1] https://shellspec.info/ | ||
[2] https://kind.sigs.k8s.io/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
spec_helper_configure() { | ||
import 'support/task_run_subject' | ||
import 'support/jq_matcher' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
shellspec_syntax 'shellspec_matcher_jq' | ||
|
||
shellspec_matcher_jq() { | ||
shellspec_matcher__match() { | ||
SHELLSPEC_EXPECT="$1" | ||
[ "${SHELLSPEC_SUBJECT+x}" ] || return 1 | ||
echo "${SHELLSPEC_SUBJECT}" | jq --exit-status "${SHELLSPEC_EXPECT}" > /dev/null || return 1 | ||
return 0 | ||
} | ||
|
||
# Message when the matcher fails with "should" | ||
shellspec_matcher__failure_message() { | ||
shellspec_putsn "expected: JSON $1 should evaluate with success against jq expression: $2" | ||
} | ||
|
||
# Message when the matcher fails with "should not" | ||
shellspec_matcher__failure_message_when_negated() { | ||
shellspec_putsn "expected: JSON $1 should not evaluate with success against jq expression: $2" | ||
} | ||
|
||
# checking for parameter count | ||
shellspec_syntax_param count [ $# -eq 1 ] || return 0 | ||
shellspec_matcher_do_match "$@" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
shellspec_syntax 'shellspec_subject_taskrun' | ||
|
||
shellspec_subject_taskrun() { | ||
# shellcheck disable=SC2034 | ||
SHELLSPEC_META='text' | ||
shellspec_readfile_once SHELLSPEC_STDOUT "$SHELLSPEC_STDOUT_FILE" | ||
if [ ${SHELLSPEC_STDOUT+x} ]; then | ||
# shellcheck disable=SC2034 | ||
LINES=(${SHELLSPEC_STDOUT[@]}) | ||
TASK_RUN_NAME="${LINES[2]}" # "TaskRun(0) started:(1) tkn-bundle-run-ndjfb(2) | ||
SHELLSPEC_SUBJECT="$(tkn tr describe "${TASK_RUN_NAME}" -o json)" | ||
shellspec_chomp SHELLSPEC_SUBJECT | ||
else | ||
unset SHELLSPEC_SUBJECT ||: | ||
fi | ||
|
||
shellspec_off UNHANDLED_STDOUT | ||
|
||
eval shellspec_syntax_dispatch modifier ${1+'"$@"'} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: test1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: test2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: test3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Maybe worth setting these labels?
pipelines.openshift.io/runtime
,pipelines.openshift.io/strategy
?(although... I'm not quite sure how those are used)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found no documentation on this, no way of telling what those need to be set to so I left them unset