diff --git a/README.md b/README.md index 5b3b18867..daa64d8a7 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ expect - see [Known Issues](#known-issues). - [Flag `FF_KANIKO_SECUREJOIN_EXTRACTION`](#flag-ff_kaniko_securejoin_extraction) - [Flag `FF_KANIKO_RESOLVE_CACHE_KEY`](#flag-ff_kaniko_resolve_cache_key) - [Flag `FF_KANIKO_UNTAR_SKIP_ROOT`](#flag-ff_kaniko_untar_skip_root) + - [Flag `FF_KANIKO_EXPAND_HEREDOC`](#flag-ff_kaniko_expand_heredoc) - [Assertion Overrides](#assertion-overrides) - [Debug Image](#debug-image) - [Security](#security) @@ -1305,6 +1306,13 @@ Set this flag to `true` to skip the root `.` entry when untarring. Defaults to `false`. Becomes default in `v1.29.0`. +#### Flag `FF_KANIKO_EXPAND_HEREDOC` + +Docker applies Dockerfile word-expansion to a `COPY` or `ADD` heredoc body when the delimiter is unquoted, so `${VAR}` expands and `\${VAR}` keeps the literal text. A quoted delimiter (`<<'EOF'`) leaves the body verbatim. kaniko writes the body verbatim in every case, so the expanded files diverge from Docker. +Set this flag to `true` to expand build args and env in unquoted `COPY` and `ADD` heredoc bodies. +Defaults to `false`. +Becomes default in `v1.29.0`. + ### Assertion Overrides Kaniko checks internal invariants at runtime. If one is violated the build stops with a message like: diff --git a/golden/golden_test.go b/golden/golden_test.go index 01dbb78a6..79e2cd35d 100644 --- a/golden/golden_test.go +++ b/golden/golden_test.go @@ -41,6 +41,7 @@ import ( testissuemz703 "github.com/osscontainertools/kaniko/golden/testdata/test_issue_mz703" testissuemz791 "github.com/osscontainertools/kaniko/golden/testdata/test_issue_mz791" testissuemz813 "github.com/osscontainertools/kaniko/golden/testdata/test_issue_mz813" + testissuemz822 "github.com/osscontainertools/kaniko/golden/testdata/test_issue_mz822" testunittests "github.com/osscontainertools/kaniko/golden/testdata/test_unittests" "github.com/osscontainertools/kaniko/golden/types" "github.com/osscontainertools/kaniko/pkg/cache" @@ -96,6 +97,7 @@ var allTests = map[string][]types.GoldenTests{ "test_issue_mz703": {testissuemz703.Tests}, "test_issue_mz791": {testissuemz791.Tests}, "test_issue_mz813": {testissuemz813.Tests}, + "test_issue_mz822": {testissuemz822.Tests}, "test_unittests": testunittests.Tests, } var update bool diff --git a/golden/testdata/test_issue_mz822/Dockerfile b/golden/testdata/test_issue_mz822/Dockerfile new file mode 100644 index 000000000..eee11c1fe --- /dev/null +++ b/golden/testdata/test_issue_mz822/Dockerfile @@ -0,0 +1,10 @@ +# mz822: a COPY heredoc whose body expands a build arg is not reflected in the +# layer cache key. The body is omitted from the instruction text the key is built +# from, so a build that only changes the arg reuses the layer cached for a +# different resolved content and serves a stale file. Same defect as mz791 for +# COPY/ADD paths and mz813 for WORKDIR. +FROM busybox@sha256:fd8d9aa63ba2f0982b5304e1ee8d3b90a210bc1ffb5314d980eb6962f1a9715d +ARG A +COPY <