Add local build API for direct filesystem builds on MacOS and Windows (only WSL)

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>
This commit is contained in:
Jan Rodák
2025-09-12 14:30:01 +02:00
parent 685a448ccc
commit a1e7e9a46d
11 changed files with 812 additions and 17 deletions

View File

@@ -23,4 +23,66 @@ 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