pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pre-commit/pre-commit/commit/5d1cac64c1953663959fb71f46dff0179bf63f9a

ref="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> ignore self-container when in docker-in-docker · pre-commit/pre-commit@5d1cac6 · GitHub
Skip to content

Commit 5d1cac6

Browse files
committed
ignore self-container when in docker-in-docker
1 parent a4444f1 commit 5d1cac6

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

pre_commit/languages/docker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pre_commit.hook import Hook
99
from pre_commit.languages import helpers
1010
from pre_commit.prefix import Prefix
11+
from pre_commit.util import CalledProcessError
1112
from pre_commit.util import clean_path_on_failure
1213
from pre_commit.util import cmd_output_b
1314

@@ -42,7 +43,11 @@ def _get_docker_path(path: str) -> str:
4243

4344
container_id = _get_container_id()
4445

45-
_, out, _ = cmd_output_b('docker', 'inspect', container_id)
46+
try:
47+
_, out, _ = cmd_output_b('docker', 'inspect', container_id)
48+
except CalledProcessError:
49+
# self-container was not visible from here (perhaps docker-in-docker)
50+
return path
4651

4752
container, = json.loads(out)
4853
for mount in container['Mounts']:

tests/languages/docker_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from pre_commit.languages import docker
11+
from pre_commit.util import CalledProcessError
1112

1213
DOCKER_CGROUP_EXAMPLE = b'''\
1314
12:hugetlb:/docker/c33988ec7651ebc867cb24755eaf637a6734088bc7eef59d5799293a9e5450f7
@@ -171,3 +172,10 @@ def test_get_docker_path_in_docker_windows(in_docker):
171172
path = r'c:\folder\test\something'
172173
expected = r'c:\users\user\test\something'
173174
assert docker._get_docker_path(path) == expected
175+
176+
177+
def test_get_docker_path_in_docker_docker_in_docker(in_docker):
178+
# won't be able to discover "self" container in true docker-in-docker
179+
err = CalledProcessError(1, (), 0, b'', b'')
180+
with mock.patch.object(docker, 'cmd_output_b', side_effect=err):
181+
assert docker._get_docker_path('/project') == '/project'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy