publish-docker-action icon indicating copy to clipboard operation
publish-docker-action copied to clipboard

Cache is not really used

Open JanMikes opened this issue 5 years ago • 2 comments

Hi!

Compare these 2 jobs:

Notice the difference:

Step 1/3 : FROM hello-world:linux
linux: Pulling from library/hello-world
0e03bdcc26d7: Pulling fs layer
0e03bdcc26d7: Verifying Checksum
0e03bdcc26d7: Download complete
0e03bdcc26d7: Pull complete
Digest: sha256:d073a5775c0b99d653c413161a8ed0e9685061afe697931d30eddf6afeef40f6
Status: Downloaded newer image for hello-world:linux
 ---> bf756fb1ae65
Step 2/3 : ENV hello=world
 ---> Running in db0fc4355854
Removing intermediate container db0fc4355854
 ---> 0430147d2bd7
Step 3/3 : ENV world=hello
 ---> Running in b742be361e05
Removing intermediate container b742be361e05
 ---> 823a4ea0983b
Successfully built 823a4ea0983b

vs my own code which actually uses cache

Step 1/3 : FROM hello-world:linux
linux: Pulling from library/hello-world
0e03bdcc26d7: Already exists
Digest: sha256:d073a5775c0b99d653c413161a8ed0e9685061afe697931d30eddf6afeef40f6
Status: Downloaded newer image for hello-world:linux
 ---> bf756fb1ae65
Step 2/3 : ENV hello=world
 ---> Using cache
 ---> 5ea1c2e029fd
Step 3/3 : ENV world=hello
 ---> Using cache
 ---> 7225a4358ba0
Successfully built 7225a4358ba0
Successfully tagged image:latest

Pulling image before using --cache-from does the trick:

docker pull lexinek/hello-world || true
docker build . --tag image --cache-from lexinek/hello-world

Because the --cache-from has no effect if the image does not exist and since it runs in CI environment, the image is not pulled there 😉

JanMikes avatar Jan 20 '20 22:01 JanMikes

I guess it may be useful on self-hosted runners.

jerray avatar Mar 05 '20 07:03 jerray

I guess it may be useful on self-hosted runners.

Sorry, i do not understand the comment.

The cache can work for github runners too, but to make cache work the image has to be pulled first, check my code sample in 1st comment.

JanMikes avatar Mar 10 '20 20:03 JanMikes