FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Optimize Docker image pull by artnc · Pull Request #3573 · pre-commit/pre-commit · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 11 additions & 2 deletions pre_commit/languages/docker_image.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ def run_hook(
require_serial: bool,
color: bool,
) -> tuple[int, bytes]: # pragma: win32 no cover
cmd = docker_cmd(color=color) + lang_base.hook_cmd(entry, args)
cmd = lang_base.hook_cmd(entry, args)

# To prevent duplicate simultaneous image pull attempts in `run_xargs`, we
# try to precache the Docker image by pulling it here first
try:
image_name = cmd[2 if cmd[0] == '--entrypoint' else 0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this won't work reliably at all

lang_base.setup_cmd(prefix, ('docker', 'pull', image_name))
except Exception:
pass
Comment on lines +33 to +34

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

? this is never acceptable


return lang_base.run_xargs(
cmd,
docker_cmd(color=color) + cmd,
file_args,
require_serial=require_serial,
color=color,
Expand Down
34 changes: 34 additions & 0 deletions tests/languages/docker_image_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from unittest.mock import patch

import pytest

from pre_commit.languages import docker_image
Expand Down Expand Up @@ -57,3 +59,35 @@ def test_docker_image_no_color_no_tty(tmp_path):
color=False,
)
assert ret == (0, b'root:x:0:\n')


@xfailif_windows # pragma: win32 no cover
@patch('pre_commit.lang_base.setup_cmd')
def test_docker_image_pre_pull_regular_entry(mock_setup, tmp_path):
ret = run_language(
tmp_path,
docker_image,
'ubuntu:22.04 echo',
args=('hello hello world',),
)
mock_setup.assert_called_once_with(
mock_setup.call_args[0][0],
('docker', 'pull', 'ubuntu:22.04'),
)
assert ret == (0, b'hello hello world\n')


@xfailif_windows # pragma: win32 no cover
@patch('pre_commit.lang_base.setup_cmd')
def test_docker_image_pre_pull_entrypoint_entry(mock_setup, tmp_path):
ret = run_language(
tmp_path,
docker_image,
'--entrypoint echo ubuntu:22.04',
args=('hello hello world',),
)
mock_setup.assert_called_once_with(
mock_setup.call_args[0][0],
('docker', 'pull', 'ubuntu:22.04'),
)
assert ret == (0, b'hello hello world\n')
Loading

Back | FazBrowse Home | New Git URL