From 04a53a26fc6016b09bd7e3f7eba6a806adaa8e8e Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Wed, 15 May 2024 20:25:23 -0400 Subject: [PATCH] Buildah: Add SKIP_UNUSED_STAGES parameter Expose the --skip-unused-stages argument to Buildah as a parameter. This is needed to handle certain Containerfiles where stages have hidden side-effects like writing things to the context directory. See https://github.com/containers/buildah/issues/5529 for details. --- task/buildah-remote/0.1/buildah-remote.yaml | 12 ++++++++++++ task/buildah/0.1/buildah.yaml | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/task/buildah-remote/0.1/buildah-remote.yaml b/task/buildah-remote/0.1/buildah-remote.yaml index c1cf496deb..bf1c9cc21d 100644 --- a/task/buildah-remote/0.1/buildah-remote.yaml +++ b/task/buildah-remote/0.1/buildah-remote.yaml @@ -86,6 +86,11 @@ spec: description: Path to a file with build arguments, see https://www.mankier.com/1/buildah-build#--build-arg-file name: BUILD_ARGS_FILE type: string + - default: "true" + description: Whether to skip stages in Containerfile that seem unused by subsequent + stages + name: SKIP_UNUSED_STAGES + type: string - description: The platform to build on name: PLATFORM type: string @@ -135,6 +140,8 @@ spec: value: $(params.ENTITLEMENT_SECRET) - name: BUILD_ARGS_FILE value: $(params.BUILD_ARGS_FILE) + - name: SKIP_UNUSED_STAGES + value: $(params.SKIP_UNUSED_STAGES) - name: BUILDER_IMAGE value: quay.io/redhat-appstudio/buildah:v1.31.0@sha256:34f12c7b72ec2c28f1ded0c494b428df4791c909f1f174dd21b8ed6a57cf5ddb steps: @@ -252,6 +259,10 @@ spec: BUILDAH_ARGS+=("--build-arg=$build_arg") done + if [ "${SKIP_UNUSED_STAGES}" != "true" ] ; then + BUILDAH_ARGS+=("--skip-unused-stages=false") + fi + if [ -d "$(workspaces.source.path)/cachi2" ]; then cp -r "$(workspaces.source.path)/cachi2" /tmp/ chmod -R go+rwX /tmp/cachi2 @@ -342,6 +353,7 @@ spec: -e PARAM_BUILDER_IMAGE="$PARAM_BUILDER_IMAGE" \ -e ENTITLEMENT_SECRET="$ENTITLEMENT_SECRET" \ -e BUILD_ARGS_FILE="$BUILD_ARGS_FILE" \ + -e SKIP_UNUSED_STAGES="$SKIP_UNUSED_STAGES" \ -e COMMIT_SHA="$COMMIT_SHA" \ -v "$BUILD_DIR/workspaces/source:$(workspaces.source.path):Z" \ -v "$BUILD_DIR/.docker/:/root/.docker:Z" \ diff --git a/task/buildah/0.1/buildah.yaml b/task/buildah/0.1/buildah.yaml index 5b6d4d19af..edbe610788 100644 --- a/task/buildah/0.1/buildah.yaml +++ b/task/buildah/0.1/buildah.yaml @@ -79,6 +79,10 @@ spec: description: Path to a file with build arguments, see https://www.mankier.com/1/buildah-build#--build-arg-file type: string default: "" + - name: SKIP_UNUSED_STAGES + description: Whether to skip stages in Containerfile that seem unused by subsequent stages + type: string + default: "true" results: - description: Digest of the image just built @@ -124,6 +128,8 @@ spec: value: $(params.ENTITLEMENT_SECRET) - name: BUILD_ARGS_FILE value: $(params.BUILD_ARGS_FILE) + - name: SKIP_UNUSED_STAGES + value: $(params.SKIP_UNUSED_STAGES) steps: - image: quay.io/redhat-appstudio/buildah:v1.31.0@sha256:34f12c7b72ec2c28f1ded0c494b428df4791c909f1f174dd21b8ed6a57cf5ddb @@ -205,6 +211,10 @@ spec: BUILDAH_ARGS+=("--build-arg=$build_arg") done + if [ "${SKIP_UNUSED_STAGES}" != "true" ] ; then + BUILDAH_ARGS+=("--skip-unused-stages=false") + fi + if [ -d "$(workspaces.source.path)/cachi2" ]; then cp -r "$(workspaces.source.path)/cachi2" /tmp/ chmod -R go+rwX /tmp/cachi2