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

Cache is not really used #6

Open
JanMikes opened this issue Jan 20, 2020 · 2 comments
Open

Cache is not really used #6

JanMikes opened this issue Jan 20, 2020 · 2 comments

Comments

@JanMikes
Copy link

JanMikes commented Jan 20, 2020

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 😉

@jerray
Copy link
Owner

jerray commented Mar 5, 2020

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

@JanMikes
Copy link
Author

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.

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

2 participants