mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1094 from geieredgar/windows-docker-fix
Fix docker based hooks failing on Windows
This commit is contained in:
commit
376d283ba3
2 changed files with 19 additions and 1 deletions
|
|
@ -73,11 +73,18 @@ def install_environment(
|
||||||
os.mkdir(directory)
|
os.mkdir(directory)
|
||||||
|
|
||||||
|
|
||||||
|
def get_docker_user(): # pragma: windows no cover
|
||||||
|
try:
|
||||||
|
return '{}:{}'.format(os.getuid(), os.getgid())
|
||||||
|
except AttributeError:
|
||||||
|
return '1000:1000'
|
||||||
|
|
||||||
|
|
||||||
def docker_cmd(): # pragma: windows no cover
|
def docker_cmd(): # pragma: windows no cover
|
||||||
return (
|
return (
|
||||||
'docker', 'run',
|
'docker', 'run',
|
||||||
'--rm',
|
'--rm',
|
||||||
'-u', '{}:{}'.format(os.getuid(), os.getgid()),
|
'-u', get_docker_user(),
|
||||||
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
|
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
|
||||||
# The `Z` option tells Docker to label the content with a private
|
# The `Z` option tells Docker to label the content with a private
|
||||||
# unshared label. Only the current container can use a private volume.
|
# unshared label. Only the current container can use a private volume.
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,14 @@ def test_docker_is_running_process_error():
|
||||||
side_effect=CalledProcessError(*(None,) * 4),
|
side_effect=CalledProcessError(*(None,) * 4),
|
||||||
):
|
):
|
||||||
assert docker.docker_is_running() is False
|
assert docker.docker_is_running() is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_docker_fallback_user():
|
||||||
|
def invalid_attribute():
|
||||||
|
raise AttributeError
|
||||||
|
with mock.patch.multiple(
|
||||||
|
'os', create=True,
|
||||||
|
getuid=invalid_attribute,
|
||||||
|
getgid=invalid_attribute,
|
||||||
|
):
|
||||||
|
assert docker.get_docker_user() == '1000:1000'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue