Skip to content

Commit

Permalink
Make this a proper array
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Sep 25, 2024
1 parent f2f8e35 commit 897f212
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 30 deletions.
39 changes: 32 additions & 7 deletions task/buildah-oci-ta/0.2/buildah-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ spec:
- name: ADDITIONAL_LABELS
description: Additional key=value labels that should be applied to the
image
type: string
default: '[]'
type: array
default: []
- name: ADDITIONAL_SECRET
description: Name of a secret which will be made available to the build
with 'buildah build --secret' at /run/secrets/$ADDITIONAL_SECRET
Expand Down Expand Up @@ -178,8 +178,6 @@ spec:
env:
- name: ACTIVATION_KEY
value: $(params.ACTIVATION_KEY)
- name: ADDITIONAL_LABELS
value: $(params.ADDITIONAL_LABELS)
- name: ADDITIONAL_SECRET
value: $(params.ADDITIONAL_SECRET)
- name: ADD_CAPABILITIES
Expand Down Expand Up @@ -231,7 +229,10 @@ spec:
- name: build
image: quay.io/konflux-ci/buildah-task:latest@sha256:860a239c5f25376a435a514ae6d53a5c75b1fa492461d17774e9b7cb32d1e275
args:
- --build-args
- $(params.BUILD_ARGS[*])
- --labels
- $(params.ADDITIONAL_LABELS[*])
workingDir: /var/workdir
volumeMounts:
- mountPath: /var/lib/containers
Expand Down Expand Up @@ -304,12 +305,36 @@ spec:
sed -e '/^#/d' -e '/^\s*$/d' "${SOURCE_CODE_DIR}/${BUILD_ARGS_FILE}"
)
fi
ADDITIONAL_LABELS=()
# Split `args` into two sets of arguments.
while [[ $# -gt 0 ]]; do
case $1 in
--build-args)
shift
while [[ $# -gt 0 && $1 != --* ]]; do
build_args+=("$1")
shift
done
;;
--labels)
shift
while [[ $# -gt 0 && $1 != --* ]]; do
ADDITIONAL_LABELS+=("$1")
shift
done
;;
*)
echo "unexpected argument: $1" >&2
exit 2
;;
esac
done
# Append BUILD_ARGS
# Note: this may result in multiple --build-arg=KEY=value flags with the same KEY being
# passed to buildah. In that case, the *last* occurrence takes precedence. This is why
# we append BUILD_ARGS after the content of the BUILD_ARGS_FILE - they take precedence.
build_args+=("$@")
BUILD_ARG_FLAGS=()
for build_arg in "${build_args[@]}"; do
BUILD_ARG_FLAGS+=("--build-arg=$build_arg")
Expand Down Expand Up @@ -390,7 +415,7 @@ spec:
[ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA")
[ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER")
for label in $(echo "${ADDITIONAL_LABELS}" | jq -r '.[]'); do
for label in "${ADDITIONAL_LABELS[@]}"; do
LABELS+=("--label" "$label")
done
Expand Down
40 changes: 32 additions & 8 deletions task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ spec:
description: Name of secret which contains subscription activation key
name: ACTIVATION_KEY
type: string
- default: '[]'
- default: []
description: Additional key=value labels that should be applied to the image
name: ADDITIONAL_LABELS
type: string
type: array
- default: does-not-exist
description: Name of a secret which will be made available to the build with 'buildah
build --secret' at /run/secrets/$ADDITIONAL_SECRET
Expand Down Expand Up @@ -158,8 +158,6 @@ spec:
env:
- name: ACTIVATION_KEY
value: $(params.ACTIVATION_KEY)
- name: ADDITIONAL_LABELS
value: $(params.ADDITIONAL_LABELS)
- name: ADDITIONAL_SECRET
value: $(params.ADDITIONAL_SECRET)
- name: ADD_CAPABILITIES
Expand Down Expand Up @@ -216,7 +214,10 @@ spec:
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:c91de1771397c5a6fde3cf0c642dd3478af5409e2d1980a3402f32b395f2d2a7
name: use-trusted-artifact
- args:
- --build-args
- $(params.BUILD_ARGS[*])
- --labels
- $(params.ADDITIONAL_LABELS[*])
computeResources:
limits:
cpu: "4"
Expand Down Expand Up @@ -338,12 +339,36 @@ spec:
sed -e '/^#/d' -e '/^\s*$/d' "${SOURCE_CODE_DIR}/${BUILD_ARGS_FILE}"
)
fi
ADDITIONAL_LABELS=()
# Split `args` into two sets of arguments.
while [[ $# -gt 0 ]]; do
case $1 in
--build-args)
shift
while [[ $# -gt 0 && $1 != --* ]]; do
build_args+=("$1")
shift
done
;;
--labels)
shift
while [[ $# -gt 0 && $1 != --* ]]; do
ADDITIONAL_LABELS+=("$1")
shift
done
;;
*)
echo "unexpected argument: $1" >&2
exit 2
;;
esac
done
# Append BUILD_ARGS
# Note: this may result in multiple --build-arg=KEY=value flags with the same KEY being
# passed to buildah. In that case, the *last* occurrence takes precedence. This is why
# we append BUILD_ARGS after the content of the BUILD_ARGS_FILE - they take precedence.
build_args+=("$@")
BUILD_ARG_FLAGS=()
for build_arg in "${build_args[@]}"; do
BUILD_ARG_FLAGS+=("--build-arg=$build_arg")
Expand Down Expand Up @@ -424,7 +449,7 @@ spec:
[ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA")
[ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER")
for label in $(echo "${ADDITIONAL_LABELS}" | jq -r '.[]'); do
for label in "${ADDITIONAL_LABELS[@]}"; do
LABELS+=("--label" "$label")
done
Expand Down Expand Up @@ -493,7 +518,6 @@ spec:
ssh $SSH_ARGS "$SSH_HOST" $PORT_FORWARD podman run $PODMAN_PORT_FORWARD \
--tmpfs /run/secrets \
-e ACTIVATION_KEY="$ACTIVATION_KEY" \
-e ADDITIONAL_LABELS="$ADDITIONAL_LABELS" \
-e ADDITIONAL_SECRET="$ADDITIONAL_SECRET" \
-e ADD_CAPABILITIES="$ADD_CAPABILITIES" \
-e BUILDAH_FORMAT="$BUILDAH_FORMAT" \
Expand Down
34 changes: 26 additions & 8 deletions task/buildah-remote/0.2/buildah-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ spec:
stages
name: SKIP_UNUSED_STAGES
type: string
- default: '[]'
- default: []
description: Additional key=value labels that should be applied to the image
name: ADDITIONAL_LABELS
type: string
type: array
- description: The platform to build on
name: PLATFORM
type: string
Expand Down Expand Up @@ -185,8 +185,6 @@ spec:
value: $(params.SQUASH)
- name: SKIP_UNUSED_STAGES
value: $(params.SKIP_UNUSED_STAGES)
- name: ADDITIONAL_LABELS
value: $(params.ADDITIONAL_LABELS)
- name: BUILDER_IMAGE
value: quay.io/konflux-ci/buildah-task:latest@sha256:860a239c5f25376a435a514ae6d53a5c75b1fa492461d17774e9b7cb32d1e275
- name: PLATFORM
Expand All @@ -198,7 +196,10 @@ spec:
name: shared
steps:
- args:
- --build-args
- $(params.BUILD_ARGS[*])
- --labels
- $(params.ADDITIONAL_LABELS[*])
computeResources:
limits:
cpu: "4"
Expand Down Expand Up @@ -320,12 +321,30 @@ spec:
sed -e '/^#/d' -e '/^\s*$/d' "${SOURCE_CODE_DIR}/${BUILD_ARGS_FILE}"
)
fi
ADDITIONAL_LABELS=()
# Split `args` into two sets of arguments.
while [[ $# -gt 0 ]]; do
case $1 in
--build-args)
shift
while [[ $# -gt 0 && $1 != --* ]]; do build_args+=("$1"); shift; done
;;
--labels)
shift
while [[ $# -gt 0 && $1 != --* ]]; do ADDITIONAL_LABELS+=("$1"); shift; done
;;
*)
echo "unexpected argument: $1" >&2
exit 2
;;
esac
done
# Append BUILD_ARGS
# Note: this may result in multiple --build-arg=KEY=value flags with the same KEY being
# passed to buildah. In that case, the *last* occurrence takes precedence. This is why
# we append BUILD_ARGS after the content of the BUILD_ARGS_FILE - they take precedence.
build_args+=("$@")
BUILD_ARG_FLAGS=()
for build_arg in "${build_args[@]}"; do
BUILD_ARG_FLAGS+=("--build-arg=$build_arg")
Expand Down Expand Up @@ -406,7 +425,7 @@ spec:
[ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA")
[ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER")
for label in $(echo "${ADDITIONAL_LABELS}" | jq -r '.[]'); do
for label in "${ADDITIONAL_LABELS[@]}"; do
LABELS+=("--label" "$label")
done
Expand Down Expand Up @@ -493,7 +512,6 @@ spec:
-e ADD_CAPABILITIES="$ADD_CAPABILITIES" \
-e SQUASH="$SQUASH" \
-e SKIP_UNUSED_STAGES="$SKIP_UNUSED_STAGES" \
-e ADDITIONAL_LABELS="$ADDITIONAL_LABELS" \
-e COMMIT_SHA="$COMMIT_SHA" \
-v "$BUILD_DIR/workspaces/source:$(workspaces.source.path):Z" \
-v "$BUILD_DIR/volumes/shared:/shared:Z" \
Expand Down
34 changes: 27 additions & 7 deletions task/buildah/0.2/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ spec:
default: "true"
- name: ADDITIONAL_LABELS
description: Additional key=value labels that should be applied to the image
type: string
default: "[]"
type: array
default: []

results:
- description: Digest of the image just built
Expand Down Expand Up @@ -166,8 +166,6 @@ spec:
value: $(params.SQUASH)
- name: SKIP_UNUSED_STAGES
value: $(params.SKIP_UNUSED_STAGES)
- name: ADDITIONAL_LABELS
value: $(params.ADDITIONAL_LABELS)

steps:
- image: quay.io/konflux-ci/buildah-task:latest@sha256:860a239c5f25376a435a514ae6d53a5c75b1fa492461d17774e9b7cb32d1e275
Expand All @@ -183,7 +181,11 @@ spec:
- name: COMMIT_SHA
value: $(params.COMMIT_SHA)
args:
- --build-args
- $(params.BUILD_ARGS[*])
- --labels
- $(params.ADDITIONAL_LABELS[*])

script: |
#!/bin/bash
set -e
Expand Down Expand Up @@ -240,12 +242,30 @@ spec:
sed -e '/^#/d' -e '/^\s*$/d' "${SOURCE_CODE_DIR}/${BUILD_ARGS_FILE}"
)
fi
ADDITIONAL_LABELS=()
# Split `args` into two sets of arguments.
while [[ $# -gt 0 ]]; do
case $1 in
--build-args)
shift
while [[ $# -gt 0 && $1 != --* ]]; do build_args+=("$1"); shift; done
;;
--labels)
shift
while [[ $# -gt 0 && $1 != --* ]]; do ADDITIONAL_LABELS+=("$1"); shift; done
;;
*)
echo "unexpected argument: $1" >&2
exit 2
;;
esac
done
# Append BUILD_ARGS
# Note: this may result in multiple --build-arg=KEY=value flags with the same KEY being
# passed to buildah. In that case, the *last* occurrence takes precedence. This is why
# we append BUILD_ARGS after the content of the BUILD_ARGS_FILE - they take precedence.
build_args+=("$@")
BUILD_ARG_FLAGS=()
for build_arg in "${build_args[@]}"; do
BUILD_ARG_FLAGS+=("--build-arg=$build_arg")
Expand Down Expand Up @@ -326,7 +346,7 @@ spec:
[ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA")
[ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER")
for label in $(echo "${ADDITIONAL_LABELS}" | jq -r '.[]'); do
for label in "${ADDITIONAL_LABELS[@]}"; do
LABELS+=("--label" "$label")
done
Expand Down
1 change: 1 addition & 0 deletions task/generate-labels/0.1/generate-labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ spec:
results:
- name: labels
description: The rendered labels, rendered from the provided templates
type: array
steps:
- name: render
image: quay.io/konflux-ci/yq:latest@sha256:91a7fe73fd28bbfd93ebdcc68cdfd7087d4f2612c627ccd0d5f984190eb7dba6
Expand Down

0 comments on commit 897f212

Please sign in to comment.