Skip to content

Commit

Permalink
Merge pull request #283 from nalind/workdir-trailing-separator
Browse files Browse the repository at this point in the history
Trim trailing path separators from WORKDIR values
  • Loading branch information
openshift-merge-bot[bot] committed Jun 3, 2024
2 parents 5b6b190 + 8fca88b commit 19da76b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dispatchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ func workdir(b *Builder, args []string, attributes map[string]bool, flagArgs []s
workdir = filepath.Join(string(os.PathSeparator), current, workdir)
}

if workdir != string(os.PathSeparator) {
workdir = strings.TrimSuffix(workdir, string(os.PathSeparator))
}

b.RunConfig.WorkingDir = workdir
return nil
}
Expand Down
10 changes: 9 additions & 1 deletion dockerclient/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ func TestConformanceInternal(t *testing.T) {
Name: "healthcheck",
Dockerfile: "testdata/Dockerfile.healthcheck",
},
{
Name: "workdir-with-trailing-path-separator",
Dockerfile: "testdata/workdir/Dockerfile.trailing",
},
{
Name: "workdir-without-trailing-path-separator",
Dockerfile: "testdata/workdir/Dockerfile.notrailing",
},
}

for i, test := range testCases {
Expand Down Expand Up @@ -518,7 +526,7 @@ func TestConformanceExternal(t *testing.T) {
{
Name: "copy and env interaction",
// Tests COPY and other complex interactions of ENV
ContextDir: "16/alpine3.18",
ContextDir: "16/alpine3.20",
Dockerfile: "Dockerfile",
Git: "https://github.com/docker-library/postgres.git",
Ignore: []ignoreFunc{
Expand Down
3 changes: 3 additions & 0 deletions dockerclient/testdata/workdir/Dockerfile.notrailing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox
USER daemon
WORKDIR /tmp
3 changes: 3 additions & 0 deletions dockerclient/testdata/workdir/Dockerfile.trailing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox
USER daemon
WORKDIR /tmp/

0 comments on commit 19da76b

Please sign in to comment.