mirror of
https://github.com/containers/podman.git
synced 2026-02-05 15:45:08 +01:00
Adds /libpod/local/build endpoint, client bindings, and path translation utilities to enable container builds from mounted directories to podman machine without tar uploads. This optimization significantly speeds up build operations when working with remote Podman machines by eliminating redundant file transfers for already-accessible files. Fixes: https://issues.redhat.com/browse/RUN-3249 Signed-off-by: Jan Rodák <hony.com@seznam.cz>
89 lines
2.6 KiB
Bash
89 lines
2.6 KiB
Bash
# -*- sh -*-
|
|
#
|
|
# Tests for build-related endpoints
|
|
#
|
|
|
|
# test if default compat build contains labels from base image
|
|
TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
|
|
function cleanBuildTest() {
|
|
podman rmi -a -f
|
|
rm -rf "${TMPD}" &> /dev/null
|
|
}
|
|
CONTAINERFILE_TAR="${TMPD}/containerfile.tar"
|
|
cat > $TMPD/containerfile << EOF
|
|
FROM $IMAGE
|
|
RUN echo hello
|
|
EOF
|
|
tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null
|
|
|
|
t POST "/build?dockerfile=containerfile&t=labeltest" $CONTAINERFILE_TAR 200 \
|
|
'.aux|select(has("ID")).ID~^sha256:[0-9a-f]\{64\}$'
|
|
|
|
t GET images/labeltest/json 200 \
|
|
.Config.Labels.created_by="test/system/build-testimage"
|
|
cleanBuildTest
|
|
|
|
# --- /libpod/local/build tests
|
|
|
|
TMPD=$(mktemp -d podman-apiv2-test.localbuild.XXXXXXXX)
|
|
TMPD=$(realpath "$TMPD")
|
|
|
|
|
|
cat > $TMPD/Containerfile << EOF
|
|
FROM $IMAGE
|
|
RUN echo "local build test"
|
|
LABEL test=local-build
|
|
EOF
|
|
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}&t=localbuildtest" - 200
|
|
|
|
t GET images/localbuildtest/json 200 \
|
|
.Config.Labels.test="local-build"
|
|
|
|
|
|
cat > $TMPD/MyDockerfile << EOF
|
|
FROM $IMAGE
|
|
RUN echo "custom dockerfile"
|
|
LABEL dockerfile=custom
|
|
EOF
|
|
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}&dockerfile=${TMPD}/MyDockerfile&t=customdockerfile" - 200
|
|
|
|
t GET images/customdockerfile/json 200 \
|
|
.Config.Labels.dockerfile="custom"
|
|
|
|
|
|
# Test local build with additional build contexts
|
|
mkdir -p ${TMPD}/additional_context
|
|
echo "additional file" > ${TMPD}/additional_context/extra.txt
|
|
|
|
cat > $TMPD/AdditionalContext << EOF
|
|
FROM $IMAGE
|
|
COPY --from=additional /extra.txt /copied.txt
|
|
RUN cat /copied.txt
|
|
EOF
|
|
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}&dockerfile=${TMPD}/AdditionalContext&additionalbuildcontexts=additional=localpath:${TMPD}/additional_context&t=additionalcontext" - 200
|
|
|
|
echo "not a directory" > ${TMPD}/notadir
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}/notadir&t=filenotdir" - 400
|
|
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}&dockerfile=/nonexistent/dockerfile&t=invalidfile" - 404
|
|
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}&additionalbuildcontexts=malformed-context-spec=localpath:/nonexistent/directory&t=badcontext" - 404
|
|
|
|
t POST "libpod/local/build?localcontextdir=${TMPD}&additionalbuildcontexts=malformed-context-spec=localpath:../../nonexistent/directory&t=badcontext" - 400
|
|
|
|
cleanBuildTest
|
|
|
|
t POST "libpod/local/build?localcontextdir=/nonexistent/directory&t=errortest" - 404
|
|
|
|
t POST "libpod/local/build?localcontextdir=../../../etc/passwd&t=errortest" - 400
|
|
|
|
t POST "libpod/local/build?t=missingcontext" - 400
|
|
|
|
t POST "libpod/local/build?localcontextdir=&t=emptycontext" - 400
|
|
|
|
|
|
# vim: filetype=sh
|