Add support for dockerfile_inline

Fixes #864

Signed-off-by: Zeglius <33781398+Zeglius@users.noreply.github.com>
This commit is contained in:
Zeglius
2025-01-22 15:53:34 +00:00
committed by Povilas Kanapickas
parent d79ff01e77
commit 105e390f6b
3 changed files with 72 additions and 15 deletions

View File

@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
import os
import unittest
from unittest import mock
@ -156,3 +157,26 @@ class TestContainerToBuildArgs(unittest.TestCase):
'.',
],
)
def test_dockerfile_inline(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['build']['dockerfile_inline'] = "FROM busybox\nRUN echo 'hello world'"
args = get_minimal_args()
cleanup_callbacks = []
args = container_to_build_args(
c, cnt, args, lambda path: True, cleanup_callbacks=cleanup_callbacks
)
temp_dockerfile = args[args.index("-f") + 1]
self.assertTrue(os.path.exists(temp_dockerfile))
with open(temp_dockerfile, "rt") as file:
contents = file.read()
self.assertEqual(contents, "FROM busybox\n" + "RUN echo 'hello world'")
for c in cleanup_callbacks:
c()
self.assertFalse(os.path.exists(temp_dockerfile))