From 50007efc424b62a9cbc6f1975740834f23e39e4e Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Mon, 17 Jun 2024 12:40:58 +0200 Subject: [PATCH] apps: Optionally load built images to docker store If buildkit and buildx supports multiple outputs then: - Load built images to the local docker store. - Push/output built images to registry. Make sure the OCI types are not used and create an image manifest not index. Signed-off-by: Mike Sul --- apps/build.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/build.sh b/apps/build.sh index dc3c79a2..d7001f42 100755 --- a/apps/build.sh +++ b/apps/build.sh @@ -16,8 +16,22 @@ HERE=$(dirname $(readlink -f $0)) require_params FACTORY +compare_versions() { + local ver1=$1 + local ver2=$2 + + if [[ "$(echo -e "$ver1\n$ver2" | sort -V | head -n1)" == "$ver1" ]]; then + return 0 # true, ver1 is less than or equal to ver2 + else + return 1 # false, ver1 is greater than ver2 + fi +} + export DOCKER_BUILDKIT=1 BUILDKIT_VERSION="${BUILDKIT_VERSION-v0.10.3}" +BUILDX_VERSION=$(docker buildx version | awk '{print $2}') +echo "BuildKit version: ${BUILDKIT_VERSION}" +echo "Buildx version: ${BUILDX_VERSION}" MANIFEST_PLATFORMS_DEFAULT="${MANIFEST_PLATFORMS_DEFAULT-linux/amd64,linux/arm,linux/arm64}" status Default container platforms will be: $MANIFEST_PLATFORMS_DEFAULT @@ -127,7 +141,11 @@ for x in $IMAGES ; do docker_cmd="$docker_cmd --no-cache" fi - docker_cmd="$docker_cmd --push --cache-to type=registry,ref=${ct_base}:${LATEST}-${ARCH}_cache,mode=max" + if compare_versions "v0.13.1" "${BUILDX_VERSION}" && compare_versions "v0.13.1" "${BUILDKIT_VERSION}"; then + docker_cmd="$docker_cmd --load --output=type=registry,oci-mediatypes=false --provenance=false --cache-to type=registry,ref=${ct_base}:${LATEST}-${ARCH}_cache,mode=max" + else + docker_cmd="$docker_cmd --push --cache-to type=registry,ref=${ct_base}:${LATEST}-${ARCH}_cache,mode=max" + fi if [ -n "$DOCKER_SECRETS" ] ; then status "DOCKER_SECRETS defined - building --secrets for $(ls /secrets)"