mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 04:50:20 -06:00
Merge pull request #462 from bpicolo/support_args_in_docker_entrypoint
Support docker hooks with args
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import shlex
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit.languages import helpers
|
||||
@@ -81,14 +82,18 @@ def run_hook(repo_cmd_runner, hook, file_args):
|
||||
# Rebuild the docker image in case it has gone missing, as many people do
|
||||
# automated cleanup of docker images.
|
||||
build_docker_image(repo_cmd_runner, pull=False)
|
||||
|
||||
entry_parts = shlex.split(hook['entry'])
|
||||
entry_executable, entry_args = entry_parts[0], entry_parts[1:]
|
||||
|
||||
cmd = (
|
||||
'docker', 'run',
|
||||
'--rm',
|
||||
'-u', '{}:{}'.format(os.getuid(), os.getgid()),
|
||||
'-v', '{}:/src:rw'.format(os.getcwd()),
|
||||
'--workdir', '/src',
|
||||
'--entrypoint', hook['entry'],
|
||||
'--entrypoint', entry_executable,
|
||||
docker_tag(repo_cmd_runner)
|
||||
)
|
||||
|
||||
return xargs(cmd + tuple(hook['args']), file_args)
|
||||
return xargs(cmd + tuple(entry_args) + tuple(hook['args']), file_args)
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
language: docker
|
||||
files: \.txt$
|
||||
|
||||
- id: docker-hook-arg
|
||||
name: Docker test hook
|
||||
entry: echo -n
|
||||
language: docker
|
||||
files: \.txt$
|
||||
|
||||
- id: docker-hook-failing
|
||||
name: Docker test hook with nonzero exit code
|
||||
entry: bork
|
||||
|
||||
@@ -141,6 +141,17 @@ def test_run_a_docker_hook(tempdir_factory, store):
|
||||
)
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@skipif_cant_run_docker
|
||||
@pytest.mark.integration
|
||||
def test_run_a_docker_hook_with_entry_args(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'docker_hooks_repo',
|
||||
'docker-hook-arg',
|
||||
['Hello World from docker'], b'Hello World from docker',
|
||||
)
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@skipif_cant_run_docker
|
||||
@pytest.mark.integration
|
||||
|
||||
Reference in New Issue
Block a user