|
23 | 23 | import podman.tests.integration.base as base |
24 | 24 | from podman import PodmanClient |
25 | 25 | from podman.domain.images import Image |
26 | | -from podman.errors import APIError, ImageNotFound |
| 26 | +from podman.errors import APIError, ImageNotFound, PodmanError |
27 | 27 |
|
28 | 28 |
|
29 | 29 | # @unittest.skipIf(os.geteuid() != 0, 'Skipping, not running as root') |
@@ -144,6 +144,42 @@ def test_build(self): |
144 | 144 | self.assertIsNotNone(image) |
145 | 145 | self.assertIsNotNone(image.id) |
146 | 146 |
|
| 147 | + def test_build_with_context(self): |
| 148 | + context = io.BytesIO() |
| 149 | + with tarfile.open(fileobj=context, mode="w") as tar: |
| 150 | + |
| 151 | + def add_file(name: str, content: str): |
| 152 | + binary_content = content.encode("utf-8") |
| 153 | + fileobj = io.BytesIO(binary_content) |
| 154 | + tarinfo = tarfile.TarInfo(name=name) |
| 155 | + tarinfo.size = len(binary_content) |
| 156 | + tar.addfile(tarinfo, fileobj) |
| 157 | + |
| 158 | + # Use a non-standard Dockerfile name to test the 'dockerfile' argument |
| 159 | + add_file( |
| 160 | + "MyDockerfile", ("FROM quay.io/libpod/alpine_labels:latest\nCOPY example.txt .\n") |
| 161 | + ) |
| 162 | + add_file("example.txt", "This is an example file.\n") |
| 163 | + |
| 164 | + # Rewind to the start of the generated file so we can read it |
| 165 | + context.seek(0) |
| 166 | + |
| 167 | + with self.assertRaises(PodmanError) as e: |
| 168 | + # If requesting a custom context, must provide the context as `fileobj` |
| 169 | + self.client.images.build(custom_context=True, path='invalid') |
| 170 | + |
| 171 | + with self.assertRaises(PodmanError) as e: |
| 172 | + # If requesting a custom context, currently must specify the dockerfile name |
| 173 | + self.client.images.build(custom_context=True, fileobj=context) |
| 174 | + |
| 175 | + image, stream = self.client.images.build( |
| 176 | + fileobj=context, |
| 177 | + dockerfile="MyDockerfile", |
| 178 | + custom_context=True, |
| 179 | + ) |
| 180 | + self.assertIsNotNone(image) |
| 181 | + self.assertIsNotNone(image.id) |
| 182 | + |
147 | 183 | @unittest.skipIf(platform.architecture()[0] == "32bit", "no 32-bit image available") |
148 | 184 | def test_pull_stream(self): |
149 | 185 | generator = self.client.images.pull("ubi8", tag="latest", stream=True) |
|
0 commit comments