Replies: 8 comments 1 reply
-
GitHub Actions doesn't directly support Docker image caching in the same way it does for dependencies with actions/cache. |
Beta Was this translation helpful? Give feedback.
-
you can achieve similar results by combining a few techniques. First, ensure Docker's BuildKit is enabled as it has improved caching mechanisms. You can enable it by setting the environment variable DOCKER_BUILDKIT=1 before your docker commands. BuildKit stores its cache separately from docker images and layers. You can leverage actions/cache to cache this BuildKit cache. try like this:
Log in to GitHub Container Registry, Push, Logout steps remain the same |
Beta Was this translation helpful? Give feedback.
-
@h0vhann1syan, thank you for responding and helping. The way I understood it, the BuiltKit is for the building phase. That part does not bother us. We are stuck at the pull phase. Our build needs some base images and it takes a lot of time to pull them each time. That's where we want to leverage caching. We tried to use So, does this BuildKit cache the pulled images too? |
Beta Was this translation helpful? Give feedback.
-
Probably for your specific use case where the pulling of base images is the bottleneck, BuildKit's caching mechanisms might not provide the direct benefit you're looking for, as it focuses more on caching build steps rather than the initial image pulls. If your base images don't change frequently, you could set up a Docker registry proxy closer to your GitHub Actions runners. This approach involves more setup but could reduce pull times if your images are large and network transfer is a significant portion of your build time. GitHub Actions runners are hosted in GitHub's data centers, so having a proxy registry within the same network could potentially speed up image pulls. |
Beta Was this translation helpful? Give feedback.
-
@h0vhann1syan, we tried to host our images on the ghcr.io, because we heard that hosting images there would drastically improve pull time. But for us, it did not change anything. The pull time was the same. So I guess creating a proxy won't help. The only option is to somehow tell docker that this image is already pulled in previous runs, so do not pull it again and read it from the cache. Yet we are stuck at this simple step. |
Beta Was this translation helpful? Give feedback.
-
Tag your base images with specific versions. Instead of relying on latest, use specific tags for your base images. This practice ensures that you know exactly which version of the image you're using and can more effectively determine whether a pull is necessary. And use a conditional step to check for image presence. Before the step where you'd typically pull your base image, add a step that checks if the specific version of the image is already present in the local Docker cache. If the image is present, you can skip the pull step.
In this setup, the check if base image exists step sets an output variable based on whether the specified version of your base image exists locally. The pull base image step then only runs if the image does not exist, as determined by the conditional if statement. |
Beta Was this translation helpful? Give feedback.
-
@h0vhann1syan, I appreciate your time. Thank you. The problem is that the conditional statement would always be false. Because each time we run our GitHub Action, we are given a new clean runner and that runner does not have our image. That's exactly the problem here. We have many APIs and many web interfaces and for each, we have a GitHub Action. And we build each of them a couple of times per day. If we want to get numeric, we have more than 50 actions, being run more than 200 times per day. And they are all dependent on our base image. This means that we need to pull them 200 times per day. Each time consumes 2GBs of bandwidth and wastes more than 1 minute of our build time. If we use |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Question
Body
This is a sample of my action YAML file:
As I see logs for actions, the
docker build
takes a lot of time, and a major part of it is because it downloads aFROM
image from the docker hub.The image name is
holism/api
. I want to cache this image but I'm stuck at how to cache it and how to load it in subsequent action runs.I can't find a good documentation for this and ChatGPT is not helping either. Can anybody please help me with this?
Beta Was this translation helpful? Give feedback.
All reactions