Skip to content

Commit

Permalink
apps: Optionally load built images to docker store
Browse files Browse the repository at this point in the history
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 <mike.sul@foundries.io>
  • Loading branch information
mike-sul committed Jun 17, 2024
1 parent b40fb74 commit 50007ef
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion apps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit 50007ef

Please sign in to comment.