Skip to content

Commit

Permalink
Build trice tag once
Browse files Browse the repository at this point in the history
There some complexity with buildx tagging for multiarch builds: docker/buildx#166
The upshot of it is that we have to invoke `docker buildx build` three
times, once to build both archs and another time to tag just the current
arch. We use this tag in the test function invoked later in the build script.
Finally, for pushing to ECR, we need to invoke it again with the `--push` argument.

Fortunately the docker layer cache should ensure the 2nd and 3rd builds
are rather quick.
  • Loading branch information
triarius committed Jan 10, 2023
1 parent 60e942a commit 6665623
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .buildkite/steps/build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -Eeufo pipefail

## This script can be run locally like this:
## If you are pushing, then images for all archtectures need to be built using buildx.
## If you are pushing, then images for all architectures need to be built using buildx.
## This typically requires something like `qemu-user-static` to be avaliable
##
## .buildkite/steps/build-docker-image.sh (alpine|alpine-k8s|ubuntu-18.04|ubuntu-20.04|sidecar) (image tag) (codename) (version)
Expand Down Expand Up @@ -81,6 +81,11 @@ trap "docker buildx rm $builder_name" EXIT
echo "--- Building :docker: $image_tag"
cp -a packaging/linux/root/usr/share/buildkite-agent/hooks/ "${packaging_dir}/hooks/"
cp pkg/buildkite-agent-linux-{amd64,arm64} "$packaging_dir"

# Build images for all architectures
docker buildx build --progress plain --builder "$builder_name" --platform linux/amd64,linux/arm64 "$packaging_dir"
# Tag images for just the architecture we are on. There is a limitation in docker that prevents this
# from being done in one command. Luckliy the second build will be quick because of docker layer caching
docker buildx build --progress plain --builder "$builder_name" --tag "$image_tag" --load "$packaging_dir"

case $variant in
Expand All @@ -103,5 +108,6 @@ if [[ $push == "true" ]] ; then
--builder "$builder_name" \
--tag "$image_tag" \
--platform linux/amd64,linux/arm64 \
--push "$packaging_dir"
--push \
"$packaging_dir"
fi

0 comments on commit 6665623

Please sign in to comment.