-
Notifications
You must be signed in to change notification settings - Fork 557
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
Cache backend API example #406
Conversation
Only merge when buildx 0.6 and BuildKit 0.9 are released. In the meantime you can test this feature with the following workflow: name: ci
on:
push:
branches:
- 'master'
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: v0.6.0
buildkitd-flags: --debug
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: user/app:latest
cache-from: type=gha
cache-to: type=gha,mode=max |
Use the new github actions cache backend to cache docker layers, configured as specified in this pull request comment: docker/build-push-action#406 (comment). The backend is still experimental but should already work. This solutions is more elegant and could be faster than the previous approach.
Use the new github actions cache backend to cache docker layers, configured as specified in this pull request comment: docker/build-push-action#406 (comment). The backend is still experimental but should already work. This solutions is more elegant and could be faster than the previous approach.
3e9ad64
to
b38b2e7
Compare
I think this can be merged now 🎉 Super cool work I have been looking forward this! |
@mmeendez8 GitHub virtual environments don't have buildx 0.6.0 (0.5.1 atm) so will wait until then. |
Oh I see, any idea about when this might happen? We may create a new topic in a discussions section |
I think it's Microsoft internal. cc @cpuguy83 |
Having some pipeline issues at the moment, but hoping to get this out today or tomorrow.... then it'll need to be picked up in the virtual-env image that GHA uses. |
@cpuguy83 Thanks a bunch! |
0.6.0 is available now, but I'm not sure when the GHA virtual-env images will be updated. You should be able to manually update ( |
This is awesome guys - great work! We've been trying this out over the last couple days and have noticed that the first build for a PR typically doesn't seem to have any cached layers. However subsequent commits to the PR seem to have cached layers and are much faster. Is this expected? For example my hope would have been that a PR merging into |
Images are generated on a weekend and deployed throughout the week, so it might be next week when |
@ianschmitz Are you using multiple restore keys? We use a system like this to fallback to a "any" image if the branch one isn't available.
So in this example you could make the second one match your main branch key. |
@robpc negative. We're following the example laid out in this PR (i think it's correct?). It looks like this: - name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: v0.6.0-rc1
driver-opts: image=moby/buildkit:v0.9.0-rc2
buildkitd-flags: --debug
- name: Login to ECR
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REG }}
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha
file: docker/Dockerfile
platforms: linux/amd64, linux/arm64
push: true
tags: ${{ env.DOCKER_REG }}/foo:${{ github.sha }} Where i was hoping that |
@ianschmitz Sorry, I got my wires crossed a bit. The example I showed was from the workaround to using local in buildx and manually setting the gh cache. I am wondering if there is an equivalent way of specifying multiple keys in this buildx option. I realize now that is probably what your question was, so apologies for that. It sounds like |
Np! I guess that's what my question is? I was more hoping that the default behavior when using Effectively the pseudo logic i was thinking would be something like:
Something along those lines 😃 |
@ianschmitz
As far as I can tell from my workflows (e.g. jojomatik/blockcluster#147 (workflow)) the same logic is true for this new cache backend. Not sure why it's not working for you. |
As far as I know the github cache action doesn't have a default. From the documentation for the cache action:
The implication there is that the user is supplying both the I am curious what the fallback logic is as implemented by this feature in buildx and if we have the power to change it. If this new feature in buildx is more or less mimicking this functionality, what is the |
|
Runners image update 20210726 includes Buildx PRs should be merged once all GitHub runners are deployed with this version (when above badges will be at 100% with version |
…g in gh actions
…g in gh actions
I'm not sure if this is related to the |
Have you tried adding |
I actually need |
🤦 nevermind, I think I see what is happening. I'm using a multi-stage docker build. Any change that is causing the first stage to be rebuilt is invalidating the cache. It has nothing to do with the fetch-depth, scope, or the I had assumed this was caching the whole docker environment including steps for non-final stages - it looks like the only thing that is cached is the final stage image, so anything that requires any step of an earlier stage to be rebuilt appears to cause the cache to not add any savings. edit: setting the cache mode to max does what I need cache-from: type=gha
cache-to: type=gha,mode=max |
6ffd7c3
to
7ee180e
Compare
7ee180e
to
f06051e
Compare
Signed-off-by: CrazyMax <[email protected]>
f06051e
to
3530a97
Compare
@@ -600,7 +579,7 @@ jobs: | |||
id: cache | |||
with: | |||
path: /tmp/.buildx-cache | |||
key: ${{ runner.os }}-buildx-ghcache-${{ github.sha }} | |||
key: ${{ runner.os }}-buildx-local-${{ github.sha }} | |||
restore-keys: | | |||
${{ runner.os }}-buildx-ghcache- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the restore-keys have been updated from "ghcache" to "local" as well?
Follow-up moby/buildkit#1974 docker/buildx#535
Signed-off-by: CrazyMax [email protected]