Skip to content

Commit e900ab7

Browse files
Brandon Duane Walkermr-c
Brandon Duane Walker
authored andcommitted
add test for building Dockerfile
1 parent 078d865 commit e900ab7

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

cwltool/docker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def get_image(
138138
dockerfile_dir,
139139
]
140140
_logger.info(str(cmd))
141-
subprocess.check_call(cmd, stdout=sys.stderr) # nosec
141+
# check_call doesn't work when using pytest
142+
subprocess.run(cmd, check=True, stdout=sys.stderr, stderr=subprocess.PIPE)
142143
found = True
143144

144145
if (force_pull or not found) and pull_image:

tests/test_tmpdir.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,65 @@ def test_dockerfile_tmpdir_prefix(tmp_path: Path, monkeypatch: pytest.MonkeyPatc
168168
assert (subdir / "Dockerfile").exists()
169169

170170

171+
@needs_docker
172+
def test_dockerfile_build(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
173+
"""Test that DockerCommandLineJob.get_image builds a Dockerfile."""
174+
monkeypatch.setattr(target=subprocess, name="check_call", value=lambda *args, **kwargs: True)
175+
(tmp_path / "out").mkdir()
176+
tmp_outdir_prefix = tmp_path / "out" / "1"
177+
(tmp_path / "3").mkdir()
178+
tmpdir_prefix = str(tmp_path / "3" / "ttmp")
179+
runtime_context = RuntimeContext(
180+
{"tmpdir_prefix": tmpdir_prefix, "user_space_docker_cmd": None}
181+
)
182+
builder = Builder(
183+
{},
184+
[],
185+
[],
186+
{},
187+
schema.Names(),
188+
[],
189+
[],
190+
{},
191+
None,
192+
None,
193+
StdFsAccess,
194+
StdFsAccess(""),
195+
None,
196+
0.1,
197+
False,
198+
False,
199+
False,
200+
"no_listing",
201+
runtime_context.get_outdir(),
202+
runtime_context.get_tmpdir(),
203+
runtime_context.get_stagedir(),
204+
INTERNAL_VERSION,
205+
"docker",
206+
)
207+
208+
docker_image_id = sys._getframe().f_code.co_name
209+
210+
assert DockerCommandLineJob(
211+
builder, {}, CommandLineTool.make_path_mapper, [], [], ""
212+
).get_image(
213+
{
214+
"class": "DockerRequirement",
215+
"dockerFile": "FROM debian:stable-slim",
216+
"dockerImageId": docker_image_id,
217+
},
218+
pull_image=False,
219+
force_pull=False,
220+
tmp_outdir_prefix=str(tmp_outdir_prefix),
221+
)
222+
output = subprocess.check_output(
223+
["docker", "images", "--quiet", docker_image_id], stderr=subprocess.STDOUT, text=True
224+
)
225+
226+
# If the output is empty, the image doesn't exist
227+
assert output.strip(), f"Docker image {docker_image_id} does not exist"
228+
229+
171230
@needs_singularity
172231
def test_dockerfile_singularity_build(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
173232
"""Test that SingularityCommandLineJob.get_image builds a Dockerfile with Singularity."""

0 commit comments

Comments
 (0)