ScribeMD / docker-cache

Cache Docker Images Whether Built or Pulled
MIT License
98 stars 27 forks source link

Is it possible to cache the image locally built? #817

Closed yegor256 closed 6 months ago

yegor256 commented 6 months ago

I'm doing this:

jobs:
  make:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@master
      - uses: ScribeMD/docker-cache@0.5.0
        with:
          key: docker-${{ runner.os }}-${{ hashFiles('Dockerfile') }}
      - run: docker build . -t cam
      - run: docker run --rm cam make test

I intend to build the image only once, unless the Dockerfile is changed. However, this approach doesn't work: the docker build starts from scratch, even though your plugin finishes with this:

...
docker load --input ~/.docker-images.tar
Loaded image: cam:latest

Full log is here: https://github.com/yegor256/cam/actions/runs/8498131819/job/23277521845

yegor256 commented 6 months ago

@Kurt-von-Laven please, help

Kurt-von-Laven commented 6 months ago

You could add a condition on your docker build step so that it only runs if there was a cache hit, but I bet you will get better performance using the approach recommended in our README:

Note that this action does not perform Docker layer caching. The official Docker build push action performs Docker layer caching for built images but does not cache pulled images.

Please let me know if neither approach solves your problem.

yegor256 commented 6 months ago

@Kurt-von-Laven maybe you know how exactly I can do this?

You could add a condition on your docker build step