From e885d6a5e652fc8ac50bae6ea2737f65fa6fc330 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 27 Mar 2018 09:48:37 -0700 Subject: [PATCH] Use default token for env replacement parsing --- pkg/commands/copy.go | 2 +- pkg/commands/env_test.go | 19 ------------------- pkg/commands/label.go | 5 ++--- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/pkg/commands/copy.go b/pkg/commands/copy.go index ff3ad9f9bb..e9f8cab592 100644 --- a/pkg/commands/copy.go +++ b/pkg/commands/copy.go @@ -44,7 +44,7 @@ func (c *CopyCommand) ExecuteCommand(config *manifest.Schema2Config) error { if err != nil { return err } - dest = resolvedEnvs[len(c.cmd.SourcesAndDest)-1] + dest = resolvedEnvs[len(resolvedEnvs)-1] // Get a map of [src]:[files rooted at src] srcMap, err := util.ResolveSources(resolvedEnvs, c.buildcontext) if err != nil { diff --git a/pkg/commands/env_test.go b/pkg/commands/env_test.go index a6c8af2461..5aedcff022 100644 --- a/pkg/commands/env_test.go +++ b/pkg/commands/env_test.go @@ -53,25 +53,6 @@ func TestUpdateEnvConfig(t *testing.T) { updateConfigEnv(newEnvs, cfg) testutil.CheckErrorAndDeepEqual(t, false, nil, expectedEnvArray, cfg.Env) } - -func TestEnvToString(t *testing.T) { - envCmd := &instructions.EnvCommand{ - Env: []instructions.KeyValuePair{ - { - Key: "PATH", - Value: "/some/path", - }, - { - Key: "HOME", - Value: "/root", - }, - }, - } - expectedString := "ENV PATH=/some/path HOME=/root" - actualString := envToString(envCmd) - testutil.CheckErrorAndDeepEqual(t, false, nil, expectedString, actualString) -} - func Test_EnvExecute(t *testing.T) { cfg := &manifest.Schema2Config{ Env: []string{ diff --git a/pkg/commands/label.go b/pkg/commands/label.go index ec80e494f1..3cf8896db7 100644 --- a/pkg/commands/label.go +++ b/pkg/commands/label.go @@ -17,9 +17,9 @@ limitations under the License. package commands import ( + "github.com/GoogleCloudPlatform/k8s-container-builder/pkg/util" "github.com/containers/image/manifest" "github.com/docker/docker/builder/dockerfile/instructions" - "github.com/docker/docker/builder/dockerfile/shell" "github.com/sirupsen/logrus" "strings" ) @@ -36,9 +36,8 @@ func updateLabels(labels []instructions.KeyValuePair, config *manifest.Schema2Co existingLabels := config.Labels // Let's unescape values before setting the label - shlex := shell.NewLex('\\') for index, kvp := range labels { - unescaped, err := shlex.ProcessWord(kvp.Value, []string{}) + unescaped, err := util.ResolveEnvironmentReplacement(kvp.Value, []string{}, false) if err != nil { return err }