add support for custom build args (#4155)

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher
2025-08-11 11:58:17 +03:00
committed by GitHub
parent 3d9bb9a128
commit 1caf2feffc
14 changed files with 308 additions and 6 deletions

View File

@@ -0,0 +1 @@
foo/

View File

@@ -0,0 +1,5 @@
FROM alpine:3.21
ARG HASH1
ARG HASH2
RUN printf '%s\n' "${HASH1}" > /var/hash1
RUN printf '%s\n' "${HASH2}" > /var/hash2

View File

@@ -0,0 +1,5 @@
org: linuxkit
image: hashes-in-build-args
buildArgs:
- HASH1=@lkt:pkg:foo/
- HASH2=@lkt:pkg:/tmp/bar12345/

View File

@@ -0,0 +1,77 @@
#!/bin/sh
# SUMMARY: Check that tar output format build is reproducible
# LABELS:
set -e
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
# need to build the special dir /tmp/bar12345 first
TMPDIR1=/tmp/bar12345
TMPDIR2=./foo/
TMPEXPORT=$(mktemp -d)
CACHE_DIR=$(mktemp -d)
clean_up() {
rm -rf ${TMPDIR1} ${TMPDIR2} ${CACHE_DIR} ${TMPEXPORT}
}
trap clean_up EXIT
# to be clear
pwd
ls -la .
for i in "${TMPDIR1}" "${TMPDIR2}"; do
rm -rf "${i}"
mkdir -p "${i}"
echo "This is a test file for the special build arg" > "${i}/test"
cat > "${i}/build.yml" <<EOF
org: linuxkit
image: hashes-in-build-args
EOF
git -C "${i}" init
git -C "${i}" config user.email "you@example.com"
git -C "${i}" config user.name "Your Name"
git -C "${i}" add .
git -C "${i}" commit -m "Initial commit for special build arg test"
done
# print it out for the logs
echo "Building packages with special build args from ${TMPDIR1} and ${TMPDIR2}"
linuxkit --cache ${CACHE_DIR} pkg show-tag "${TMPDIR1}"
linuxkit --cache ${CACHE_DIR} pkg show-tag "${TMPDIR2}"
logs=$(linuxkit --cache ${CACHE_DIR} pkg build --force . 2>&1)
if [ $? -ne 0 ]; then
echo "Build failed with logs:"
echo "${logs}"
exit 1
fi
expected1=$(linuxkit pkg show-tag "${TMPDIR1}")
expected2=$(linuxkit pkg show-tag "${TMPDIR2}")
current=$(linuxkit pkg show-tag .)
# dump it to a filesystem
linuxkit --cache ${CACHE_DIR} cache export --format filesystem --outfile - "${current}" | tar -C "${TMPEXPORT}" -xvf -
# for extra debugging
find "${TMPEXPORT}" -type f -exec ls -la {} \;
actual1=$(cat ${TMPEXPORT}/var/hash1)
actual2=$(cat ${TMPEXPORT}/var/hash2)
if [ "${expected1}" != "${actual1}" ]; then
echo "Expected HASH1: ${expected1}, but got: ${actual1}"
exit 1
fi
if [ "${expected2}" != "${actual2}" ]; then
echo "Expected HASH2: ${expected2}, but got: ${actual2}"
exit 1
fi
# Check that the build args were correctly transformed
exit 0

View File

@@ -0,0 +1,5 @@
FROM alpine:3.21
ARG HASH1
ARG HASH2
RUN printf '%s\n' "${HASH1}" > /var/hash1
RUN printf '%s\n' "${HASH2}" > /var/hash2

View File

@@ -0,0 +1,2 @@
HASH1=@lkt:pkg:foo/
HASH2=@lkt:pkg:/tmp/bar67890/

View File

@@ -0,0 +1,2 @@
org: linuxkit
image: test-image-in-yaml-build-args

View File

@@ -0,0 +1,76 @@
#!/bin/sh
# SUMMARY: Check that tar output format build is reproducible
# LABELS:
set -e
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
# need to build the special dir /tmp/bar12345 first
TMPDIR1=/tmp/bar67890
TMPDIR2=./foo/
TMPEXPORT=$(mktemp -d)
CACHE_DIR=$(mktemp -d)
clean_up() {
rm -rf ${TMPDIR1} ${TMPDIR2} ${CACHE_DIR} ${TMPEXPORT}
}
trap clean_up EXIT
# to be clear
pwd
ls -la .
for i in "${TMPDIR1}" "${TMPDIR2}"; do
rm -rf "${i}"
mkdir -p "${i}"
echo "This is a test file for the special build arg" > "${i}/test"
cat > "${i}/build.yml" <<EOF
org: linuxkit
image: hashes-in-build-args
EOF
git -C "${i}" init
git -C "${i}" config user.email "you@example.com"
git -C "${i}" config user.name "Your Name"
git -C "${i}" add .
git -C "${i}" commit -m "Initial commit for special build arg test"
done
# print it out for the logs
echo "Building packages with special build args from ${TMPDIR1} and ${TMPDIR2}"
linuxkit --cache ${CACHE_DIR} pkg show-tag "${TMPDIR1}"
linuxkit --cache ${CACHE_DIR} pkg show-tag "${TMPDIR2}"
logs=$(linuxkit --cache ${CACHE_DIR} pkg build --force --build-arg-file build-args . 2>&1)
if [ $? -ne 0 ]; then
echo "Build failed with logs:"
echo "${logs}"
exit 1
fi
expected1=$(linuxkit pkg show-tag "${TMPDIR1}")
expected2=$(linuxkit pkg show-tag "${TMPDIR2}")
current=$(linuxkit pkg show-tag .)
# dump it to a filesystem
linuxkit --cache ${CACHE_DIR} cache export --format filesystem --outfile - "${current}" | tar -C "${TMPEXPORT}" -xvf -
# for extra debugging
find "${TMPEXPORT}" -type f -exec ls -la {} \;
actual1=$(cat ${TMPEXPORT}/var/hash1)
actual2=$(cat ${TMPEXPORT}/var/hash2)
if [ "${expected1}" != "${actual1}" ]; then
echo "Expected HASH1: ${expected1}, but got: ${actual1}"
exit 1
fi
if [ "${expected2}" != "${actual2}" ]; then
echo "Expected HASH2: ${expected2}, but got: ${actual2}"
exit 1
fi
# Check that the build args were correctly transformed
exit 0