There was an error while loading. Please reload this page.
2 parents 332b98b + d4a9ff4 commit 376d283Copy full SHA for 376d283
2 files changed
pre_commit/languages/docker.py
@@ -73,11 +73,18 @@ def install_environment(
73
os.mkdir(directory)
74
75
76
+def get_docker_user(): # pragma: windows no cover
77
+ try:
78
+ return '{}:{}'.format(os.getuid(), os.getgid())
79
+ except AttributeError:
80
+ return '1000:1000'
81
+
82
83
def docker_cmd(): # pragma: windows no cover
84
return (
85
'docker', 'run',
86
'--rm',
- '-u', '{}:{}'.format(os.getuid(), os.getgid()),
87
+ '-u', get_docker_user(),
88
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
89
# The `Z` option tells Docker to label the content with a private
90
# unshared label. Only the current container can use a private volume.
tests/languages/docker_test.py
@@ -13,3 +13,14 @@ def test_docker_is_running_process_error():
13
side_effect=CalledProcessError(*(None,) * 4),
14
):
15
assert docker.docker_is_running() is False
16
17
18
+def test_docker_fallback_user():
19
+ def invalid_attribute():
20
+ raise AttributeError
21
+ with mock.patch.multiple(
22
+ 'os', create=True,
23
+ getuid=invalid_attribute,
24
+ getgid=invalid_attribute,
25
+ ):
26
+ assert docker.get_docker_user() == '1000:1000'
0 commit comments