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

caching the Docker image #35

Open
tropxy opened this issue Sep 22, 2022 · 3 comments
Open

caching the Docker image #35

tropxy opened this issue Sep 22, 2022 · 3 comments

Comments

@tropxy
Copy link

tropxy commented Sep 22, 2022

Hi, thanks for your great work on this, very helpful!

I was wondering what would be the best strategy to cache the docker image used by this action...would it be something related with using the cache action https://github.com/actions/cache? but how should we use it in combination with your action?

I also checked this thread: https://stackoverflow.com/questions/66421411/how-to-run-cached-docker-image-in-github-action, which gives a glimpse but I suppose your action would need to be modified for this...

@Fuseteam
Copy link

hmmm that seems to be about building caching and running an image, i'm not sure if it applies to pulling, caching and running an image.

is your use case caching within one workflow or across workflow? i've heard across workflow is like not possible

@envzhu
Copy link

envzhu commented Nov 3, 2022

I found a simple way to use caches on this action, so share it here.

The solution is to set the load option to true and specify a kind of cache by cache-from and cache-to when building a container with caches.
The load lets docker load container images built from caches to docker images. (docker buildx build | Docker Documentation)
Without setting the load, docker can't find the cached container image when trying to run a container.

An example to use caches via GitHub Cache API:

- uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v3
  with:
    tags: test-image:latest
    push: false
    load: true
    cache-from: type=gha
    cache-to: type=gha,mode=max
- uses: addnab/docker-run-action@v3
  with:
    image: test-image:latest
    run: echo "hello world"

Notices:

  • Using Buildx as docker driver is required to export a cache.
  • This example uses GitHub Cache API, which is EXPERIMENTAL on docker/build-push-action. However, I think it is the clearest way to use GitHub Actions Cache.
  • This should be applicable to another cache mechanism. See build-push-action/cache.md at master · docker/build-push-action for more details.

@max-sixty
Copy link

Thanks @envzhu — this was v helpful

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

No branches or pull requests

4 participants