Simplify docker user fallback implementation and test

This commit is contained in:
Edgar Geier
2019-07-25 11:20:03 +02:00
parent a21a4f46c7
commit d4a9ff4d1f
2 changed files with 11 additions and 23 deletions

View File

@@ -14,8 +14,6 @@ from pre_commit.util import cmd_output
ENVIRONMENT_DIR = 'docker'
PRE_COMMIT_LABEL = 'PRE_COMMIT'
FALLBACK_UID = 1000
FALLBACK_GID = 1000
get_default_version = helpers.basic_get_default_version
healthy = helpers.basic_healthy
@@ -75,25 +73,18 @@ def install_environment(
os.mkdir(directory)
def getuid(): # pragma: windows no cover
def get_docker_user(): # pragma: windows no cover
try:
return os.getuid()
return '{}:{}'.format(os.getuid(), os.getgid())
except AttributeError:
return FALLBACK_UID
def getgid(): # pragma: windows no cover
try:
return os.getgid()
except AttributeError:
return FALLBACK_GID
return '1000:1000'
def docker_cmd(): # pragma: windows no cover
return (
'docker', 'run',
'--rm',
'-u', '{}:{}'.format(getuid(), getgid()),
'-u', get_docker_user(),
# 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
# unshared label. Only the current container can use a private volume.