Skip to content

Commit 7bc9691

Browse files
nalindTomSweeneyRedHat
authored andcommitted
buildah-bud tests: handle "-t oci:" and such, skip a new --output
Teach our patched version of run_buildah() to notice when a build tries to write the output image to an oci:/oci-archive:/docker-archive:/dir: location, and for those cases, adjust the command to commit the image to local storage and then copy it to the desired location. It's a hack on top of a hack. I don't love it, but here we are. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent ac99084 commit 7bc9691

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

test/buildah-bud/apply-podman-deltas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ skip_if_remote "--output option not implemented in podman-remote" \
241241
"build with custom build output for single-stage-cached and output rootfs to directory" \
242242
"build with custom build output for multi-stage-cached and output rootfs to directory" \
243243
"build with custom build output for multi-stage and output rootfs to directory" \
244-
"build-with-two-outputs"
244+
"build-with-two-outputs" \
245+
"bud-with-source-date-epoch-env"
245246

246247
# https://github.com/containers/podman/issues/14544
247248
skip_if_remote "logfile not implemented on remote" "bud-logfile-with-split-logfile-by-platform"

test/buildah-bud/buildah-tests.diff

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ diff --git a/tests/helpers.bash b/tests/helpers.bash
1313
index 3d1211492..dbf175de3 100644
1414
--- a/tests/helpers.bash
1515
+++ b/tests/helpers.bash
16-
@@ -81,6 +81,42 @@ EOF
16+
@@ -82,6 +82,42 @@ EOF
1717
BUILDAH_REGISTRY_OPTS="${regconfopt} ${regconfdir} --short-name-alias-conf ${TEST_SCRATCH_DIR}/cache/shortnames.conf"
1818
COPY_REGISTRY_OPTS="${BUILDAH_REGISTRY_OPTS}"
1919
PODMAN_REGISTRY_OPTS="${regconfopt}"
@@ -56,7 +56,7 @@ index 3d1211492..dbf175de3 100644
5656
}
5757

5858
function starthttpd() { # directory [working-directory-or-"" [certfile, keyfile]]
59-
@@ -145,6 +181,22 @@ function teardown_tests() {
59+
@@ -146,6 +182,22 @@ function teardown_tests() {
6060
stop_git_daemon
6161
stop_registry
6262

@@ -79,7 +79,7 @@ index 3d1211492..dbf175de3 100644
7979
# Workaround for #1991 - buildah + overlayfs leaks mount points.
8080
# Many tests leave behind /var/tmp/.../root/overlay and sub-mounts;
8181
# let's find those and clean them up, otherwise 'rm -rf' fails.
82-
@@ -266,7 +318,12 @@ function copy() {
82+
@@ -267,7 +319,12 @@ function copy() {
8383
}
8484

8585
function podman() {
@@ -93,12 +93,13 @@ index 3d1211492..dbf175de3 100644
9393
}
9494

9595
# There are various scenarios where we would like to execute `tests` as rootless user, however certain commands like `buildah mount`
96-
@@ -373,8 +430,36 @@ function run_buildah() {
96+
@@ -374,8 +431,78 @@ function run_buildah() {
9797
--retry) retry=3; shift;; # retry network flakes
9898
esac
9999

100100
+ local podman_or_buildah=${BUILDAH_BINARY}
101101
+ local _opts="${ROOTDIR_OPTS} ${BUILDAH_REGISTRY_OPTS}"
102+
+ local copydown=:
102103
+ if [[ $1 == "build" || $1 == "build-using-dockerfile" || $1 == "bud" ]]; then
103104
+ shift
104105
+ # podman defaults to --layers=true; buildah to --false.
@@ -109,6 +110,48 @@ index 3d1211492..dbf175de3 100644
109110
+ else
110111
+ set "build" "--force-rm=false" "--layers=false" "$@"
111112
+ fi
113+
+ # Figure out an archive format that will match the --format flag, if one was used.
114+
+ local nativearchive=oci-archive
115+
+ local formatpattern="((--format( |=))(oci|docker))"
116+
+ if [[ "$*" =~ ${formatpattern} ]]; then
117+
+ case "${BASH_REMATCH[4]}" in
118+
+ oci) nativearchive=oci-archive;;
119+
+ docker) nativearchive=docker-archive;;
120+
+ esac
121+
+ fi
122+
+ local iidpattern="(--iidfile( |=))([^[:blank:]]+)"
123+
+ local iidfile=
124+
+ if [[ "$*" =~ ${iidpattern} ]]; then
125+
+ iidfile=${BASH_REMATCH[3]}
126+
+ else
127+
+ shift
128+
+ iidfile=$(mktemp ${BATS_TMPDIR:-${TMPDIR:-/tmp}}/iidfileXXXXXX)
129+
+ set "build" "--iidfile=${iidfile}" "${@}"
130+
+ fi
131+
+ local tagpattern="(-t |--tag( |=))(oci|oci-archive|docker-archive|dir):([^[:blank:]]+)"
132+
+ if [[ -n "$REMOTE" ]] && [[ "$*" =~ ${tagpattern} ]]; then
133+
+ # We're attempting to commit directly to something other than default storage, and we don't want remote clients doing that,
134+
+ # so tweak the build command to instead tag the image with a more or less random name if it succeeds...
135+
+ local tmpImageName=localhost/$(basename $(mktemp -u | tr '[A-Z]' '[a-z]')):$(basename $(mktemp -u | tr '[A-Z]' '[a-z]'))
136+
+ local format=--format=docker-archive
137+
+ local location=${BASH_REMATCH[4]}
138+
+ local location2=
139+
+ case "${BASH_REMATCH[3]}" in
140+
+ oci) format=--format=oci-dir;;
141+
+ oci-archive) format=--format=oci-archive;;
142+
+ docker-archive) format=--format=docker-archive;;
143+
+ dir) format=--format=$nativearchive ; location2=dir:${location}; location=${location}archive;;
144+
+ esac
145+
+ set "${@/${BASH_REMATCH[3]}:${BASH_REMATCH[4]}/${tmpImageName}}"
146+
+ set "${@/--tag=${BASH_REMATCH[3]}:${BASH_REMATCH[4]}/--tag=${tmpImageName}}"
147+
+ # ... and then set up to copy that image to local disk for examination, if the build succeeds.
148+
+ copydown="echo copying image \$(cat ${iidfile}) to ${BASH_REMATCH[3]}:${BASH_REMATCH[4]}; rm -fr ${location} && mkdir -p $(dirname ${location}) && echo saving to ${location} && podman save --uncompressed ${format} -o ${location} \$(cat ${iidfile}) && podman rmi ${tmpImageName}"
149+
+ # If the target might be compressed, copy to a temporary location first, then to the destination.
150+
+ if [[ -n "${location2}" ]] ; then
151+
+ copydown="$copydown && mkdir -p $(dirname ${location2##*:}) && echo copying to ${location2} && ${COPY_BINARY} --dest-decompress ${nativearchive}:${location} ${location2} && rm -fr ${location}"
152+
+ fi
153+
+ copydown="$copydown && echo copied image ${tmpImageName} to ${BASH_REMATCH[3]}:${BASH_REMATCH[4]}"
154+
+ fi
112155
+ podman_or_buildah=${PODMAN_BINARY}
113156
+ _opts="${ROOTDIR_OPTS} ${PODMAN_REGISTRY_OPTS}"
114157
+ if [[ -n "$REMOTE" ]]; then
@@ -123,15 +166,14 @@ index 3d1211492..dbf175de3 100644
123166
+ esac
124167
+ fi
125168
+ local cmd_basename=$(basename ${podman_or_buildah})
126-
+
127169
+
128170
# Remember command args, for possible use in later diagnostic messages
129171
- MOST_RECENT_BUILDAH_COMMAND="buildah $*"
130172
+ MOST_RECENT_BUILDAH_COMMAND="$cmd_basename $*"
131173

132174
# If session is rootless and `buildah mount` is invoked, perform unshare,
133175
# since normal user cannot mount a filesystem unless they're in a user namespace along with its own mount namespace.
134-
@@ -388,8 +473,8 @@ function run_buildah() {
176+
@@ -394,8 +516,8 @@ function run_buildah() {
135177
retry=$(( retry - 1 ))
136178

137179
# stdout is only emitted upon error; this echo is to help a debugger
@@ -142,7 +184,17 @@ index 3d1211492..dbf175de3 100644
142184
# without "quotes", multiple lines are glommed together into one
143185
if [ -n "$output" ]; then
144186
echo "$output"
145-
@@ -753,6 +838,26 @@ function skip_if_no_unshare() {
187+
@@ -422,6 +544,9 @@ function run_buildah() {
188+
false
189+
fi
190+
191+
+ if [[ "$status" -eq 0 ]] ; then
192+
+ eval ${copydown}
193+
+ fi
194+
if [ -n "$expected_rc" ]; then
195+
if [ "$status" -eq "$expected_rc" ]; then
196+
return
197+
@@ -759,6 +884,26 @@ function skip_if_no_unshare() {
146198
fi
147199
}
148200

0 commit comments

Comments
 (0)