* Restore build args after optimize. Fixes #1910, #1912. * Apply review suggestions.
This commit is contained in:
parent
0adbbee21d
commit
ef97636546
|
|
@ -51,8 +51,11 @@ func (b *BuildArgs) Clone() *BuildArgs {
|
||||||
|
|
||||||
// ReplacementEnvs returns a list of filtered environment variables
|
// ReplacementEnvs returns a list of filtered environment variables
|
||||||
func (b *BuildArgs) ReplacementEnvs(envs []string) []string {
|
func (b *BuildArgs) ReplacementEnvs(envs []string) []string {
|
||||||
|
// Ensure that we operate on a new array and do not modify the underlying array
|
||||||
|
resultEnv := make([]string, len(envs))
|
||||||
|
copy(resultEnv, envs)
|
||||||
filtered := b.FilterAllowed(envs)
|
filtered := b.FilterAllowed(envs)
|
||||||
return append(envs, filtered...)
|
return append(resultEnv, filtered...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMetaArgs adds the supplied args map to b's allowedMetaArgs
|
// AddMetaArgs adds the supplied args map to b's allowedMetaArgs
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -181,6 +182,9 @@ func initConfig(img partial.WithConfigFile, opts *config.KanikoOptions) (*v1.Con
|
||||||
func (s *stageBuilder) populateCompositeKey(command fmt.Stringer, files []string, compositeKey CompositeCache, args *dockerfile.BuildArgs, env []string) (CompositeCache, error) {
|
func (s *stageBuilder) populateCompositeKey(command fmt.Stringer, files []string, compositeKey CompositeCache, args *dockerfile.BuildArgs, env []string) (CompositeCache, error) {
|
||||||
// First replace all the environment variables or args in the command
|
// First replace all the environment variables or args in the command
|
||||||
replacementEnvs := args.ReplacementEnvs(env)
|
replacementEnvs := args.ReplacementEnvs(env)
|
||||||
|
// 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)
|
resolvedCmd, err := util.ResolveEnvironmentReplacement(command.String(), replacementEnvs, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return compositeKey, err
|
return compositeKey, err
|
||||||
|
|
@ -227,6 +231,11 @@ func (s *stageBuilder) optimize(compositeKey CompositeCache, cfg v1.Config) erro
|
||||||
if !s.opts.Cache {
|
if !s.opts.Cache {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
var buildArgs = s.args.Clone()
|
||||||
|
// Restore build args back to their original values
|
||||||
|
defer func() {
|
||||||
|
s.args = buildArgs
|
||||||
|
}()
|
||||||
|
|
||||||
stopCache := false
|
stopCache := false
|
||||||
// Possibly replace commands with their cached implementations.
|
// Possibly replace commands with their cached implementations.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue