Skip to content

Commit

Permalink
Renaming APP_IMAGE to IMAGE
Browse files Browse the repository at this point in the history
Following the same param name than `buildah` Task. By convention the
container image produced by the OpenShift Pipeline Tasks should use
`IMAGE` to name this type of param.
  • Loading branch information
otaviof authored and vdemeester committed Jul 3, 2023
1 parent dc3b485 commit 0e87bba
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 89 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ TASK_GIT ?= https://github.com/openshift-pipelines/task-git/releases/download/0.
# picked up by the "test-e2e" target
E2E_PARAM_URL ?= https://github.com/paketo-buildpacks/samples.git
E2E_PARAM_SUBDIRECTORY ?= nodejs/npm
E2E_PARAM_APP_IMAGE ?= registry.registry.svc.cluster.local:32222/task-buildpacks/samples-nodejs:latest

# container registry URL, usually hostname and port
REGISTRY_URL ?= registry.registry.svc.cluster.local:32222
# containre registry namespace, as in the section of the registry allowed to push images
REGISTRY_NAMESPACE ?= task-buildpacks
# base part of a fully qualified container image name
IMAGE_BASE ?= $(REGISTRY_URL)/$(REGISTRY_NAMESPACE)

# simple image name, followed by tag
E2E_IMAGE_TAG ?= samples-nodejs:latest
# task parameter with the fully qualified image name, to be built with buildpacks
E2E_PARAM_IMAGE ?= $(IMAGE_BASE)/${E2E_IMAGE_TAG}

# workspace "source" pvc resource and name
E2E_PVC ?= test/e2e/resources/01-pvc.yaml
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
- name: source

params:
- name: APP_IMAGE
- name: IMAGE
type: string
description: Fully qualified image name, including tag

Expand All @@ -43,7 +43,7 @@ spec:
value: https://github.com/paketo-buildpacks/samples.git

# Running the buildpacks' CNB on the source code to build the container
# image (APP_IMAGE).
# image (IMAGE param).
- name: buildpacks
taskRef:
name: buildpacks
Expand All @@ -55,16 +55,15 @@ spec:
params:
- name: SUBDIRECTORY
value: nodejs/npm
- name: APP_IMAGE
value: $(params.APP_IMAGE)

- name: IMAGE
value: $(params.IMAGE)
```
Please consider the [Workspaces](#workspaces), [Parameters](#parameters) and [Results](#results) described below.
## Container Registry Authentication
The `buildpacks` Task needs credentials to communicate with the Container Registries to publish the images created by the CNB (`APP_IMAGE` param), and also, to optionally store cached data (`CACHE_IMAGE` param).
The `buildpacks` Task needs credentials to communicate with the Container Registries to publish the images created by the CNB (`IMAGE` param), and also, to optionally store cached data (`CACHE_IMAGE` param).

Please consider Tekton Pipeline documentation to setup the [Container Registry authentication][tektonContainerRegistryAuth].

Expand Down Expand Up @@ -102,7 +101,7 @@ Given the param `BINDINGS_GLOB` is set to pick up `*.pem` files, then you can [m

| Param | Type | Default | Description |
| :------------ | :------------------------: | :--------------------------- | :------------------------- |
| `APP_IMAGE` | `string` | (required) | Application's container image name, and tag. |
| `IMAGE` | `string` | (required) | Application's container image name, and tag. |
| `BUILDER_IMAGE` | `string` | `docker.io/paketobuildpacks/builder:base` | Cloud Native Builder (CNB) container image name (and tag). |
| `CNB_PLATFORM_API` | `string` | `0.11` | Lifecycle platform API compatibility version. |
| `SUBDIRECTORY` | `string` | "" (empty) | Alternative `CNB_APP_DIR` directory, relative to the "source" Workspace. |
Expand All @@ -120,8 +119,8 @@ Given the param `BINDINGS_GLOB` is set to pick up `*.pem` files, then you can [m

| Result | Description |
| :------------ | :------------------------- |
| `APP_IMAGE_DIGEST` | Reported `APP_IMAGE` digest. |
| `APP_IMAGE_URL` | Reported fully qualified container image name. |
| `IMAGE_DIGEST` | Reported `IMAGE` digest. |
| `IMAGE_URL` | Reported fully qualified container image name. |

[buildpacksIO]: https://buildpacks.io/
[paketoNodejsSample]: https://github.com/paketo-buildpacks/samples/tree/main/nodejs/npm
Expand Down
12 changes: 6 additions & 6 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function phase() {
# Environment Variables
#

declare -rx PARAMS_APP_IMAGE="${PARAMS_APP_IMAGE:-}"
declare -rx PARAMS_IMAGE="${PARAMS_IMAGE:-}"
declare -rx PARAMS_BUILDER_IMAGE="${PARAMS_BUILDER_IMAGE:-}"
declare -rx PARAMS_CNB_PLATFORM_API="${PARAMS_CNB_PLATFORM_API:-}"
declare -rx PARAMS_SUBDIRECTORY="${PARAMS_SUBDIRECTORY:-}"
Expand All @@ -36,8 +36,8 @@ declare -rx WORKSPACES_CACHE_PATH="${WORKSPACES_CACHE_PATH:-}"
declare -rx WORKSPACES_BINDINGS_BOUND="${WORKSPACES_BINDINGS_BOUND:-}"
declare -rx WORKSPACES_BINDINGS_PATH="${WORKSPACES_BINDINGS_PATH:-}"

declare -rx RESULTS_APP_IMAGE_DIGEST_PATH="${RESULTS_APP_IMAGE_DIGEST_PATH:-}"
declare -rx RESULTS_APP_IMAGE_URL_PATH="${RESULTS_APP_IMAGE_URL_PATH:-}"
declare -rx RESULTS_IMAGE_DIGEST_PATH="${RESULTS_IMAGE_DIGEST_PATH:-}"
declare -rx RESULTS_IMAGE_URL_PATH="${RESULTS_IMAGE_URL_PATH:-}"

#
# Additional Configuration
Expand All @@ -61,9 +61,9 @@ declare -rx REPORT_TOML_PATH="${REPORT_TOML_PATH:-${LAYERS_DIR}/report.toml}"

declare -ra required_vars=(
WORKSPACES_SOURCE_PATH
PARAMS_APP_IMAGE
RESULTS_APP_IMAGE_DIGEST_PATH
RESULTS_APP_IMAGE_URL_PATH
PARAMS_IMAGE
RESULTS_IMAGE_DIGEST_PATH
RESULTS_IMAGE_URL_PATH
)

for v in "${required_vars[@]}"; do
Expand Down
6 changes: 3 additions & 3 deletions scripts/creator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ phase "Inspecting source directory '${SOURCE_DIR}' (subdirectory '${PARAMS_SUBDI

declare -rx CNB_PLATFORM_API="${PARAMS_CNB_PLATFORM_API}"

phase "Creating the image '${PARAMS_APP_IMAGE}' from '${SOURCE_DIR}' (API=${CNB_PLATFORM_API})"
phase "Creating the image '${PARAMS_IMAGE}' from '${SOURCE_DIR}' (API=${CNB_PLATFORM_API})"
set -x
exec creator \
-app="${SOURCE_DIR}" \
Expand All @@ -26,9 +26,9 @@ exec creator \
-skip-restore="${PARAMS_SKIP_RESTORE}" \
-cache-dir="${WORKSPACES_CACHE_PATH}" \
-cache-image="${PARAMS_CACHE_IMAGE}" \
-previous-image="${PARAMS_APP_IMAGE}" \
-previous-image="${PARAMS_IMAGE}" \
-run-image="${PARAMS_RUN_IMAGE}" \
-report="${REPORT_TOML_PATH}" \
-log-level="${CNB_LOG_LEVEL}" \
-no-color \
${PARAMS_APP_IMAGE}
${PARAMS_IMAGE}
8 changes: 4 additions & 4 deletions scripts/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ phase "Extracting result image digest and URL"
readonly digest="$(awk -F '"' '/digest/ { print $2 }' ${REPORT_TOML_PATH})"
readonly image_tag="$(awk -F '"' '/tags/ { print $2 }' ${REPORT_TOML_PATH})"

phase "Writing image digest '${digest}' to '${RESULTS_APP_IMAGE_DIGEST_PATH}'"
printf "%s" "${digest}" >${RESULTS_APP_IMAGE_DIGEST_PATH}
phase "Writing image digest '${digest}' to '${RESULTS_IMAGE_DIGEST_PATH}'"
printf "%s" "${digest}" >${RESULTS_IMAGE_DIGEST_PATH}

phase "Writing image URL '${image_tag}' to '${RESULTS_APP_IMAGE_URL_PATH}'"
printf "%s" "${image_tag}" >${RESULTS_APP_IMAGE_URL_PATH}
phase "Writing image URL '${image_tag}' to '${RESULTS_IMAGE_URL_PATH}'"
printf "%s" "${image_tag}" >${RESULTS_IMAGE_URL_PATH}
6 changes: 3 additions & 3 deletions templates/environment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/ -}}
{{- define "environment" -}}
{{- range list
"params.APP_IMAGE"
"params.IMAGE"
"params.BUILDER_IMAGE"
"params.CNB_PLATFORM_API"
"params.SUBDIRECTORY"
Expand All @@ -26,8 +26,8 @@
"workspaces.cache.path"
"workspaces.bindings.bound"
"workspaces.bindings.path"
"results.APP_IMAGE_DIGEST.path"
"results.APP_IMAGE_URL.path"
"results.IMAGE_DIGEST.path"
"results.IMAGE_URL.path"
}}
- name: {{ . | upper | replace "." "_" | replace "-" "_" }}
value: "$({{ . }})"
Expand Down
8 changes: 4 additions & 4 deletions templates/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
Extra bindings, CA certificate bundle files.
params:
- name: APP_IMAGE
- name: IMAGE
type: string
description: |
Application's container image name, and tag.
Expand Down Expand Up @@ -95,10 +95,10 @@ spec:
Turns on verbose logging, all commands executed will be printed out.

results:
- name: APP_IMAGE_DIGEST
- name: IMAGE_DIGEST
description: |
Reported `APP_IMAGE` digest.
- name: APP_IMAGE_URL
Reported `IMAGE` digest.
- name: IMAGE_URL
description: |
Reported fully qualified container image name.
Expand Down
57 changes: 12 additions & 45 deletions test/e2e/e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
source ./test/helper/helper.sh

# e2e tests paramters for the test pipeline
readonly E2E_PARAM_URL="${E2E_PARAM_URL:-}"
readonly E2E_PARAM_SUBDIRECTORY="${E2E_PARAM_SUBDIRECTORY:-}"
readonly E2E_PARAM_APP_IMAGE="${E2E_PARAM_APP_IMAGE:-}"
readonly E2E_PVC_NAME="${E2E_PVC_NAME:-}"
declare E2E_PARAM_URL="${E2E_PARAM_URL:-}"
declare E2E_PARAM_SUBDIRECTORY="${E2E_PARAM_SUBDIRECTORY:-}"
declare E2E_PARAM_IMAGE="${E2E_PARAM_IMAGE:-}"
declare E2E_PVC_NAME="${E2E_PVC_NAME:-}"

# spinning up a PipeineRun using the internal Container-Registry to store the final image, when the
# process is completed the resource is inspected to assert wether sucessful
@test "[e2e] pipeline-run using git and buildpacks tasks" {
# asserting all required configuration is informed
[ -n "${E2E_PARAM_URL}" ]
[ -n "${E2E_PARAM_APP_IMAGE}" ]
[ -n "${E2E_PARAM_IMAGE}" ]
[ -n "${E2E_PARAM_SUBDIRECTORY}" ]
[ -n "${E2E_PVC_NAME}" ]

Expand All @@ -29,53 +29,20 @@ readonly E2E_PVC_NAME="${E2E_PVC_NAME:-}"
run tkn pipeline start task-buildpacks \
--param="URL=${E2E_PARAM_URL}" \
--param="SUBDIRECTORY=${E2E_PARAM_SUBDIRECTORY}" \
--param="APP_IMAGE=${E2E_PARAM_APP_IMAGE}" \
--param="IMAGE=${E2E_PARAM_IMAGE}" \
--param="VERBOSE=true" \
--workspace="name=source,claimName=${E2E_PVC_NAME},subPath=source" \
--workspace="name=cache,claimName=${E2E_PVC_NAME},subPath=cache" \
--workspace="name=bindings,emptyDir=" \
--filename=test/e2e/resources/10-pipeline.yaml \
--showlog >&3
--showlog
assert_success

# waiting a few seconds before asserting results
sleep 15
sleep 30

#
# Asserting Status
#

readonly tmpl_file="${BASE_DIR}/go-template.tpl"

cat >${tmpl_file} <<EOS
{{- range .status.conditions -}}
{{- if and (eq .type "Succeeded") (eq .status "True") }}
{{ .message }}
{{- end }}
{{- end -}}
EOS

# using template to select the requered information and asserting all tasks have been executed
# without failed or skipped steps
run tkn pipelinerun describe --output=go-template-file --template=${tmpl_file}
assert_success
assert_output --partial '(Failed: 0, Cancelled 0), Skipped: 0'

#
# Asserting Results
#

cat >${tmpl_file} <<EOS
{{- range .status.taskRuns -}}
{{- range .status.taskResults -}}
{{ printf "%s=%s\n" .name .value }}
{{- end -}}
{{- end -}}
EOS

# using a template to render the result attributes on a multi-line key-value pair output, the
# assertion is based on finding the expected results filled up
run tkn pipelinerun describe --output=go-template-file --template=${tmpl_file}
assert_success
assert_output --regexp $'^APP_IMAGE_DIGEST=\S+\nAPP_IMAGE_URL=\S+.*'
# asserting the task status, it must have all steps running sucessfully
assert_tekton_resource "pipelinerun" --partial '(Failed: 0, Cancelled 0), Skipped: 0'
# asserting the task results using a regexp to match the expected key-value entries
assert_tekton_resource "taskrun" --regexp $'IMAGE_DIGEST=\S+.\nIMAGE_URL=\S+*'
}
6 changes: 3 additions & 3 deletions test/e2e/resources/10-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
- name: URL
type: string
description: Git repository URL
- name: APP_IMAGE
- name: IMAGE
type: string
description: Fully qualified image name, including tag
- name: SUBDIRECTORY
Expand Down Expand Up @@ -51,8 +51,8 @@ spec:
- name: bindings
workspace: bindings
params:
- name: APP_IMAGE
value: $(params.APP_IMAGE)
- name: IMAGE
value: $(params.IMAGE)
- name: SUBDIRECTORY
value: $(params.SUBDIRECTORY)
- name: VERBOSE
Expand Down
29 changes: 28 additions & 1 deletion test/helper/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load '../.bats/bats-file/load'

# base directory to run the prepare script against, it will contain a strucuture mimicing what the
# CNB filesystem looks like
export BASE_DIR=""
declare -x BASE_DIR=""

function setup() {
# creating a temporary directory before each test run below
Expand All @@ -21,3 +21,30 @@ function setup() {
function teardown() {
rm -rfv ${BASE_DIR} || true
}

# Assert elements of a Tekton resource (taskrun or pipelinerun) using bats framework, the first
# function argument represents the Tekton resource and the rest is passed to "assert_output".
function assert_tekton_resource () {
declare tmpl_file="${BASE_DIR}/go-template.tpl"
# the following template is able to extract information from TaskRun and PipelineRun resources,
# and as well supports the current Tekton Pipeline version using a different `.task.results`
# attribute
cat >${tmpl_file} <<EOS
{{- range .status.conditions }}
{{- if and (eq .type "Succeeded") (eq .status "True") }}
{{- printf "%s\n" .message -}}
{{- end -}}
{{- end }}
{{- range .status.taskResults }}
{{- printf "%s=%s\n" .name .value -}}
{{- end -}}
{{- range .status.results }}
{{- printf "%s=%s\n" .name .value -}}
{{- end -}}
EOS

run tkn ${1} describe --last --output=go-template-file --template=${tmpl_file}
shift
assert_success
assert_output ${*}
}
10 changes: 5 additions & 5 deletions test/integration/prepare.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source ./test/helper/helper.sh

export PARAMS_APP_IMAGE="registry.local/namespace/project:latest"
export PARAMS_IMAGE="registry.local/namespace/project:latest"

export PARAMS_BINDINGS_GLOB="*.pem"
export PARAMS_GROUP_ID="$(id -g)"
Expand Down Expand Up @@ -35,8 +35,8 @@ prepare_sh="./scripts/prepare.sh"
export WORKSPACES_CACHE_BOUND="false"
export WORKSPACES_CACHE_PATH="${BASE_DIR}/workspace/cache"

export RESULTS_APP_IMAGE_DIGEST_PATH="${BASE_DIR}/results/image-digest.txt"
export RESULTS_APP_IMAGE_URL_PATH="${BASE_DIR}/results/image-digest.txt"
export RESULTS_IMAGE_DIGEST_PATH="${BASE_DIR}/results/image-digest.txt"
export RESULTS_IMAGE_URL_PATH="${BASE_DIR}/results/image-digest.txt"

run mkdir -p -v ${TEKTON_HOME} ${LAYERS_DIR} ${WORKSPACES_SOURCE_PATH}
assert_success
Expand Down Expand Up @@ -64,8 +64,8 @@ prepare_sh="./scripts/prepare.sh"
export WORKSPACES_BINDINGS_BOUND="true"
export WORKSPACES_BINDINGS_PATH="${BASE_DIR}/workspace/bindings"

export RESULTS_APP_IMAGE_DIGEST_PATH="${BASE_DIR}/results/image-digest.txt"
export RESULTS_APP_IMAGE_URL_PATH="${BASE_DIR}/results/image-digest.txt"
export RESULTS_IMAGE_DIGEST_PATH="${BASE_DIR}/results/image-digest.txt"
export RESULTS_IMAGE_URL_PATH="${BASE_DIR}/results/image-digest.txt"

run mkdir -p -v ${TEKTON_HOME} \
${LAYERS_DIR} \
Expand Down
10 changes: 5 additions & 5 deletions test/integration/report.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source ./test/helper/helper.sh

report_sh="./scripts/report.sh"

export PARAMS_APP_IMAGE="registry.local/namespace/project:latest"
export PARAMS_IMAGE="registry.local/namespace/project:latest"
export PARAMS_VERBOSE="true"

# asserting the script will error out when the environment is not complete
Expand All @@ -21,15 +21,15 @@ export PARAMS_VERBOSE="true"
@test "[report.sh] should be able to extract image digest and fully qualified image name" {
export WORKSPACES_SOURCE_PATH="${BASE_DIR}/workspace/source"

export RESULTS_APP_IMAGE_DIGEST_PATH="${BASE_DIR}/image-digest.txt"
export RESULTS_APP_IMAGE_URL_PATH="${BASE_DIR}/image-url.txt"
export RESULTS_IMAGE_DIGEST_PATH="${BASE_DIR}/image-digest.txt"
export RESULTS_IMAGE_URL_PATH="${BASE_DIR}/image-url.txt"

export REPORT_TOML_PATH="./test/mock/report.toml"

run ${report_sh}
assert_success

# making sure the result files tekton will read from are written and contain what's expected
assert_file_contains ${RESULTS_APP_IMAGE_DIGEST_PATH} "sha256:digest"
assert_file_contains ${RESULTS_APP_IMAGE_URL_PATH} "registry.local/namespace/project:latest"
assert_file_contains ${RESULTS_IMAGE_DIGEST_PATH} "sha256:digest"
assert_file_contains ${RESULTS_IMAGE_URL_PATH} "registry.local/namespace/project:latest"
}

0 comments on commit 0e87bba

Please sign in to comment.