Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Save and Push #727

Closed
deavisdude opened this issue Nov 22, 2022 · 13 comments · Fixed by docker/buildx#2302
Closed

Feature Request: Save and Push #727

deavisdude opened this issue Nov 22, 2022 · 13 comments · Fixed by docker/buildx#2302

Comments

@deavisdude
Copy link

deavisdude commented Nov 22, 2022

I would like to be able to use this action to build a docker image, and then both save the image locally AND push it to a container registry. I want to be able to perform other actions on the image like a container image scan as a part of my CI workflow. Currently, I am only able to give either push: true OR outputs: type=docker,dest=/tmp/myimage.tar meaning that I have to do one of the following:

  • build the image twice, once with local outputs and once with a push
  • build the image locally and just use another action/job to do the push
  • go and fetch it from the registry I just pushed it to to perform additional actions

Ideally I would just like to use this action to build my image and push it to the container registry, while retaining a local file for use in other jobs.

@jedevc
Copy link
Contributor

jedevc commented Nov 22, 2022

This looks similar to moby/buildkit#2760 - currently multiple exporters aren't supported.

You can work around this today by creating multiple invocations of the build-push-action, the invocations after the first won't be re-run (as long as no content has changed), since all the content should be cached.

@ricardo-dematos
Copy link

@jedevc I followed your idea but, although it uses the cached layers, thus speeding up the process, it still produces "different" images.

@JoshMcCullough
Copy link

JoshMcCullough commented May 16, 2023

It would be nice to have an option to save the image as an artifact. Just to remove the extra duplicated YML to run Docker build twice. Sure, could move that job to a reusable workflow, but that just adds more complexity.

@DaAwesomeP
Copy link

Is this possible now that moby/buildkit#4134 has merged?

@crazy-max
Copy link
Member

Will be with next Buildx 0.13 and BuildKit 0.13.

@tonynajjar
Copy link

tonynajjar commented Mar 1, 2024

@crazy-max I tried using this Github actions configuration but still got the error ERROR: push and load may not be set together at the moment. Any idea why? The needed changes should be in these pre-releases.

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        with:
          version: v0.13.0-rc2
          driver-opts: image=moby/buildkit:v0.13.0-rc3

Setting up successfully:

image

Fail message:

Run docker/build-push-action@v5

Buildx version
  /usr/bin/docker buildx version
  github.com/docker/buildx v0.13.0-rc2 e273a53c88832df6dceebd727a259cae2fd5be88
/usr/bin/docker buildx build --ssh default=/tmp/ssh-XXXXXXeOnRQE/agent.2698 --tag europe-west3-docker.pkg.dev/my-project/my-project/my-project:main --target dev --load --metadata-file /home/runner/work/_temp/docker-actions-toolkit-4m2nWl/metadata-file --push docker/desktop/
ERROR: push and load may not be set together at the moment
Error: buildx failed with: ERROR: push and load may not be set together at the moment

@crazy-max
Copy link
Member

@tonynajjar Thanks for trying this out! I'm looking at it and keep you posted.

@crazy-max
Copy link
Member

Ok after looking at it we indeed forgot to handle the push and load shorthand. I tested local changes on my side and it seems to work. I'm opening a PR on buildx repo asap to have this in v0.13.

$ docker buildx --builder builder build --load --push --tag crazymax/test:buildx013 .
...
...
#17 [gobase 3/3] WORKDIR /src
#17 CACHED

#18 importing to docker
#18 DONE 0.0s

#19 exporting to docker image format
#19 exporting layers done
#19 exporting manifest sha256:e00c6a8b8abd1a8894f04bc42ba7790dd4fc65827749131b38c94cc5f7edc542 0.0s done
#19 exporting config sha256:f531890d23f1061bbab561329fd116ed1eb292d96c4d21f5313ca05289a0f573 done
#19 sending tarball 0.1s done
#19 DONE 0.1s

#20 exporting to image
#20 exporting layers done
#20 exporting manifest sha256:c4ec88b12080da795ce65e208b8c63eb46489a8ddc7826903e888d212aeb6c4b 0.0s done
#20 exporting config sha256:f531890d23f1061bbab561329fd116ed1eb292d96c4d21f5313ca05289a0f573 0.0s done
#20 exporting attestation manifest sha256:159347107ebe1d2cf2a50c9202cc66bf7e1fbc71d2021a6552c7ddee3edddd86 0.1s done
#20 exporting manifest list sha256:42572ae22030649847750526830d4324b4eef5d2d16ace609d5ad7cdfa84524d 0.0s done
#20 pushing layers
#20 ...

#21 [auth] crazymax/test:pull,push token for registry-1.docker.io
#21 DONE 0.0s

#20 exporting to image
#20 pushing layers 4.5s done
#20 pushing manifest for docker.io/crazymax/test:buildx013@sha256:42572ae22030649847750526830d4324b4eef5d2d16ace609d5ad7cdfa84524d
#20 pushing manifest for docker.io/crazymax/test:buildx013@sha256:42572ae22030649847750526830d4324b4eef5d2d16ace609d5ad7cdfa84524d 1.2s done
#20 DONE 5.8s

View build details: docker-desktop://dashboard/build/builder/builder0/r4tqwahepxipca10ytz6kwzjl

@crazy-max
Copy link
Member

@tonynajjar Can you try with this step and let us know?:

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        with:
          version: https://github.com/crazy-max/buildx.git#multi-load-push
          driver-opts: image=moby/buildkit:v0.13.0-rc3

@tonynajjar
Copy link

tonynajjar commented Mar 1, 2024

on it

EDIT: I'm affected by https://www.githubstatus.com/incidents/wcl1sw4mzg60 so it might take a bit longer

@tonynajjar
Copy link

tonynajjar commented Mar 1, 2024

From my very basic test looks like it works! 🚀

@crazy-max
Copy link
Member

@tonynajjar Just made some tests in this repo as well and looks good: #1075

@DaAwesomeP
Copy link

May someone provide an example of the original configuration in question? Is this correct?

uses: docker/build-push-action@v5
with:
  push: true
  outputs: |
    docker,dest=image.tar
  push: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants