Skip to content

Commit

Permalink
Handle env commands with multiple variable definitions (GoogleContain…
Browse files Browse the repository at this point in the history
…erTools#1625) (GoogleContainerTools#1626)

Signed-off-by: Cornelius Weig <cornelius.weig@tngtech.com>
  • Loading branch information
Cornelius Weig authored and balopat committed Feb 8, 2019
1 parent afd356c commit 5862895
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/skaffold/docker/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ func copiedFiles(nodes []*parser.Node) ([][]string, error) {
copied = append(copied, files)
}
case command.Env:
envs[node.Next.Value] = node.Next.Next.Value
// 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
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/skaffold/docker/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ WORKDIR ${foo} # WORKDIR /bar
COPY $foo /quux # COPY bar /quux
`

const multiEnvTest = `
FROM busybox
ENV baz=bar \
foo=docker
COPY $foo/nginx.conf . # COPY docker/nginx.conf .
`

const copyDirectory = `
FROM nginx
ADD . /etc/
Expand Down Expand Up @@ -293,6 +300,13 @@ func TestGetDependencies(t *testing.T) {
expected: []string{"Dockerfile", "bar"},
fetched: []string{"busybox"},
},
{
description: "multiple env test",
dockerfile: multiEnvTest,
workspace: ".",
expected: []string{"Dockerfile", filepath.Join("docker", "nginx.conf")},
fetched: []string{"busybox"},
},
{
description: "multi file copy",
dockerfile: multiFileCopy,
Expand Down

0 comments on commit 5862895

Please sign in to comment.