Simplify data flow of environment variables
@@ -158,7 +158,7 @@ func onbuildInstructions(nodes []*parser.Node, insecureRegistries map[string]boo
func copiedFiles(nodes []*parser.Node) ([][]string, error) {
var copied [][]string
- envs := map[string]string{}
+ envs := make([]string, 0)
for _, node := range nodes {
switch node.Value {
case command.Add, command.Copy:
@@ -173,7 +173,7 @@ func copiedFiles(nodes []*parser.Node) ([][]string, error) {
case command.Env:
// one env command may define multiple variables
for node := node.Next; node != nil && node.Next != nil; node = node.Next.Next {
- envs[node.Value] = node.Next.Value
+ envs = append(envs, fmt.Sprintf("%s=%s", node.Value, node.Next.Value))
}
}
}
@@ -396,7 +396,7 @@ func retrieveImage(image string, insecureRegistries map[string]bool) (*v1.Config
return localDaemon.ConfigFile(context.Background(), image)
}
-func processCopy(value *parser.Node, envs map[string]string) ([]string, error) {
+func processCopy(value *parser.Node, envs []string) ([]string, error) {
var copied []string
slex := shell.NewLex('\\')
@@ -405,7 +405,7 @@ func processCopy(value *parser.Node, envs map[string]string) ([]string, error) {
if value.Next.Next == nil || strings.HasPrefix(value.Next.Next.Value, "#") {
break
}
- src, err := processShellWord(slex, value.Next.Value, envs)
+ src, err := slex.ProcessWord(value.Next.Value, envs)
if err != nil {
return nil, errors.Wrap(err, "processing word")
}
@@ -426,14 +426,6 @@ func processCopy(value *parser.Node, envs map[string]string) ([]string, error) {
return copied, nil
}
-func processShellWord(lex *shell.Lex, word string, envs map[string]string) (string, error) {
- envSlice := []string{}
- for envKey, envVal := range envs {
- envSlice = append(envSlice, fmt.Sprintf("%s=%s", envKey, envVal))
- }
- return lex.ProcessWord(word, envSlice)
-}
-
func hasMultiStageFlag(flags []string) bool {
for _, f := range flags {
if strings.HasPrefix(f, "--from=") {
