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

Skip to content

Commit b7bd825

Browse files
author
Ben Picolo
committed
Support docker hooks with args
1 parent 58df7c0 commit b7bd825

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

pre_commit/languages/docker.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,17 @@ def run_hook(repo_cmd_runner, hook, file_args):
8181
# Rebuild the docker image in case it has gone missing, as many people do
8282
# automated cleanup of docker images.
8383
build_docker_image(repo_cmd_runner, pull=False)
84+
85+
entry_parts = hook['entry'].split(' ')
86+
entry_executable, entry_args = entry_parts[0], entry_parts[1:]
87+
8488
cmd = (
8589
'docker', 'run',
8690
'--rm',
87-
'-u', '{}:{}'.format(os.getuid(), os.getgid()),
8891
'-v', '{}:/src:rw'.format(os.getcwd()),
8992
'--workdir', '/src',
90-
'--entrypoint', hook['entry'],
93+
'--entrypoint', entry_executable,
9194
docker_tag(repo_cmd_runner)
9295
)
9396

94-
return xargs(cmd + tuple(hook['args']), file_args)
97+
return xargs(cmd + tuple(entry_args) + tuple(hook['args']), file_args)

testing/resources/docker_hooks_repo/hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
language: docker
55
files: \.txt$
66

7+
- id: docker-hook-arg
8+
name: Docker test hook
9+
entry: echo -n
10+
language: docker
11+
files: \.txt$
12+
713
- id: docker-hook-failing
814
name: Docker test hook with nonzero exit code
915
entry: bork

tests/repository_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ def test_run_a_docker_hook(tempdir_factory, store):
141141
)
142142

143143

144+
@skipif_slowtests_false
145+
@skipif_cant_run_docker
146+
@pytest.mark.integration
147+
def test_run_a_docker_hook_with_entry_args(tempdir_factory, store):
148+
_test_hook_repo(
149+
tempdir_factory, store, 'docker_hooks_repo',
150+
'docker-hook-arg',
151+
['Hello World from docker'], b'Hello World from docker',
152+
)
153+
154+
144155
@skipif_slowtests_false
145156
@skipif_cant_run_docker
146157
@pytest.mark.integration

0 commit comments

Comments
 (0)