Skip to content

Detect Windows absolute paths on non-Windows CLI - #1990

Merged
silvin-lubecki merged 1 commit into
docker:masterfrom
thaJeztah:cross_platform_bind
Jul 11, 2019
Merged

Detect Windows absolute paths on non-Windows CLI#1990
silvin-lubecki merged 1 commit into
docker:masterfrom
thaJeztah:cross_platform_bind

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Jul 9, 2019

Copy link
Copy Markdown
Member

Note that there is an alternative PR in #1871, but that PR changes the current behaviour, and might require more discussion. This PR tries to focus on just the basic problem.

addresses #1403
addresses moby/moby#33746
fixesmoby/moby#34810

When deploying a stack using a relative path as bind-mount source in the compose file, the CLI converts the relative path to an absolute path, relative to the location of the docker-compose file.

This causes a problem when deploying a stack that uses an absolute Windows path, because a non Windows client will fail to detect that the path (e.g. C:\somedir) is an absolute path (and not a relative directory named C:\).

The existing code did already take Windows clients deploying a Linux stack into account (by checking if the path had a leading slash). This patch adds the reverse, and adds detection for Windows absolute paths on non-Windows clients.

The code used to detect Windows absolute paths is copied from the Golang filepath package;
https://github.com/golang/go/blob/1d0e94b1e13d5e8a323a63cd1cc1ef95290c9c36/src/path/filepath/path_windows.go#L12-L65

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

ping @silvin-lubecki@vdemeester@ddebroy PTAL

/cc @stevenfollis@david-yu@ivansharamok

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Ah, booh! The linter doesn't like the Golang standard library;

cli/compose/loader/windows_path.go:35::warning: cyclomatic complexity 18 of function volumeNameLen() is high (> 16) (gocyclo)

@thaJeztah
thaJeztahforce-pushed the cross_platform_bind branch from ea9fac0 to af38be8CompareJuly 9, 2019 22:22
@codecov-io

codecov-io commented Jul 9, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1990 into master will increase coverage by 0.04%.
The diff coverage is 90.32%.

@@ Coverage Diff @@## master #1990 +/- ##
==========================================
+ Coverage 56.74% 56.78% +0.04% 
==========================================
Files 310 311 +1 Lines 21802 21832 +30 ==========================================
+ Hits 12371 12398 +27 - Misses 8517 8519 +2 - Partials 914 915 +1


// volumeNameLen returns length of the leading volume name on Windows.
// It returns 0 elsewhere.
// nolint: gocyclo

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to silence the linter

@ddebroyddebroy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple of suggestions that can be addressed later

Comment threadcli/compose/loader/loader_test.go Outdated
image: mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
volumes:
- type: bind
source: c:\

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be safe, can the unit tests use E:\ or X:\ as the source path's drive (something other than C:\) in some of the cases?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can change that; let me update

Comment threadcli/compose/loader/windows_path.go Outdated
@thaJeztah
thaJeztahforce-pushed the cross_platform_bind branch 2 times, most recently from 43574ef to 72bb085CompareJuly 9, 2019 23:14

@vdemeestervdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐯
/cc @simonferquel

@thaJeztah
thaJeztahforce-pushed the cross_platform_bind branch from 72bb085 to d760466CompareJuly 10, 2019 09:55
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Per discussion with @silvin-lubecki on slack: I removed the redundant path.IsAbs from the isAbs() function, and updated the test-file to also include the copyright from upstream

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Booh; this one starts failing now all of a sudden; #1841 (comment)

10:06:29 === FAIL: e2e/container TestSigProxyWithTTY (6.52s)
10:06:29 proxy_signal_test.go:38: terminating PID 3438
10:06:29 proxy_signal_test.go:42: timeout hit after 5s: expected status exited != running

@silvin-lubeckisilvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

When deploying a stack using a relative path as bind-mount
source in the compose file, the CLI converts the relative
path to an absolute path, relative to the location of the
docker-compose file.
This causes a problem when deploying a stack that uses
an absolute Windows path, because a non-Windows client will
fail to detect that the path (e.g. `C:\somedir`) is an absolute
path (and not a relative directory named `C:\`).
The existing code did already take Windows clients deploying
a Linux stack into account (by checking if the path had a leading
slash). This patch adds the reverse, and adds detection for Windows
absolute paths on non-Windows clients.
The code used to detect Windows absolute paths is copied from the
Golang filepath package;
https://github.com/golang/go/blob/1d0e94b1e13d5e8a323a63cd1cc1ef95290c9c36/src/path/filepath/path_windows.go#L12-L65
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker stack deploy prepends current Unix dir to Windows bind mount source

6 participants

@thaJeztah@codecov-io@vdemeester@ddebroy@silvin-lubecki@GordonTheTurtle