-
Notifications
You must be signed in to change notification settings - Fork 582
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
Export layers to "regular" docker #539
Comments
There are two things to take into account. When you use the cache exporter (
I agree and I would suggest to use the GitHub cache exporter instead. Here is what I would do: - uses: actions/checkout@v2
- name: Set up docker buildx
uses: docker/setup-buildx-action@v1
- name: Build base Docker image
uses: docker/build-push-action@v2
with:
tags: my-image-cached
cache-from: type=gha,scope=cached-stage
cache-to: type=gha,scope=cached-stage,mode=max
target: cached
- name: Build final docker image
uses: docker/build-push-action@v2
with:
tags: my-image
load: true
cache-from: type=gha,scope=cached-stage
- run: docker run my-image ... Also |
You could also improve your workflow and have a dedicated job that will just build and cache the jobs:
base:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build base Docker image
uses: docker/build-push-action@v2
with:
context: .
cache-from: type=gha,scope=cached-stage
cache-to: type=gha,scope=cached-stage,mode=max
target: cached
build:
needs:
- base
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build final docker image
uses: docker/build-push-action@v2
with:
context: .
tags: my-image
load: true
cache-from: type=gha,scope=cached-stage
-
run: docker run my-image ... |
@crazy-max thanks for the quick reply!
So you mean that I actually do not need to
Thanks for the suggestion. I looked into it but saw it was labeled as "experimental" in the buildx docs, and moreover couldn't quite understand how it works; does it store artefacts locally, or will it upload the cache after each build? Similarly, won't splitting my build in two different jobs cause more download and upload? One fact that I didn't mention is that my base image is ~3GB, which means that uploading and downloading takes some time. |
Yes it should work. Let me know if you encounter an issue.
It uses the same API as
Yes in that case it would be more effective to have a single job agree but using the GitHub cache exporter of BuildKit is more effective than |
@crazy-max Ok so I confirm: if I remove Also, is there any way to have something akin to |
Can you declare a -
name: Build base Docker image
uses: docker/build-push-action@v2
with:
context: .
cache-from: type=gha,scope=cached-stage
cache-to: type=gha,scope=cached-stage,mode=max
outputs: type=cacheonly
target: cached
You could use the |
@crazy-max Base image building now, will report when it's done. I'm assuming I should try without
There's a fair bit of overhead. When there's a cache hit, the actual (second step, non-cached) build takes 2mn (125s), but the OCI export step takes an additional 3.5mn (200s). |
Yes that's it. |
Unfortunately omitting |
You're welcome, see also dfinity/nns-dapp#357 (review) to export artifacts as it seems it's what you want so it removes the |
Thanks for all the help here, really appreciated! The workflow is much simpler and about twice as fast. Got yourself a new sponsor :) |
Hi, thanks for the great action!
I've been trying to figure out how to export a
buildx
build to Docker that includes the layers. Right now I useload: true
which allows me to run e.g.docker run
subsequently, however now I'm trying to figure out how to export the layers as well.I have a 2-step build. The first step is a
build-push-action
build that is cached between runs (usingcache-to
and saved withactions/cache
). My second build is not cached, and re-uses the layers from the first build withcache-from
. This second build is saved to docker (throughload: true
), so I can usedocker run
and other commands (build file below).While I need
build-push-action
in the first build step (in order to export and cache the layers), I'd like to not use it in the second step, and use a regulardocker build
instead. The reason is that the second step wastes about a minute importing the output withcache-from
. Unfortunately, I noticed that when I save the image withload: true
, a subsequentdocker build
won't be able to re-use the layers, but will see the image as a whole. Is there a way to export the layers from buildx so that I can use them in a regulardocker build
?The text was updated successfully, but these errors were encountered: