From cfc9f39176a4509d26a1ed7f2dca6a387e600d50 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Mon, 4 May 2020 15:47:28 +0200 Subject: [PATCH 1/2] feat: ensure relative WorkingDir work Currently the default WorkingDir in test is "/", while in reallife it's empty. This change the tests to reflect reel life and fix the case where First WorkingDir is relative. --- pkg/commands/workdir.go | 6 +++++- pkg/commands/workdir_test.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/commands/workdir.go b/pkg/commands/workdir.go index 273432052..153f27c92 100644 --- a/pkg/commands/workdir.go +++ b/pkg/commands/workdir.go @@ -48,7 +48,11 @@ func (w *WorkdirCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile if filepath.IsAbs(resolvedWorkingDir) { config.WorkingDir = resolvedWorkingDir } else { - config.WorkingDir = filepath.Join(config.WorkingDir, resolvedWorkingDir) + if config.WorkingDir != "" { + config.WorkingDir = filepath.Join(config.WorkingDir, resolvedWorkingDir) + } else { + config.WorkingDir = filepath.Join("/", resolvedWorkingDir) + } } logrus.Infof("Changed working directory to %s", config.WorkingDir) diff --git a/pkg/commands/workdir_test.go b/pkg/commands/workdir_test.go index 7a95ccad0..c347c7062 100644 --- a/pkg/commands/workdir_test.go +++ b/pkg/commands/workdir_test.go @@ -35,6 +35,11 @@ var workdirTests = []struct { expectedPath string snapshotFiles []string }{ + { + path: "a", + expectedPath: "/a", + snapshotFiles: []string{"/a"}, + }, { path: "/a", expectedPath: "/a", @@ -92,7 +97,7 @@ func TestWorkdirCommand(t *testing.T) { }() cfg := &v1.Config{ - WorkingDir: "/", + WorkingDir: "", Env: []string{ "path=usr/", "home=/root", From c6a98b754a5c018ea5b7acc8b35f0c7e930f8338 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Mon, 4 May 2020 09:48:09 -0700 Subject: [PATCH 2/2] Make sure integration test has a relative workdir --- integration/dockerfiles/Dockerfile_test_workdir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/dockerfiles/Dockerfile_test_workdir b/integration/dockerfiles/Dockerfile_test_workdir index df8bd3e4b..5f32a4047 100644 --- a/integration/dockerfiles/Dockerfile_test_workdir +++ b/integration/dockerfiles/Dockerfile_test_workdir @@ -1,6 +1,6 @@ FROM debian:9.11 COPY context/foo foo -WORKDIR /test +WORKDIR test # Test that this will be appended on to the previous command, to create /test/workdir WORKDIR workdir COPY context/foo ./currentfoo