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 Oct 7, 2024
1 parent aa67163 commit 40b8747
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 @@ -233,7 +231,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 @@ -309,12 +310,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 @@ -395,7 +420,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 @@ -218,7 +216,10 @@ spec:
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:e0e457b6af10e44ff6b90208a9e69adc863a865e1c062c4cb84bf3846037d74d
name: use-trusted-artifact
- args:
- --build-args
- $(params.BUILD_ARGS[*])
- --labels
- $(params.ADDITIONAL_LABELS[*])
computeResources:
limits:
cpu: "4"
Expand Down Expand Up @@ -343,12 +344,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 @@ -429,7 +454,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 @@ -501,7 +526,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 @@ -187,8 +187,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 @@ -200,7 +198,10 @@ spec:
name: shared
steps:
- args:
- --build-args
- $(params.BUILD_ARGS[*])
- --labels
- $(params.ADDITIONAL_LABELS[*])
computeResources:
limits:
cpu: "4"
Expand Down Expand Up @@ -325,12 +326,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 @@ -411,7 +430,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 @@ -502,7 +521,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 @@ -168,8 +168,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 @@ -185,7 +183,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 @@ -245,12 +247,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 @@ -331,7 +351,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 40b8747

Please sign in to comment.