Skip to content

Commit

Permalink
buildah: don't modify Dockerfile in place
Browse files Browse the repository at this point in the history
STONEBLD-2795

Instead, make a copy outside the repo and modify the copy. This is to
avoid dirtying the repo.

For example, when combined with the push-dockerfile task, the pipeline
will now push the original dockerfile instead of pushing the modified
one.

Signed-off-by: Adam Cmiel <[email protected]>
  • Loading branch information
chmeliik committed Sep 24, 2024
1 parent dc9d917 commit 727152d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions task/buildah/0.2/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ spec:
echo "Cannot find Dockerfile $DOCKERFILE"
exit 1
fi
if [ -n "$JVM_BUILD_WORKSPACE_ARTIFACT_CACHE_PORT_80_TCP_ADDR" ] && grep -q '^\s*RUN \(./\)\?mvn' "$dockerfile_path"; then
sed -i -e "s|^\s*RUN \(\(./\)\?mvn\)\(.*\)|RUN echo \"<settings><mirrors><mirror><id>mirror.default</id><url>http://$JVM_BUILD_WORKSPACE_ARTIFACT_CACHE_PORT_80_TCP_ADDR/v1/cache/default/0/</url><mirrorOf>*</mirrorOf></mirror></mirrors></settings>\" > /tmp/settings.yaml; \1 -s /tmp/settings.yaml \3|g" "$dockerfile_path"
dockerfile_copy=/tmp/$(basename "$dockerfile_path")
cp "$dockerfile_path" "$dockerfile_copy"
if [ -n "$JVM_BUILD_WORKSPACE_ARTIFACT_CACHE_PORT_80_TCP_ADDR" ] && grep -q '^\s*RUN \(./\)\?mvn' "$dockerfile_copy"; then
sed -i -e "s|^\s*RUN \(\(./\)\?mvn\)\(.*\)|RUN echo \"<settings><mirrors><mirror><id>mirror.default</id><url>http://$JVM_BUILD_WORKSPACE_ARTIFACT_CACHE_PORT_80_TCP_ADDR/v1/cache/default/0/</url><mirrorOf>*</mirrorOf></mirror></mirrors></settings>\" > /tmp/settings.yaml; \1 -s /tmp/settings.yaml \3|g" "$dockerfile_copy"
touch /var/lib/containers/java
fi
Expand Down Expand Up @@ -246,7 +250,7 @@ spec:
done
BASE_IMAGES=$(
dockerfile-json "${BUILD_ARG_FLAGS[@]}" "$dockerfile_path" |
dockerfile-json "${BUILD_ARG_FLAGS[@]}" "$dockerfile_copy" |
jq -r '.Stages[] | select(.From | .Stage or .Scratch | not) | .BaseName | select(test("^oci-archive:") | not)'
)
Expand Down Expand Up @@ -288,7 +292,7 @@ spec:
sed -E -i \
-e 'H;1h;$!d;x' \
-e 's@^\s*(run((\s|\\\n)+-\S+)*(\s|\\\n)+)@\1. /cachi2/cachi2.env \&\& \\\n @igM' \
"$dockerfile_path"
"$dockerfile_copy"
echo "Prefetched content will be made available"
prefetched_repo_for_my_arch="/tmp/cachi2/output/deps/rpm/$(uname -m)/repos.d/cachi2.repo"
Expand Down Expand Up @@ -355,7 +359,7 @@ spec:
"${LABELS[@]}" \
--tls-verify=$TLSVERIFY --no-cache \
--ulimit nofile=4096:4096 \
-f "$dockerfile_path" -t $IMAGE .
-f "$dockerfile_copy" -t $IMAGE .
container=$(buildah from --pull-never $IMAGE)
buildah mount $container | tee /shared/container_path
Expand Down

0 comments on commit 727152d

Please sign in to comment.