buildx icon indicating copy to clipboard operation
buildx copied to clipboard

Feature request: Save and reload multi-platform images

Open mortenlj opened this issue 5 years ago • 2 comments

A common pattern I've used a lot is to have a two step build pipeline. The first step is to build the docker image and run tests etc. The second step is only run if some condition is true, and pushes the image to a registry.

When using buildx to build a multi-platform image, I can't seem to find a set of commands that allows me to do this. There are several output options that will save a multi-platform image to disk, either as a file tree, a tarball, or an OCI Image tarball. But I haven't been able to find a way to take that output and upload it to a registry in the next step.

Crucially, I don't want to run the build again, because that will happen in a different runner without any cache. Running the build again opens up the possibility that something changes, and then you push an untested image to the registry.

The way I do this with normal docker and single-platform images:

First step:

  • docker build . --tag "${IMAGE_NAME}:${TAG}" --tag "${IMAGE_NAME}:latest"
  • Run various tests
  • docker image save "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:latest" | bzip2 > docker.tar.bz2
  • Save docker.tar.bz2 to suitable artifact storage

Second step:

  • Fetch docker.tar.bz2 from artifact storage
  • bunzip2 --stdout docker.tar.bz2 | docker image load
  • docker push "${IMAGE_NAME}"

mortenlj avatar Sep 15 '20 10:09 mortenlj

I have the same request, but for a slightly different reason: CI time & code reduction. I would like to avoid running the same build twice in CI, and it would be nice to define the build a single time and share it across multiple tagging & deployment jobs.

GeorgeHahn avatar Mar 21 '21 07:03 GeorgeHahn

Hm. Does this issue cover the case where one wants to save out architecture specific images from the cache that buildx produced. I'd like to do docker save for each architecture specific image that buildx build --platform foo,bar produced.

quite avatar Mar 17 '22 07:03 quite