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

Using cache with build arg in FROM statement #637

Closed
bottleneko opened this issue Apr 1, 2019 · 17 comments
Closed

Using cache with build arg in FROM statement #637

bottleneko opened this issue Apr 1, 2019 · 17 comments
Assignees
Labels
area/caching For all bugs related to cache issues more-information-needed priority/p1 Basic need feature compatibility with docker build. we should be working on this next.

Comments

@bottleneko
Copy link

bottleneko commented Apr 1, 2019

Actual behavior
Kaniko rebuilds all layers with build arg used in from statement, but cache exists locally in in remote registry

Expected behavior
Kaniko rebuilds only changed layers

To Reproduce
Steps to reproduce the behavior:

  1. Run in kaniko build for first dockerfile
/kaniko/executor \
        --context "test1" \
        --dockerfile "text1/Dockerfile" \
        --destination "$CI_REGISTRY_IMAGE/test1:$CI_COMMIT_REF_NAME" \
        --cache=true
  1. Run in same container build for second dockerfile
/kaniko/executor \
        --context "test2" \
        --dockerfile "test2/Dockerfile" \
        --destination "$CI_REGISTRY_IMAGE/test2:$CI_COMMIT_REF_NAME" \
        --build-arg BASE_IMAGE="$CI_REGISTRY_IMAGE/test1:$CI_COMMIT_REF_NAME" \
        --cache=true

Additional Information

  • Dockerfile

test1/Dockerfile

FROM debian

RUN apt-get update && apt-get install -y build-essential

test2/Dockerfile

ARG BASE_IMAGE

FROM $BASE_IMAGE

RUN apt-get update && apt-get install -y emacs
  • Kaniko Image (fully qualified with digest)
Image: gcr.io/kaniko-project/executor:debug
Digest: sha256:62bc2acb47775f717cd5e81076e46f2c552d0ae958cd6d300d42ff73892c19da
@discordianfish
Copy link
Contributor

While debugging why caching isn't working for one of my images, I've just found out that apparently the build args are included in the cache key, so if any build arg is different from the cached build it won't be used.

@discordianfish
Copy link
Contributor

With debug logging enabled I get:

DEBU[0000] Key missing was: sha256:f2557f94cac1cc4509d0483cb6e302da841ecd6f82eb2e91dc7ba6cfd0c580ab-TAG=1b8e8b1f578b75b98193d4f

Where TAG is my build-arg.

@bottleneko
Copy link
Author

@discordianfish, thanks for your reply!

While build running, kaniko prints info messages about using cache or adding new layers and always prints these messages at the end.

INFO[0005] Adding / to layer, because it was changed.   
INFO[0005] Adding /var to layer, because it was changed. 
INFO[0005] Adding /etc to layer, because it was changed. 
INFO[0005] Adding /.dockerenv to layer, because it was changed. 

Seems these steps changing hash of final image, thus derived images builds again

@discordianfish
Copy link
Contributor

@bottleneko Yes, I think there are actually two issues:

  1. The build args are included in the base cache key:

    compositeKey.AddKey(s.opts.BuildArgs...)

    That will case it to never reuse layers that had a different build arg, which is the case with you using BASE_IMAGE build arg. I've just removed the line and it fixes this issue

  2. Unfortunately there is still something else causing the image to be different.

So while my fix works and causes kaniko to reuse cached layers when I build the same image multiple time with different build args, I can't use the resulting images in FROM without busting the cache for them.

@discordianfish
Copy link
Contributor

Okay I can confirm, it's simply that kaniko builds are simply not reproducable. Even without build args or anything. Building the same image twice (when using cache at least, but that should even make it easier), results in two different SHAs. And yeah, probably due to the side effects you mentioned that didn't get filtered out properly.

First run (not cached)

...
2019-04-03T12:55:11.137947703Z INFO[0027] Pushing layer xx.dkr.ecr.us-east-1.amazonaws.com/fish/kaniko-test/cache:44721af09bbd510af4b8fd5c6e8108bdb9e3f128faa931432ba0cc7610cfc880 to cache now
2019-04-03T12:55:11.74915181Z 2019/04/03 12:55:11 pushed blob: sha256:23913822d919774bcfc2c2bb244c9f5aeede49149bfa52246feff2e1b2c488aa
2019-04-03T12:55:24.634739067Z 2019/04/03 12:55:24 pushed blob: sha256:d9667b12a02e550aaaccbb91bc68aa33078e75ace347e8bb3d864dc5ce0e50ae
2019-04-03T12:55:24.734825892Z 2019/04/03 12:55:24 xx.dkr.ecr.us-east-1.amazonaws.com/fish/kaniko-test/cache:44721af09bbd510af4b8fd5c6e8108bdb9e3f128faa931432ba0cc7610cfc880: digest: sha256:514fa09672dcfc6044c109744659019bac48768096df75f9444bb9092939e16e size: 430
2019-04-03T12:55:24.774303117Z 2019/04/03 12:55:24 existing blob: sha256:e79bb959ec00faf01da52437df4fad4537ec669f60455a38ad583ec2b8f00498
2019-04-03T12:55:25.182797368Z 2019/04/03 12:55:25 pushed blob: sha256:3597dbf527a4d0aae500d71e81c998e6dad5d53eb5de6d96f2ae6daf7c65e79b
2019-04-03T12:55:40.580214934Z 2019/04/03 12:55:40 pushed blob: sha256:d9667b12a02e550aaaccbb91bc68aa33078e75ace347e8bb3d864dc5ce0e50ae
2019-04-03T12:55:40.684259557Z 2019/04/03 12:55:40 xx.dkr.ecr.us-east-1.amazonaws.com/fish/kaniko-test:latest: digest: sha256:fcdc9f2e1ac1b7fae73c472243ec79b180de67de5e0a24ff40c03d19e6b8b896 size: 595

Second run (cached)

2019-04-03T13:00:13.896638382Z INFO[0000] Resolved base name debian to debian
2019-04-03T13:00:13.896676793Z INFO[0000] Resolved base name debian to debian
2019-04-03T13:00:13.89668469Z INFO[0000] Downloading base image debian
2019-04-03T13:00:13.896911248Z 2019/04/03 13:00:13 No matching credentials were found, falling back on anonymous
2019-04-03T13:00:14.029257737Z INFO[0000] Error while retrieving image from cache: getting file info: stat /cache/sha256:9a1b6b1073bf12428a55c54e6e3bb001946afbcf49b7fea6a02d345790356998: no such file or directory
2019-04-03T13:00:14.02927428Z INFO[0000] Downloading base image debian
2019-04-03T13:00:14.029278165Z 2019/04/03 13:00:14 No matching credentials were found, falling back on anonymous
2019-04-03T13:00:14.239512362Z INFO[0000] Built cross stage deps: map[]
2019-04-03T13:00:14.239527766Z INFO[0000] Downloading base image debian
2019-04-03T13:00:14.239531834Z 2019/04/03 13:00:14 No matching credentials were found, falling back on anonymous
2019-04-03T13:00:14.338394566Z INFO[0000] Error while retrieving image from cache: getting file info: stat /cache/sha256:9a1b6b1073bf12428a55c54e6e3bb001946afbcf49b7fea6a02d345790356998: no such file or directory
2019-04-03T13:00:14.338408652Z INFO[0000] Downloading base image debian
2019-04-03T13:00:14.338454072Z 2019/04/03 13:00:14 No matching credentials were found, falling back on anonymous
2019-04-03T13:00:14.573789525Z INFO[0000] Checking for cached layer xx.dkr.ecr.us-east-1.amazonaws.com/fish/kaniko-test/cache:44721af09bbd510af4b8fd5c6e8108bdb9e3f128faa931432ba0cc7610cfc880...
2019-04-03T13:00:14.73097185Z INFO[0001] Using caching version of cmd: RUN apt-get update && apt-get install -y build-essential
2019-04-03T13:00:14.730992394Z INFO[0001] Skipping unpacking as no commands require it.
2019-04-03T13:00:14.731291877Z INFO[0001] Taking snapshot of full filesystem...
2019-04-03T13:00:14.750156483Z INFO[0001] Adding /root/.ecr/cache.json to layer, because it was changed.
2019-04-03T13:00:14.750219055Z INFO[0001] Adding /var to layer, because it was changed.
2019-04-03T13:00:14.750236432Z INFO[0001] Adding /etc to layer, because it was changed.
2019-04-03T13:00:14.75031379Z INFO[0001] Adding /.dockerenv to layer, because it was changed.
2019-04-03T13:00:14.750323205Z INFO[0001] Adding /workspace to layer, because it was changed.
2019-04-03T13:00:14.750415687Z INFO[0001] Adding / to layer, because it was changed.
2019-04-03T13:00:14.750446571Z INFO[0001] Adding /root to layer, because it was changed.
2019-04-03T13:00:14.75058078Z INFO[0001] Adding /root/.ecr to layer, because it was changed.
2019-04-03T13:00:14.750734277Z INFO[0001] RUN apt-get update && apt-get install -y build-essential
2019-04-03T13:00:14.750742543Z INFO[0001] Found cached layer, extracting to filesystem
2019-04-03T13:00:18.447106154Z INFO[0004] Taking snapshot of files...
2019-04-03T13:00:23.929975873Z 2019/04/03 13:00:23 existing blob: sha256:e79bb959ec00faf01da52437df4fad4537ec669f60455a38ad583ec2b8f00498
2019-04-03T13:00:24.257291537Z 2019/04/03 13:00:24 pushed blob: sha256:f7277e171fe1413582721e941b821c065b8579b1175d9f0bd30be96d369a162d
2019-04-03T13:00:37.256461987Z 2019/04/03 13:00:37 pushed blob: sha256:f3f8b0d82bf6364e8b9c63d6be30eb9051b26b66e7ee843183cb5ae3f5b5490a
2019-04-03T13:00:37.369490505Z 2019/04/03 13:00:37 xx.dkr.ecr.us-east-1.amazonaws.com/fish/kaniko-test:latest: digest: sha256:2c352c5a920484c4464c8f0817444d93921b3ba94bddf330a20b9a965ebad278 size: 595

@shanemcd
Copy link

I am seeing this as well. Even when the cache hits on every layer, I end up with a new image and SHA.

@oscarAmarello
Copy link

oscarAmarello commented Jul 4, 2019

I'm having the same issue with google cloud build

First run:

Step #1: Pulling image: gcr.io/kaniko-project/executor:latest
Step #1: latest: Pulling from kaniko-project/executor
Step #1: Digest: sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400
Step #1: Status: Downloaded newer image for gcr.io/kaniko-project/executor:latest
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:15 No matching credentials were found, falling back on anonymous
Step #1: INFO[0001] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0001] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:16 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Built cross stage deps: map[] 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:17 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:17 No matching credentials were found, falling back on anonymous
Step #1: INFO[0003] Checking for cached layer gcr.io/pruebas-internas/node-cidr-service/cache:791c9b1a43348a900b467d1b3f07998a9a530a7b766b7182220c57b2285c5850... 
Step #1: INFO[0003] Using caching version of cmd: RUN apk update && apk add nodejs yarn 
Step #1: INFO[0003] cmd: EXPOSE 
Step #1: INFO[0003] Adding exposed port: 3000/tcp 
Step #1: INFO[0003] Using files from context: [/workspace] 
Step #1: INFO[0004] Skipping unpacking as no commands require it. 
Step #1: INFO[0004] Taking snapshot of full filesystem... 
Step #1: INFO[0004] RUN apk update && apk add nodejs yarn 
Step #1: INFO[0004] Found cached layer, extracting to filesystem 
Step #1: INFO[0005] Taking snapshot of files... 
Step #1: INFO[0006] EXPOSE 3000 
Step #1: INFO[0006] cmd: EXPOSE 
Step #1: INFO[0006] Adding exposed port: 3000/tcp 
Step #1: INFO[0006] No files changed in this command, skipping snapshotting. 
Step #1: INFO[0006] Using files from context: [/workspace] 
Step #1: INFO[0006] COPY . . 
Step #1: INFO[0008] Taking snapshot of files... 
Step #1: INFO[0011] CMD ["yarn","start"] 
Step #1: INFO[0011] No files changed in this command, skipping snapshotting. 
Step #1: 2019/07/04 01:32:26 existing blob: sha256:921b31ab772b38172fd9f942a40fae6db24decbd6706f67836260d47a72baab5
Step #1: 2019/07/04 01:32:28 pushed blob: sha256:32766be702dc21a5cdbcca8f5ee932ebf48eec6543183a2d10ee2e4633e1b39c
Step #1: 2019/07/04 01:32:30 pushed blob: sha256:4735f63259b0c9a61515fe53726829780452005177e7a3a3aea59f44ed7c1823
Step #1: 2019/07/04 01:32:31 pushed blob: sha256:efe4a9114c3719d99d6fcaa833f748f051762183c962c7b8f88f33719b94ad0d
Step #1: 2019/07/04 01:32:32 gcr.io/pruebas-internas/node-cidr-service:1.0: digest: sha256:4ac8c69591198acd60d84f7d14706b648236b7ecdb81282771bd4b2bc13c36ad size: 758
Finished Step #1

Seccond run:

Step #1: Pulling image: gcr.io/kaniko-project/executor:latest
Step #1: latest: Pulling from kaniko-project/executor
Step #1: Digest: sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400
Step #1: Status: Downloaded newer image for gcr.io/kaniko-project/executor:latest
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:54 No matching credentials were found, falling back on anonymous
Step #1: INFO[0001] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0001] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:55 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Built cross stage deps: map[] 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:55 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:56 No matching credentials were found, falling back on anonymous
Step #1: INFO[0003] Checking for cached layer gcr.io/pruebas-internas/node-cidr-service/cache:791c9b1a43348a900b467d1b3f07998a9a530a7b766b7182220c57b2285c5850... 
Step #1: INFO[0003] Using caching version of cmd: RUN apk update && apk add nodejs yarn 
Step #1: INFO[0003] cmd: EXPOSE 
Step #1: INFO[0003] Adding exposed port: 3000/tcp 
Step #1: INFO[0003] Using files from context: [/workspace] 
Step #1: INFO[0004] Skipping unpacking as no commands require it. 
Step #1: INFO[0004] Taking snapshot of full filesystem... 
Step #1: INFO[0004] RUN apk update && apk add nodejs yarn 
Step #1: INFO[0004] Found cached layer, extracting to filesystem 
Step #1: INFO[0005] Taking snapshot of files... 
Step #1: INFO[0006] EXPOSE 3000 
Step #1: INFO[0006] cmd: EXPOSE 
Step #1: INFO[0006] Adding exposed port: 3000/tcp 
Step #1: INFO[0006] No files changed in this command, skipping snapshotting. 
Step #1: INFO[0006] Using files from context: [/workspace] 
Step #1: INFO[0006] COPY . . 
Step #1: INFO[0008] Taking snapshot of files... 
Step #1: INFO[0010] CMD ["yarn","start"] 
Step #1: INFO[0010] No files changed in this command, skipping snapshotting. 
Step #1: 2019/07/04 01:35:04 existing blob: sha256:921b31ab772b38172fd9f942a40fae6db24decbd6706f67836260d47a72baab5
Step #1: 2019/07/04 01:35:06 pushed blob: sha256:6869a159ed33a82805d25d8322914cef91a93f0a37571a24663faa6cfaac7864
Step #1: 2019/07/04 01:35:09 pushed blob: sha256:4ebe3598f3ce2d06d1633d4d1e7bd62f96e489bd2a9cf379abd3f3a02b8099b7
Step #1: 2019/07/04 01:35:09 pushed blob: sha256:5e152f83cb4e3845a33369d043216e8b2208e42125c25718c6fa64d0b8a8928e
Step #1: 2019/07/04 01:35:10 gcr.io/pruebas-internas/node-cidr-service:1.0: digest: sha256:eb5854a63d9dbd16ece26e65f8314c2a47dfdd90e73c0817569c5eb4c8930973 size: 758
Finished Step #1

@oscarAmarello
Copy link

I'm having the same issue with google cloud build

First run:

Step #1: Pulling image: gcr.io/kaniko-project/executor:latest
Step #1: latest: Pulling from kaniko-project/executor
Step #1: Digest: sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400
Step #1: Status: Downloaded newer image for gcr.io/kaniko-project/executor:latest
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:15 No matching credentials were found, falling back on anonymous
Step #1: INFO[0001] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0001] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:16 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Built cross stage deps: map[] 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:17 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:32:17 No matching credentials were found, falling back on anonymous
Step #1: INFO[0003] Checking for cached layer gcr.io/pruebas-internas/node-cidr-service/cache:791c9b1a43348a900b467d1b3f07998a9a530a7b766b7182220c57b2285c5850... 
Step #1: INFO[0003] Using caching version of cmd: RUN apk update && apk add nodejs yarn 
Step #1: INFO[0003] cmd: EXPOSE 
Step #1: INFO[0003] Adding exposed port: 3000/tcp 
Step #1: INFO[0003] Using files from context: [/workspace] 
Step #1: INFO[0004] Skipping unpacking as no commands require it. 
Step #1: INFO[0004] Taking snapshot of full filesystem... 
Step #1: INFO[0004] RUN apk update && apk add nodejs yarn 
Step #1: INFO[0004] Found cached layer, extracting to filesystem 
Step #1: INFO[0005] Taking snapshot of files... 
Step #1: INFO[0006] EXPOSE 3000 
Step #1: INFO[0006] cmd: EXPOSE 
Step #1: INFO[0006] Adding exposed port: 3000/tcp 
Step #1: INFO[0006] No files changed in this command, skipping snapshotting. 
Step #1: INFO[0006] Using files from context: [/workspace] 
Step #1: INFO[0006] COPY . . 
Step #1: INFO[0008] Taking snapshot of files... 
Step #1: INFO[0011] CMD ["yarn","start"] 
Step #1: INFO[0011] No files changed in this command, skipping snapshotting. 
Step #1: 2019/07/04 01:32:26 existing blob: sha256:921b31ab772b38172fd9f942a40fae6db24decbd6706f67836260d47a72baab5
Step #1: 2019/07/04 01:32:28 pushed blob: sha256:32766be702dc21a5cdbcca8f5ee932ebf48eec6543183a2d10ee2e4633e1b39c
Step #1: 2019/07/04 01:32:30 pushed blob: sha256:4735f63259b0c9a61515fe53726829780452005177e7a3a3aea59f44ed7c1823
Step #1: 2019/07/04 01:32:31 pushed blob: sha256:efe4a9114c3719d99d6fcaa833f748f051762183c962c7b8f88f33719b94ad0d
Step #1: 2019/07/04 01:32:32 gcr.io/pruebas-internas/node-cidr-service:1.0: digest: sha256:4ac8c69591198acd60d84f7d14706b648236b7ecdb81282771bd4b2bc13c36ad size: 758
Finished Step #1

Seccond run:

Step #1: Pulling image: gcr.io/kaniko-project/executor:latest
Step #1: latest: Pulling from kaniko-project/executor
Step #1: Digest: sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400
Step #1: Status: Downloaded newer image for gcr.io/kaniko-project/executor:latest
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Resolved base name alpine:latest to alpine:latest 
Step #1: INFO[0000] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:54 No matching credentials were found, falling back on anonymous
Step #1: INFO[0001] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0001] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:55 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Built cross stage deps: map[] 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:55 No matching credentials were found, falling back on anonymous
Step #1: INFO[0002] Error while retrieving image from cache: getting file info: stat /cache/sha256:97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a: no such file or directory 
Step #1: INFO[0002] Downloading base image alpine:latest 
Step #1: 2019/07/04 01:34:56 No matching credentials were found, falling back on anonymous
Step #1: INFO[0003] Checking for cached layer gcr.io/pruebas-internas/node-cidr-service/cache:791c9b1a43348a900b467d1b3f07998a9a530a7b766b7182220c57b2285c5850... 
Step #1: INFO[0003] Using caching version of cmd: RUN apk update && apk add nodejs yarn 
Step #1: INFO[0003] cmd: EXPOSE 
Step #1: INFO[0003] Adding exposed port: 3000/tcp 
Step #1: INFO[0003] Using files from context: [/workspace] 
Step #1: INFO[0004] Skipping unpacking as no commands require it. 
Step #1: INFO[0004] Taking snapshot of full filesystem... 
Step #1: INFO[0004] RUN apk update && apk add nodejs yarn 
Step #1: INFO[0004] Found cached layer, extracting to filesystem 
Step #1: INFO[0005] Taking snapshot of files... 
Step #1: INFO[0006] EXPOSE 3000 
Step #1: INFO[0006] cmd: EXPOSE 
Step #1: INFO[0006] Adding exposed port: 3000/tcp 
Step #1: INFO[0006] No files changed in this command, skipping snapshotting. 
Step #1: INFO[0006] Using files from context: [/workspace] 
Step #1: INFO[0006] COPY . . 
Step #1: INFO[0008] Taking snapshot of files... 
Step #1: INFO[0010] CMD ["yarn","start"] 
Step #1: INFO[0010] No files changed in this command, skipping snapshotting. 
Step #1: 2019/07/04 01:35:04 existing blob: sha256:921b31ab772b38172fd9f942a40fae6db24decbd6706f67836260d47a72baab5
Step #1: 2019/07/04 01:35:06 pushed blob: sha256:6869a159ed33a82805d25d8322914cef91a93f0a37571a24663faa6cfaac7864
Step #1: 2019/07/04 01:35:09 pushed blob: sha256:4ebe3598f3ce2d06d1633d4d1e7bd62f96e489bd2a9cf379abd3f3a02b8099b7
Step #1: 2019/07/04 01:35:09 pushed blob: sha256:5e152f83cb4e3845a33369d043216e8b2208e42125c25718c6fa64d0b8a8928e
Step #1: 2019/07/04 01:35:10 gcr.io/pruebas-internas/node-cidr-service:1.0: digest: sha256:eb5854a63d9dbd16ece26e65f8314c2a47dfdd90e73c0817569c5eb4c8930973 size: 758
Finished Step #1

Nevermind...it works

@mamoit
Copy link

mamoit commented Jul 5, 2019

@oscarAmarello what did you change to make it work?

@oscarAmarello
Copy link

oscarAmarello commented Jul 5, 2019

@oscarAmarello what did you change to make it work?

I had an error on my cloudbuild config file

@priyawadhwa priyawadhwa added the area/caching For all bugs related to cache issues label Jul 25, 2019
@silencej
Copy link

Same here

INFO[0000] Resolved base name node:12.10.0-alpine to node:12.10.0-alpine 
INFO[0000] Resolved base name nginx:1.17.3-alpine to nginx:1.17.3-alpine 
INFO[0000] Resolved base name node:12.10.0-alpine to node:12.10.0-alpine 
INFO[0000] Resolved base name nginx:1.17.3-alpine to nginx:1.17.3-alpine 
INFO[0000] Downloading base image node:12.10.0-alpine   
INFO[0004] Error while retrieving image from cache: getting file info: stat /cache/sha256:7a1789ae7b16137af96748012c6175c0561709f830de29922b7355509f4f9175: no such file or directory 
INFO[0004] Downloading base image node:12.10.0-alpine   
INFO[0006] Downloading base image nginx:1.17.3-alpine   
INFO[0008] Error while retrieving image from cache: getting file info: stat /cache/sha256:1907fa667b160c40dcc7f99d884f4b12cf49e487408a869857e75e64838fc9b6: no such file or directory 
INFO[0008] Downloading base image nginx:1.17.3-alpine   
INFO[0010] Built cross stage deps: map[0:[/build/]]     
INFO[0010] Downloading base image node:12.10.0-alpine   
INFO[0012] Error while retrieving image from cache: getting file info: stat /cache/sha256:7a1789ae7b16137af96748012c6175c0561709f830de29922b7355509f4f9175: no such file or directory 
INFO[0012] Downloading base image node:12.10.0-alpine

And the Dockerfile is

# Use specific version to be cache-friendly
FROM node:12.10.0-alpine AS cache
WORKDIR /build/
COPY ./yarn.lock ./package.json /build/

RUN yarn

COPY . .
RUN yarn run build

FROM nginx:1.17.3-alpine
WORKDIR /usr/share/nginx/html/
COPY --from=cache /build/ /usr/share/nginx/html/
EXPOSE 80

@ghost
Copy link

ghost commented Nov 16, 2019

yes. I get a lot of this errors for the cache. I don't have ARG. use kaniko-project/executor:v0.12.0

@kvaps
Copy link
Contributor

kvaps commented Nov 17, 2019

I have the same issue when using docker staging build, eg.:

ARG/ENV and command on single stage, cache is working:

# single stage
FROM alpine:3.10
RUN apk add --no-cache wget
ARG QBEC_VER=0.7.5
RUN wget -O- https://github.com/splunk/qbec/releases/download/v${QBEC_VER}/qbec-linux-amd64.tar.gz \
     | tar -C /usr/local/bin -xzf -

ARG/ENV and command on second stage, cache is not working:

# first stage
FROM alpine:3.10 as builder
RUN apk add --no-cache wget

# second stage
FROM builder
ARG QBEC_VER=0.7.5
RUN wget -O- https://github.com/splunk/qbec/releases/download/v${QBEC_VER}/qbec-linux-amd64.tar.gz \
     | tar -C /usr/local/bin -xzf -

ENV on first stage, command on second stage, cache is not working:

# first stage
FROM alpine:3.10 as builder
RUN apk add --no-cache wget
ENV QBEC_VER=0.7.5

# second stage
FROM builder
RUN wget -O- https://github.com/splunk/qbec/releases/download/v${QBEC_VER}/qbec-linux-amd64.tar.gz \
     | tar -C /usr/local/bin -xzf -
Kaniko version :  v0.14.0

@cvgw cvgw self-assigned this Nov 28, 2019
@trongchata
Copy link

Have took a quick look at kaniko code, seems it use context, command args, files, and Dockerfile command to generate the HashValue for each image layer.
In this case, you change the context name, and Dockerfile, so the hashValue will be different.

@cvgw
Copy link
Contributor

cvgw commented Dec 20, 2019

I'd like to get some clarity on this issue as a number of things have changed in Kaniko and it sounds like there are a couple of things at play here.

Some bugs in caching have been fixed so getting consistent cache keys is no longer a problem in v 0.15.0

Digests of layers and images built by kaniko are not reproducible (unless the --reproducible flag is used); that is working as designed

Kaniko includes build args in the cache key (as mentioned earlier in this thread). It seems to me that this is the desired behavior, but I may be missing some use cases.

Can someone share an example of when you would change a build arg but still want the build to be cached?

OR

Perhaps I'm misunderstanding this issue. It could be that layers which are unaffected by the change in build args should remain cached and are currently not.

@kvaps
Copy link
Contributor

kvaps commented Dec 21, 2019

Hi @cvgw,
I've just tested my cases from #637 (comment) with new kaniko v0.15.0, all of them are working fine.
So problem solved I guess. Thank you!

@tejal29
Copy link
Member

tejal29 commented Jan 10, 2020

Thanks @kvaps for confirming. i am going to close this issue now.

@tejal29 tejal29 closed this as completed Jan 10, 2020
@tejal29 tejal29 added this to the GA Release v1.0.0 milestone Jan 10, 2020
@tejal29 tejal29 added the priority/p1 Basic need feature compatibility with docker build. we should be working on this next. label Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/caching For all bugs related to cache issues more-information-needed priority/p1 Basic need feature compatibility with docker build. we should be working on this next.
Projects
None yet
Development

No branches or pull requests