Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7ce5db

Browse files
committed
Use fallback uid and gid if os.getuid() and os.getgid() are unavailable
1 parent 1bd9bfe commit b7ce5db

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

pre_commit/languages/docker.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
ENVIRONMENT_DIR = 'docker'
1616
PRE_COMMIT_LABEL = 'PRE_COMMIT'
17+
FALLBACK_UID = 1000
18+
FALLBACK_GID = 1000
1719
get_default_version = helpers.basic_get_default_version
1820
healthy = helpers.basic_healthy
1921

@@ -73,11 +75,25 @@ def install_environment(
7375
os.mkdir(directory)
7476

7577

78+
def getuid():
79+
try:
80+
return os.getuid()
81+
except AttributeError:
82+
return FALLBACK_UID
83+
84+
85+
def getgid():
86+
try:
87+
return os.getgid()
88+
except AttributeError:
89+
return FALLBACK_GID
90+
91+
7692
def docker_cmd(): # pragma: windows no cover
7793
return (
7894
'docker', 'run',
7995
'--rm',
80-
'-u', '{}:{}'.format(os.getuid(), os.getgid()),
96+
'-u', '{}:{}'.format(getuid(), getgid()),
8197
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
8298
# The `Z` option tells Docker to label the content with a private
8399
# unshared label. Only the current container can use a private volume.

0 commit comments

Comments
 (0)