From 100d23416da4504c60179c56c5866ff2e3b9e3df Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Thu, 3 Oct 2024 17:58:04 -0400 Subject: [PATCH] Handle conflicts between additional and default labels --- task/buildah-oci-ta/0.2/buildah-oci-ta.yaml | 22 ++++++++++++++----- .../0.2/buildah-remote-oci-ta.yaml | 22 ++++++++++++++----- task/buildah-remote/0.2/buildah-remote.yaml | 22 ++++++++++++++----- task/buildah/0.2/buildah.yaml | 22 ++++++++++++++----- 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/task/buildah-oci-ta/0.2/buildah-oci-ta.yaml b/task/buildah-oci-ta/0.2/buildah-oci-ta.yaml index 4df7988201..8283df358f 100644 --- a/task/buildah-oci-ta/0.2/buildah-oci-ta.yaml +++ b/task/buildah-oci-ta/0.2/buildah-oci-ta.yaml @@ -412,15 +412,25 @@ spec: VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume ${mount_point}:${YUM_REPOS_D_TARGET}" fi - LABELS=( - "--label" "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" - "--label" "architecture=$(uname -m)" - "--label" "vcs-type=git" + DEFAULT_LABELS=( + "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" + "architecture=$(uname -m)" + "vcs-type=git" ) - [ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA") - [ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER") + [ -n "$COMMIT_SHA" ] && DEFAULT_LABELS+=("vcs-ref=$COMMIT_SHA") + [ -n "$IMAGE_EXPIRES_AFTER" ] && DEFAULT_LABELS+=("quay.expires-after=$IMAGE_EXPIRES_AFTER") + LABELS=() for label in "${ADDITIONAL_LABELS[@]}"; do + echo "Adding label from param $label" + LABELS+=("--label" "$label") + done + for label in "${DEFAULT_LABELS[@]}"; do + if [[ ${ADDITIONAL_LABELS[*]} =~ ${label//=*/} ]]; then + echo "Dropping default label $label" + continue + fi + echo "Adding default label $label" LABELS+=("--label" "$label") done diff --git a/task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml b/task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml index dd33682c44..d82ec797f1 100644 --- a/task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml +++ b/task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml @@ -446,15 +446,25 @@ spec: VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume ${mount_point}:${YUM_REPOS_D_TARGET}" fi - LABELS=( - "--label" "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" - "--label" "architecture=$(uname -m)" - "--label" "vcs-type=git" + DEFAULT_LABELS=( + "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" + "architecture=$(uname -m)" + "vcs-type=git" ) - [ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA") - [ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER") + [ -n "$COMMIT_SHA" ] && DEFAULT_LABELS+=("vcs-ref=$COMMIT_SHA") + [ -n "$IMAGE_EXPIRES_AFTER" ] && DEFAULT_LABELS+=("quay.expires-after=$IMAGE_EXPIRES_AFTER") + LABELS=() for label in "${ADDITIONAL_LABELS[@]}"; do + echo "Adding label from param $label" + LABELS+=("--label" "$label") + done + for label in "${DEFAULT_LABELS[@]}"; do + if [[ ${ADDITIONAL_LABELS[*]} =~ ${label//=*/} ]]; then + echo "Dropping default label $label" + continue + fi + echo "Adding default label $label" LABELS+=("--label" "$label") done diff --git a/task/buildah-remote/0.2/buildah-remote.yaml b/task/buildah-remote/0.2/buildah-remote.yaml index 0a33bf86d7..5e52cf48fb 100644 --- a/task/buildah-remote/0.2/buildah-remote.yaml +++ b/task/buildah-remote/0.2/buildah-remote.yaml @@ -422,15 +422,25 @@ spec: VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume ${mount_point}:${YUM_REPOS_D_TARGET}" fi - LABELS=( - "--label" "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" - "--label" "architecture=$(uname -m)" - "--label" "vcs-type=git" + DEFAULT_LABELS=( + "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" + "architecture=$(uname -m)" + "vcs-type=git" ) - [ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA") - [ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER") + [ -n "$COMMIT_SHA" ] && DEFAULT_LABELS+=("vcs-ref=$COMMIT_SHA") + [ -n "$IMAGE_EXPIRES_AFTER" ] && DEFAULT_LABELS+=("quay.expires-after=$IMAGE_EXPIRES_AFTER") + LABELS=() for label in "${ADDITIONAL_LABELS[@]}"; do + echo "Adding label from param $label" + LABELS+=("--label" "$label") + done + for label in "${DEFAULT_LABELS[@]}"; do + if [[ ${ADDITIONAL_LABELS[*]} =~ ${label//=*} ]]; then + echo "Dropping default label $label" + continue + fi + echo "Adding default label $label" LABELS+=("--label" "$label") done diff --git a/task/buildah/0.2/buildah.yaml b/task/buildah/0.2/buildah.yaml index de9878f3fe..66fa0aff24 100644 --- a/task/buildah/0.2/buildah.yaml +++ b/task/buildah/0.2/buildah.yaml @@ -343,15 +343,25 @@ spec: VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume ${mount_point}:${YUM_REPOS_D_TARGET}" fi - LABELS=( - "--label" "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" - "--label" "architecture=$(uname -m)" - "--label" "vcs-type=git" + DEFAULT_LABELS=( + "build-date=$(date -u +'%Y-%m-%dT%H:%M:%S')" + "architecture=$(uname -m)" + "vcs-type=git" ) - [ -n "$COMMIT_SHA" ] && LABELS+=("--label" "vcs-ref=$COMMIT_SHA") - [ -n "$IMAGE_EXPIRES_AFTER" ] && LABELS+=("--label" "quay.expires-after=$IMAGE_EXPIRES_AFTER") + [ -n "$COMMIT_SHA" ] && DEFAULT_LABELS+=("vcs-ref=$COMMIT_SHA") + [ -n "$IMAGE_EXPIRES_AFTER" ] && DEFAULT_LABELS+=("quay.expires-after=$IMAGE_EXPIRES_AFTER") + LABELS=() for label in "${ADDITIONAL_LABELS[@]}"; do + echo "Adding label from param $label" + LABELS+=("--label" "$label") + done + for label in "${DEFAULT_LABELS[@]}"; do + if [[ ${ADDITIONAL_LABELS[*]} =~ ${label//=*} ]]; then + echo "Dropping default label $label" + continue + fi + echo "Adding default label $label" LABELS+=("--label" "$label") done