Created
May 15, 2021 15:14
-
-
Save thiagoalmeidasa/ae09f5051ccc91c91300af9ae98d2e09 to your computer and use it in GitHub Desktop.
Multi platform builds with buildx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script demonstrates how to use `docker buildx` to build container | |
# images for the linux/amd64 and linux/arm64 platforms. It creates a | |
# `docker buildx` builder instance when required. | |
# | |
# If you change the platforms, be sure to | |
# | |
# (1) delete the buildx builder named `-builder`, and | |
# (2) update the corresponding node-affinities in k8s/pod.yaml. | |
# The platforms to build. | |
platforms="linux/amd64,linux/arm64" | |
# `buildx` uses named _builder_ instances configured for specific platforms. | |
# This script creates a `multi-plat-builder` as required. | |
if ! docker buildx inspect multi-plat-builder >/dev/null 2>&1; then | |
docker buildx create --name multi-plat-builder --platform $platforms | |
fi | |
# Building for multiple platforms requires pushing to a registry | |
# as the Docker Daemon cannot load multi-platform images. | |
if [ "$PUSH_IMAGE" = true ]; then | |
args="--platform $platforms --push" | |
else | |
args="--load" | |
fi | |
set -x # show the command-line | |
docker buildx build --builder multi-plat-builder --tag $IMAGE $args "$BUILD_CONTEXT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment