Fix windowsPath to handle local named pipes correctly
What does this MR do?
- Fixes
windowsPath.IsRoot
andwindowsPath.IsAbs
to correctly handle Windows local named pipes, and adds tests. - Fixes a minor bug in the
windowsPipe
regex inexecutors/docker/internal/volumes/parser/windows_parser.go
which would also match\\a\pipe\namedpipe
. - Adds a test to
executors/docker/internal/volumes/manager.go
to use the Windows path class (all the rest are using the Unix version). - Renames
addParser
toaddUnixParser
to make it clear which parser implementation we're using in a given test.
Why was this MR needed?
See #4295 (closed)
What's the best way to test this MR?
Unit tests
Check that the unit tests are passing and test the intended scenarios.
Before the fix to the code:
$ vagrant up && vagrant ssh
vagrant@VAGRANT-2019 C:\Users\vagrant>cd %RUNNER_SRC%
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -run TestWindowsIsAbs .\helpers\path
--- FAIL: TestWindowsIsAbs (0.00s)
--- FAIL: TestWindowsIsAbs/named_pipe_path (0.00s)
windows_path_test.go:90:
Error Trace: windows_path_test.go:90
Error: Not equal:
expected: true
actual : false
Test: TestWindowsIsAbs/named_pipe_path
--- FAIL: TestWindowsIsAbs/named_pipe_path_with_forward_slashes (0.00s)
windows_path_test.go:90:
Error Trace: windows_path_test.go:90
Error: Not equal:
expected: true
actual : false
Test: TestWindowsIsAbs/named_pipe_path_with_forward_slashes
FAIL
FAIL gitlab.com/gitlab-org/gitlab-runner/helpers/path 0.027s
FAIL
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -run TestWindowsIsRoot .\helpers\path
ok gitlab.com/gitlab-org/gitlab-runner/helpers/path 0.033s
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -v -run TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows .\executors\docker\internal\volumes
=== RUN TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows
=== RUN TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows/pipe_name_volume_specified
panic:
mock: Unexpected Method Call
-----------------------------
VolumeCreate(*context.emptyCtx,volume.VolumeCreateBody)
0: (*context.emptyCtx)(0xc000030118)
1: volume.VolumeCreateBody{Driver:"", DriverOpts:map[string]string(nil), Labels:map[string]string{"com.gitlab.gitlab-runner.job.before_sha":"", "com.gitlab.gitlab-runner.job.id":"0", "com.gitlab.gitla
b-runner.job.ref":"", "com.gitlab.gitlab-runner.job.sha":"", "com.gitlab.gitlab-runner.pipeline.id":"", "com.gitlab.gitlab-runner.project.id":"0", "com.gitlab.gitlab-runner.runner.id":"", "com.gitlab.gitlab-runner.runner.local_id":"0", "com.gitlab.gitlab-runner.type":"cache"}, Name:"uniq-cache-2be4e73b4826f26a0049c7794d38cdb0"}
After the fix to the code:
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -run TestWindowsIsAbs .\helpers\path
ok gitlab.com/gitlab-org/gitlab-runner/helpers/path (cached)
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -v -run TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows .\executors\docker\internal\volumes
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -run TestWindowsIsRoot .\helpers\path
ok gitlab.com/gitlab-org/gitlab-runner/helpers/path (cached)
vagrant@VAGRANT-2019 C:\GitLab-Runner>go test -v -run TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows .\executors\docker\internal\volumes
=== RUN TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows
=== RUN TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows/pipe_name_volume_specified
=== RUN TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows/duplicate_pipe_name_volume_specified
--- PASS: TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows (0.00s)
--- PASS: TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows/pipe_name_volume_specified (0.00s)
manager_windows_test.go:62: PASS: VolumeCreate(string,mock.argumentMatcher)
manager_windows_test.go:63: PASS: Path()
manager_windows_test.go:63: PASS: ParseVolume(string)
manager_windows_test.go:63: PASS: ParseVolume(string)
--- PASS: TestDefaultManager_CreateUserVolumes_CacheVolume_VolumeBased_Windows/duplicate_pipe_name_volume_specified (0.00s)
manager_windows_test.go:63: PASS: Path()
manager_windows_test.go:63: PASS: ParseVolume(string)
manager_windows_test.go:63: PASS: ParseVolume(string)
PASS
ok gitlab.com/gitlab-org/gitlab-runner/executors/docker/internal/volumes (cached)
Manual tests
-
Set up a Windows VM with Docker:
vagrant up --provider virtualbox 2019-box
-
Copy the fixed Windows Runner .exe to a directory in the VM using the VirtualBox File Manager.
-
Register the runner:
gitlab-runner-windows-amd64.exe register -c .\config.toml -n -u https://gitlab.com/ -r <registration token> --tag-list "windows,docker,vagrant" --executor docker-windows --docker-image mcr.microsoft.com/windows/servercore:ltsc2019 --docker-helper-image gitlab/gitlab-runner-helper:x86_64-575a5585-servercore1809 --docker-volumes "c:\cache" --docker-volumes "\\.\pipe\docker_engine:\\.\pipe\docker_engine"
-
Start the runner:
gitlab-runner-windows-amd64.exe run -c .\config.toml
-
Run any build against it. A failed build (using a
master
branch build) is shown here. The same job was replayed against the branch runner and succeeded.
What are the relevant issue numbers?
Closes #4295 (closed)
Edited by Pedro Pombeiro