ARG/ENV does not invalidate build cache
Actual behavior ARG/ENV does not invalidate build cache
Expected behavior When building an image with different args/env vars expected behavior is to not reuse the caching layer from the previous build with different args/env vars.
To Reproduce Steps to reproduce the behavior:
-
Create Dockerfile with content FROM node:9.5.0-alpine as build ARG RUNTIME_ENV ENV RUNTIME_ENV $RUNTIME_ENV RUN printenv > /printenv.results
-
Build image first time with arg/env var RUNTIME_ENV=production containers:
- name: test-first-2 image: gcr.io/kaniko-project/executor:v0.10.0 args: ["--context=s3://s3location/context.tar.gz", "--destination=ecr/first", "--build-arg", "RUNTIME_ENV=production", "--cache"]
-
Build image second time with arg/env var RUNTIME_ENV=staging containers:
- name: test-first-2 image: gcr.io/kaniko-project/executor:v0.10.0 args: ["--context=s3://s3location/context.tar.gz", "--destination=ecr/second", "--build-arg", "RUNTIME_ENV=staging", "--cache"]
-
Run docker container to output save environment variables docker run ecr/second cat /printenv.results
Expected RUNTIME_ENV=staging, got RUNTIME_ENV=production
Additional Information
- Dockerfile
FROM node:9.5.0-alpine as build ARG RUNTIME_ENV ENV RUNTIME_ENV $RUNTIME_ENV RUN printenv > /printenv.results
- Build Context
Dockerfile only
- Kaniko Image (fully qualified with digest) gcr.io/kaniko-project/executor:v0.10.0 sha256:78d44ec4e9cb5545d7f85c1924695c89503ded86a59f92c7ae658afa3cff5400
First run logs (removed dates):
Resolved base name node:9.5.0-alpine to node:9.5.0-alpine
Resolved base name node:9.5.0-alpine to node:9.5.0-alpine
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Error while retrieving image from cache: getting file info: stat /cache/sha256:cb81f746508956c83961e0b4c8f849c7a11ded06aa08722587fa5b720c50fbb8: no such file or directory
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Built cross stage deps: map[]
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Error while retrieving image from cache: getting file info: stat /cache/sha256:cb81f746508956c83961e0b4c8f849c7a11ded06aa08722587fa5b720c50fbb8: no such file or directory
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Executing 0 build triggers
Checking for cached layer ecr-cache:848b4b90d8647bf22668fe7d9a6da8129476f3cbfc39b0bff04e324ad8d752ec...
No cached layer found for cmd RUN printenv > /printenv.results
Unpacking rootfs as cmd RUN printenv > /printenv.results requires it.
Taking snapshot of full filesystem...
ARG RUNTIME_ENV
No files changed in this command, skipping snapshotting.
ENV RUNTIME_ENV $RUNTIME_ENV
No files changed in this command, skipping snapshotting.
RUN printenv > /printenv.results
cmd: /bin/sh
args: [-c printenv > /printenv.results]
Taking snapshot of full filesystem...
Pushing layer ecr-cache:848b4b90d8647bf22668fe7d9a6da8129476f3cbfc39b0bff04e324ad8d752ec to cache now
2019/07/29 09:25:30 pushed blob: sha256:28cbf58eab524da091828467dee7296c928ee1867b454ee7b6a4da5e481eb630
2019/07/29 09:25:30 pushed blob: sha256:b60a1abeb61aa211a9a1d1fca7a8925c7ee826bea43203f82d6e2d13760d8207
2019/07/29 09:25:30 ecr-cache:848b4b90d8647bf22668fe7d9a6da8129476f3cbfc39b0bff04e324ad8d752ec: digest: sha256:68f75ac6b2b2b3d9a05f6aae7148db478acd0b00b4ef3b77e088e3b895cd8398 size: 424
2019/07/29 09:25:30 existing blob: sha256:5c0ee846ddbc2700cb056145baa950f6174998b76acadefeda52c0f03861522c
2019/07/29 09:25:30 existing blob: sha256:4273d98615930d1f4ba4dd36a45379e87ad3580335b5d737be9c204f07026121
2019/07/29 09:25:30 existing blob: sha256:605ce1bd3f3164f2949a30501cc596f52a72de05da1306ab360055f0d7130c32
2019/07/29 09:25:30 pushed blob: sha256:08e4a3116f8f6b06e4b3c8fc7a9a7d441afa703854c75a3e4938ed6b70eab821
2019/07/29 09:25:32 pushed blob: sha256:28cbf58eab524da091828467dee7296c928ee1867b454ee7b6a4da5e481eb630
2019/07/29 09:25:32 ecr: digest: sha256:751eba066b28e20ce6214e92be6e808e233ff192874302f183b3a2e54cbed449 size: 917
Second run logs (removed dates):
Resolved base name node:9.5.0-alpine to node:9.5.0-alpine
Resolved base name node:9.5.0-alpine to node:9.5.0-alpine
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Error while retrieving image from cache: getting file info: stat /cache/sha256:cb81f746508956c83961e0b4c8f849c7a11ded06aa08722587fa5b720c50fbb8: no such file or directory
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Built cross stage deps: map[]
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Error while retrieving image from cache: getting file info: stat /cache/sha256:cb81f746508956c83961e0b4c8f849c7a11ded06aa08722587fa5b720c50fbb8: no such file or directory
Downloading base image node:9.5.0-alpine
matching credentials were found, falling back on anonymous
Executing 0 build triggers
Checking for cached layer ecr-cache:848b4b90d8647bf22668fe7d9a6da8129476f3cbfc39b0bff04e324ad8d752ec...
Using caching version of cmd: RUN printenv > /printenv.results
Skipping unpacking as no commands require it.
Taking snapshot of full filesystem...
ARG RUNTIME_ENV
No files changed in this command, skipping snapshotting.
ENV RUNTIME_ENV $RUNTIME_ENV
No files changed in this command, skipping snapshotting.
RUN printenv > /printenv.results
Found cached layer, extracting to filesystem
Taking snapshot of files...
2019/07/29 09:26:28 existing blob: sha256:5c0ee846ddbc2700cb056145baa950f6174998b76acadefeda52c0f03861522c
2019/07/29 09:26:28 existing blob: sha256:605ce1bd3f3164f2949a30501cc596f52a72de05da1306ab360055f0d7130c32
2019/07/29 09:26:28 existing blob: sha256:4273d98615930d1f4ba4dd36a45379e87ad3580335b5d737be9c204f07026121
2019/07/29 09:26:29 pushed blob: sha256:c16efa667e0c7ebe8ca01d5493188a7147f31fe923426fd852a3e6944f726df6
2019/07/29 09:26:29 pushed blob: sha256:1cbf0d7570951920e7f5ecd2e9a4f7b00f22db9ccd183ed94f9dac142f3b26f5
2019/07/29 09:26:29 ecr:test-second-2: digest: sha256:3371f959e1c84f27f7cf925dbb0d5c73ec521f02a81b35e7c298e251386f8791 size: 917