add support for dynamically calculated build arg sets (#4156)

This commit is contained in:
Avi Deitcher
2025-08-13 12:33:52 +03:00
committed by GitHub
parent 1caf2feffc
commit 999110c6de
12 changed files with 206 additions and 29 deletions

View File

@@ -19,10 +19,6 @@ clean_up() {
}
trap clean_up EXIT
# to be clear
pwd
ls -la .
for i in "${TMPDIR1}" "${TMPDIR2}"; do
rm -rf "${i}"
mkdir -p "${i}"
@@ -57,7 +53,6 @@ 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)

View File

@@ -19,10 +19,6 @@ clean_up() {
}
trap clean_up EXIT
# to be clear
pwd
ls -la .
for i in "${TMPDIR1}" "${TMPDIR2}"; do
rm -rf "${i}"
mkdir -p "${i}"
@@ -57,7 +53,6 @@ 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)

View File

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

View File

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

View File

@@ -0,0 +1 @@
HASH_%=@lkt:pkgs:/tmp/foo/*

View File

@@ -0,0 +1,2 @@
org: linuxkit
image: hashes-in-build-args-file

View File

@@ -0,0 +1,4 @@
org: linuxkit
image: hashes-in-build-args-yaml
buildArgs:
- HASH_%=@lkt:pkgs:/tmp/foo/*

View File

@@ -0,0 +1,94 @@
#!/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
TMPDIR=/tmp/foo
TMPDIR1=${TMPDIR}/one
TMPDIR2=${TMPDIR}/two
TMPEXPORT=$(mktemp -d)
CACHE_DIR=$(mktemp -d)
clean_up() {
rm -rf ${TMPDIR} ${CACHE_DIR} ${TMPEXPORT}
}
trap clean_up EXIT
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-$(basename "${i}")
EOF
done
git -C "${TMPDIR}" init
git -C "${TMPDIR}" config user.email "you@example.com"
git -C "${TMPDIR}" config user.name "Your Name"
git -C "${TMPDIR}" add .
git -C "${TMPDIR}" commit -m "Initial commit for special build arg test"
expected1=$(linuxkit pkg show-tag "${TMPDIR1}")
expected2=$(linuxkit pkg show-tag "${TMPDIR2}")
# 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}"
## Run two tests: with build args in yaml and with build arg file
targetarch="arm64"
for yml in build.yml build-file.yml; do
extra_args=""
if [ "$yml" = "build-file.yml" ]; then
extra_args="--build-arg-file ./build-args"
fi
linuxkit --cache ${CACHE_DIR} pkg build --platforms linux/${targetarch} --force --build-yml "${yml}" . ${extra_args} 2>&1
if [ $? -ne 0 ]; then
echo "Build failed"
exit 1
fi
current=$(linuxkit pkg show-tag --build-yml "${yml}" .)
# for debugging
find ${CACHE_DIR} -ls
cat ${CACHE_DIR}/index.json
index=$(cat ${CACHE_DIR}/index.json | jq -r '.manifests[] | select(.annotations["org.opencontainers.image.ref.name"] == "'${current}'") | .digest' | cut -d: -f2)
echo "Current package index: ${index}"
cat ${CACHE_DIR}/blobs/sha256/${index} | jq '.'
manifest=$(cat ${CACHE_DIR}/blobs/sha256/${index} | jq -r '.manifests[] | select(.platform.architecture == "'${targetarch}'") | .digest' | cut -d: -f2)
echo "Current package manifest: ${manifest}"
cat ${CACHE_DIR}/blobs/sha256/${manifest} | jq '.'
# dump it to a filesystem
rm -rf "${TMPEXPORT}/*"
linuxkit --cache ${CACHE_DIR} cache export --platform linux/${targetarch} --format filesystem --outfile /tmp/lktout123.tar "${current}"
file /tmp/lktout123.tar
ls -l /tmp/lktout123.tar
cat /tmp/lktout123.tar | tar -C "${TMPEXPORT}" -xvf -
# for extra debugging
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
done
exit 0