mirror of
https://github.com/containers/podman-compose.git
synced 2025-05-31 23:45:51 +02:00
Merge pull request #1222 from mokibit/print-full-dockerfile-path
Print full Dockerfile path instead of context on error
This commit is contained in:
commit
b650efbb33
@ -2752,8 +2752,10 @@ def container_to_build_args(
|
|||||||
build_args = []
|
build_args = []
|
||||||
|
|
||||||
if not is_path_git_url(ctx):
|
if not is_path_git_url(ctx):
|
||||||
|
custom_dockerfile_given = False
|
||||||
if dockerfile:
|
if dockerfile:
|
||||||
dockerfile = os.path.join(ctx, dockerfile)
|
dockerfile = os.path.join(ctx, dockerfile)
|
||||||
|
custom_dockerfile_given = True
|
||||||
else:
|
else:
|
||||||
dockerfile_alts = [
|
dockerfile_alts = [
|
||||||
"Containerfile",
|
"Containerfile",
|
||||||
@ -2773,6 +2775,9 @@ def container_to_build_args(
|
|||||||
dockerfile = os.path.normpath(os.path.join(ctx, dockerfile))
|
dockerfile = os.path.normpath(os.path.join(ctx, dockerfile))
|
||||||
build_args.extend(["-f", dockerfile])
|
build_args.extend(["-f", dockerfile])
|
||||||
else:
|
else:
|
||||||
|
if custom_dockerfile_given:
|
||||||
|
# custom dockerfile name was also not found in the file system
|
||||||
|
raise OSError(f"Dockerfile not found in {dockerfile}")
|
||||||
raise OSError(f"Dockerfile not found in {ctx}")
|
raise OSError(f"Dockerfile not found in {ctx}")
|
||||||
|
|
||||||
build_args.extend(["-t", cnt["image"]])
|
build_args.extend(["-t", cnt["image"]])
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
test
|
@ -3,3 +3,12 @@ services:
|
|||||||
test:
|
test:
|
||||||
build: ./context
|
build: ./context
|
||||||
image: build-fail-img
|
image: build-fail-img
|
||||||
|
test_no_dockerfile:
|
||||||
|
build:
|
||||||
|
context: ./context_no_file
|
||||||
|
image: busybox
|
||||||
|
test_no_custom_dockerfile:
|
||||||
|
build:
|
||||||
|
context: ./context_no_file
|
||||||
|
dockerfile: Dockerfile-alt
|
||||||
|
image: busybox
|
||||||
|
@ -22,9 +22,48 @@ class TestComposeBuildFail(unittest.TestCase, RunSubprocessMixin):
|
|||||||
"-f",
|
"-f",
|
||||||
compose_yaml_path(),
|
compose_yaml_path(),
|
||||||
"build",
|
"build",
|
||||||
|
"test",
|
||||||
],
|
],
|
||||||
expected_returncode=127,
|
expected_returncode=127,
|
||||||
)
|
)
|
||||||
self.assertIn("RUN this_command_does_not_exist", str(output))
|
self.assertIn("RUN this_command_does_not_exist", str(output))
|
||||||
self.assertIn("this_command_does_not_exist: not found", str(error))
|
self.assertIn("this_command_does_not_exist: not found", str(error))
|
||||||
self.assertIn("while running runtime: exit status 127", str(error))
|
self.assertIn("while running runtime: exit status 127", str(error))
|
||||||
|
|
||||||
|
def test_dockerfile_does_not_exist(self):
|
||||||
|
out, error = self.run_subprocess_assert_returncode(
|
||||||
|
[
|
||||||
|
podman_compose_path(),
|
||||||
|
"-f",
|
||||||
|
compose_yaml_path(),
|
||||||
|
"build",
|
||||||
|
"test_no_dockerfile",
|
||||||
|
],
|
||||||
|
expected_returncode=1,
|
||||||
|
)
|
||||||
|
error = error.decode('utf-8')
|
||||||
|
result = '\n'.join(error.splitlines()[-1:])
|
||||||
|
|
||||||
|
expected_path = os.path.join(os.path.dirname(__file__), "context_no_file")
|
||||||
|
expected = f'OSError: Dockerfile not found in {expected_path}'
|
||||||
|
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
def test_custom_dockerfile_does_not_exist(self):
|
||||||
|
out, error = self.run_subprocess_assert_returncode(
|
||||||
|
[
|
||||||
|
podman_compose_path(),
|
||||||
|
"-f",
|
||||||
|
compose_yaml_path(),
|
||||||
|
"build",
|
||||||
|
"test_no_custom_dockerfile",
|
||||||
|
],
|
||||||
|
expected_returncode=1,
|
||||||
|
)
|
||||||
|
error = error.decode('utf-8')
|
||||||
|
result = '\n'.join(error.splitlines()[-1:])
|
||||||
|
|
||||||
|
expected_path = os.path.join(os.path.dirname(__file__), "context_no_file/Dockerfile-alt")
|
||||||
|
expected = f'OSError: Dockerfile not found in {expected_path}'
|
||||||
|
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user