diff --git a/task/buildah/0.2/buildah.yaml b/task/buildah/0.2/buildah.yaml index 8c8719b253..94aa81adc0 100644 --- a/task/buildah/0.2/buildah.yaml +++ b/task/buildah/0.2/buildah.yaml @@ -256,10 +256,11 @@ spec: ) BUILDAH_ARGS=() + UNSHARE_ARGS=() if [ "${HERMETIC}" == "true" ]; then BUILDAH_ARGS+=("--pull=never") - UNSHARE_ARGS="--net" + UNSHARE_ARGS+=("--net") for image in $BASE_IMAGES; do unshare -Ufp --keep-caps -r --map-users 1,1,65536 --map-groups 1,1,65536 -- buildah pull $image done @@ -284,10 +285,12 @@ spec: BUILDAH_ARGS+=("--skip-unused-stages=false") fi + VOLUME_MOUNTS=() + if [ -f "$(workspaces.source.path)/cachi2/cachi2.env" ]; then cp -r "$(workspaces.source.path)/cachi2" /tmp/ chmod -R go+rwX /tmp/cachi2 - VOLUME_MOUNTS="--volume /tmp/cachi2:/cachi2" + VOLUME_MOUNTS+=(--volume /tmp/cachi2:/cachi2) # Read in the whole file (https://unix.stackexchange.com/questions/533277), then # for each RUN ... line insert the cachi2.env command *after* any options like --mount sed -E -i \ @@ -314,7 +317,7 @@ spec: if [ -d "${YUM_REPOS_D_FETCHED}" ]; then chmod -R go+rwX ${YUM_REPOS_D_FETCHED} mount_point=$(realpath ${YUM_REPOS_D_FETCHED}) - VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume ${mount_point}:${YUM_REPOS_D_TARGET}" + VOLUME_MOUNTS+=(--volume "${mount_point}:${YUM_REPOS_D_TARGET}") fi LABELS=( @@ -335,12 +338,12 @@ spec: if [ -e /activation-key/org ]; then cp -r --preserve=mode "$ACTIVATION_KEY_PATH" /tmp/activation-key mkdir /shared/rhsm-tmp - VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume /tmp/activation-key:/activation-key -v /shared/rhsm-tmp:/etc/pki/entitlement:Z" + VOLUME_MOUNTS+=(--volume /tmp/activation-key:/activation-key -v /shared/rhsm-tmp:/etc/pki/entitlement:Z) echo "Adding activation key to the build" elif find /entitlement -name "*.pem" >> null; then cp -r --preserve=mode "$ENTITLEMENT_PATH" /tmp/entitlement - VOLUME_MOUNTS="${VOLUME_MOUNTS} --volume /tmp/entitlement:/etc/pki/entitlement" + VOLUME_MOUNTS+=(--volume /tmp/entitlement:/etc/pki/entitlement) echo "Adding the entitlement to the build" fi @@ -357,13 +360,19 @@ spec: # Prevent ShellCheck from giving a warning because 'image' is defined and 'IMAGE' is not. declare IMAGE - unshare -Uf $UNSHARE_ARGS --keep-caps -r --map-users 1,1,65536 --map-groups 1,1,65536 -w ${SOURCE_CODE_DIR}/$CONTEXT -- buildah build \ - $VOLUME_MOUNTS \ - "${BUILDAH_ARGS[@]}" \ - "${LABELS[@]}" \ - --tls-verify=$TLSVERIFY --no-cache \ - --ulimit nofile=4096:4096 \ - -f "$dockerfile_copy" -t "$IMAGE" . + buildah_cmd_array=( + buildah build + "${VOLUME_MOUNTS[@]}" + "${BUILDAH_ARGS[@]}" + "${LABELS[@]}" + --tls-verify="$TLSVERIFY" --no-cache + --ulimit nofile=4096:4096 + -f "$dockerfile_path" -t "$IMAGE" . + ) + buildah_cmd=$(printf "%q " "${buildah_cmd_array[@]}") + command="ip link set lo up && $buildah_cmd" + + unshare -Uf "${UNSHARE_ARGS[@]}" --keep-caps -r --map-users 1,1,65536 --map-groups 1,1,65536 -w "${SOURCE_CODE_DIR}/$CONTEXT" -- sh -c "$command" container=$(buildah from --pull-never "$IMAGE") buildah mount $container | tee /shared/container_path