@@ -168,6 +168,65 @@ def test_dockerfile_tmpdir_prefix(tmp_path: Path, monkeypatch: pytest.MonkeyPatc
168
168
assert (subdir / "Dockerfile" ).exists ()
169
169
170
170
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
+
171
230
@needs_singularity
172
231
def test_dockerfile_singularity_build (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ) -> None :
173
232
"""Test that SingularityCommandLineJob.get_image builds a Dockerfile with Singularity."""
0 commit comments