Skip to content

Commit 9dd10db

Browse files
committed
buildah: add WORKINGDIR_MOUNT parameter
Allows to mount the current working directory into the build using --volume $PWD:/$WORKINGDIR_MOUNT. Note that the $PWD will be the context directory for the build, because we set the workdir to the context dir before calling 'buildah build'. The primary use case for this parameter is for builds that need to write some outputs into a shared directory and reference the output in a later FROM instruction, e.g. FROM oci-archive:./out.ociarchive See konflux-ci/buildah-container#134 for more details. Signed-off-by: Adam Cmiel <[email protected]>
1 parent 5e17c5d commit 9dd10db

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

task/buildah/0.4/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ When prefetch-dependencies task is activated it is using its artifacts to run bu
3838
|SBOM_TYPE|Select the SBOM format to generate. Valid values: spdx, cyclonedx. Note: the SBOM from the prefetch task - if there is one - must be in the same format.|spdx|false|
3939
|BUILDAH_FORMAT|The format for the resulting image's mediaType. Valid values are oci (default) or docker.|oci|false|
4040
|ADDITIONAL_BASE_IMAGES|Additional base image references to include to the SBOM. Array of image_reference_with_digest strings|[]|false|
41+
|WORKINGDIR_MOUNT|Mount the current working directory into the build using --volume $PWD:/$WORKINGDIR_MOUNT. Note that the $PWD will be the context directory for the build (see the CONTEXT param).|""|false|
4142

4243
## Results
4344
|name|description|

task/buildah/0.4/buildah.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ spec:
137137
Additional base image references to include to the SBOM. Array of image_reference_with_digest strings
138138
type: array
139139
default: []
140+
- name: WORKINGDIR_MOUNT
141+
description: >-
142+
Mount the current working directory into the build using
143+
--volume $PWD:/$WORKINGDIR_MOUNT. Note that the $PWD will be the
144+
context directory for the build (see the CONTEXT param).
145+
type: string
146+
default: ""
140147

141148
results:
142149
- description: Digest of the image just built
@@ -203,6 +210,8 @@ spec:
203210
value: $(params.SBOM_TYPE)
204211
- name: ANNOTATIONS_FILE
205212
value: $(params.ANNOTATIONS_FILE)
213+
- name: WORKINGDIR_MOUNT
214+
value: $(params.WORKINGDIR_MOUNT)
206215

207216
steps:
208217
- image: quay.io/konflux-ci/buildah-task:latest@sha256:4d8273444b0f2781264c232e12e88449bbf078c99e3da2a7f6dcaaf27bc53712
@@ -476,6 +485,18 @@ spec:
476485
echo "Adding the entitlement to the build"
477486
fi
478487
488+
if [ -n "$WORKINGDIR_MOUNT" ]; then
489+
if [[ "$WORKINGDIR_MOUNT" == *:* ]]; then
490+
echo "WORKINGDIR_MOUNT contains ':'" >&2
491+
echo "Refusing to proceed in case this is an attempt to set unexpected mount options." >&2
492+
exit 1
493+
fi
494+
# ${SOURCE_CODE_DIR}/${CONTEXT} will be the $PWD when we call 'buildah build'
495+
# (we set the workdir using 'unshare -w')
496+
context_dir=$(realpath "${SOURCE_CODE_DIR}/${CONTEXT}")
497+
VOLUME_MOUNTS+=(--volume "$context_dir:${WORKINGDIR_MOUNT}")
498+
fi
499+
479500
if [ -n "${ADDITIONAL_VOLUME_MOUNTS-}" ]; then
480501
# ADDITIONAL_VOLUME_MOUNTS allows to specify more volumes for the build.
481502
# Instrumented builds (SAST) use this step as their base and add some other tools.

0 commit comments

Comments
 (0)