Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use my "gha" Docker cache to speed up Docker pull, as well as Docker build on Github Actions?

On Github Actions, I'd like to avoid having to pull my newly built Docker image from the registry when I have it in a cache (and this is the slowest part of my jobs)

My workflow is something like

  1. Build an image (with all my dependencies baked in)
  2. Run a command within the above image

As per the Docker Build Push Action docs, setting up the cache-to and cache-from to point to gha has helped speed up step 1 a lot.

However, when I run docker run ghcr.io/org/image:new-tag command, it always starts with

Unable to find image 'ghcr.io/org/image:new-tag' locally
new-tag: Pulling from org/image
...
5402d6c1eb0a: Pulling fs layer
...

which takes around a 50 seconds (of around a total job time of ~75 seconds).

This seems unnecessary when there's a cache sat within reach that contains this information, however I don't know how to tell my docker run command how to make use of this cache as, as far as I can see, there's no --cache-from=gha equivalent option for docker run.

How can I tell docker to look in the gha cache for an image when I call docker run on Github Actions?

like image 326
Joshua Avatar asked Oct 23 '21 11:10

Joshua


1 Answers

We faced similar situation some time back but we recently found a github-actions which actually helps in caching the docker-layers & images b/w subsequent runs.

I am sure that your problem can also be solved with it. Here is the link to the gh-action https://github.com/satackey/action-docker-layer-caching.

Configuration Example You can add the following lines above the docker run step to ensure caching to be done in gha

    - uses: satackey/[email protected]
      continue-on-error: true
like image 155
Kush Trivedi Avatar answered Sep 28 '22 06:09

Kush Trivedi