Merge pull request #461 from pre-commit/only_pull_on_initial_build

Only --pull on initial docker build
This commit is contained in:
Anthony Sottile 2017-01-04 11:59:52 -08:00 committed by GitHub
commit a2ba618d72

View file

@ -39,13 +39,16 @@ def assert_docker_available():
) )
def build_docker_image(repo_cmd_runner): def build_docker_image(repo_cmd_runner, **kwargs):
pull = kwargs.pop('pull')
assert not kwargs, kwargs
cmd = ( cmd = (
'docker', 'build', '--pull', 'docker', 'build', '.',
'--tag', docker_tag(repo_cmd_runner), '--tag', docker_tag(repo_cmd_runner),
'--label', PRE_COMMIT_LABEL, '--label', PRE_COMMIT_LABEL,
'.'
) )
if pull:
cmd += ('--pull',)
helpers.run_setup_cmd(repo_cmd_runner, cmd) helpers.run_setup_cmd(repo_cmd_runner, cmd)
@ -62,21 +65,22 @@ def install_environment(
) )
assert_docker_available() assert_docker_available()
directory = helpers.environment_dir(ENVIRONMENT_DIR, 'default') directory = repo_cmd_runner.path(helpers.environment_dir(
os.mkdir(repo_cmd_runner.path(directory)) ENVIRONMENT_DIR, 'default',
))
# Docker doesn't really have relevant disk environment, but pre-commit # Docker doesn't really have relevant disk environment, but pre-commit
# still needs to cleanup it's state files on failure # still needs to cleanup it's state files on failure
env_dir = repo_cmd_runner.path(directory) with clean_path_on_failure(directory):
with clean_path_on_failure(env_dir): build_docker_image(repo_cmd_runner, pull=True)
build_docker_image(repo_cmd_runner) os.mkdir(directory)
def run_hook(repo_cmd_runner, hook, file_args): def run_hook(repo_cmd_runner, hook, file_args):
assert_docker_available() assert_docker_available()
# Rebuild the docker image in case it has gone missing, as many people do # Rebuild the docker image in case it has gone missing, as many people do
# automated cleanup of docker images. # automated cleanup of docker images.
build_docker_image(repo_cmd_runner) build_docker_image(repo_cmd_runner, pull=False)
cmd = ( cmd = (
'docker', 'run', 'docker', 'run',
'--rm', '--rm',