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

FIX: missing or partial support for pattern substition in variable when cache enabled #2968

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ func (s *stageBuilder) populateCompositeKey(command commands.DockerCommand, file
// The sort order of `replacementEnvs` is basically undefined, sort it
// so we can ensure a stable cache key.
sort.Strings(replacementEnvs)
resolvedCmd, err := util.ResolveEnvironmentReplacement(command.String(), replacementEnvs, false)
if err != nil {
return compositeKey, err
}
// Use the special argument "|#" at the start of the args array. This will
// avoid conflicts with any RUN command since commands can not
// start with | (vertical bar). The "#" (number of build envs) is there to
Expand All @@ -221,7 +217,7 @@ func (s *stageBuilder) populateCompositeKey(command commands.DockerCommand, file
}

// Add the next command to the cache key.
compositeKey.AddKey(resolvedCmd)
compositeKey.AddKey(command.String())

for _, f := range files {
if err := compositeKey.AddPath(f, s.fileContext); err != nil {
Expand Down
32 changes: 30 additions & 2 deletions pkg/executor/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,34 @@ func Test_stageBuilder_populateCompositeKey(t *testing.T) {
[]string{"ENV=1"},
),
},
{
description: "cache key for command [RUN] with same env values [check that variable no interpolate in RUN command]",
cmd1: newStageContext(
"RUN echo $ENV > test",
map[string]string{"ARG": "foo"},
[]string{"ENV=1"},
),
cmd2: newStageContext(
"RUN echo 1 > test",
map[string]string{"ARG": "foo"},
[]string{"ENV=1"},
),
shdEqual: false,
},
{
description: "cache key for command [RUN] with different env values [check that variable no interpolate in RUN command]",
cmd1: newStageContext(
"RUN echo ${APP_VERSION%.*} ${APP_VERSION%-*} > test",
map[string]string{"ARG": "foo"},
[]string{"ENV=1"},
),
cmd2: newStageContext(
"RUN echo ${APP_VERSION%.*} ${APP_VERSION%-*} > test",
map[string]string{"ARG": "foo"},
[]string{"ENV=2"},
),
shdEqual: false,
},
func() testcase {
dir, files := tempDirAndFile(t)
file := files[0]
Expand Down Expand Up @@ -1331,7 +1359,7 @@ RUN foobar
ch := NewCompositeCache("")
ch.AddKey("|1")
ch.AddKey("arg=value")
ch.AddKey("RUN value")
ch.AddKey("RUN $arg")
hash, err := ch.Hash()
if err != nil {
t.Errorf("couldn't create hash %v", err)
Expand Down Expand Up @@ -1376,7 +1404,7 @@ RUN foobar
ch2 := NewCompositeCache("")
ch2.AddKey("|1")
ch2.AddKey("arg=anotherValue")
ch2.AddKey("RUN anotherValue")
ch2.AddKey("RUN $arg")
hash2, err := ch2.Hash()
if err != nil {
t.Errorf("couldn't create hash %v", err)
Expand Down
Loading