5
5
from subprocess import DEVNULL , PIPE , run
6
6
from typing import Iterable , List
7
7
8
- from ._docker_cmake import cmake_config_dockerfile
8
+ from ._docker_cmake import cmake_build_dockerfile , cmake_config_dockerfile
9
9
from ._docker_git import git_extract_dockerfile
10
10
from ._docker_insert import insert_dir_dockerfile
11
11
from ._docker_mamba import mamba_lockfile_command
12
12
from ._image import Image
13
13
from ._url_reader import URLReader
14
- from ._utils import image_command_check , is_conda_pkg_name , temp_image
15
- from .defaults import universal_tag_prefix
14
+ from ._utils import image_command_check , is_conda_pkg_name , prefix_image_tag , temp_image
16
15
17
16
18
17
def get_archive (
@@ -54,11 +53,11 @@ def get_archive(
54
53
with temp_image (base ) as temp_img :
55
54
_ , url_reader , _ = image_command_check (temp_img )
56
55
57
- prefix = universal_tag_prefix ( )
58
- img_tag = tag if tag . startswith ( prefix ) else f" { prefix } - { tag } "
56
+ img_tag = prefix_image_tag ( tag )
57
+ base_tag = prefix_image_tag ( base )
59
58
60
59
dockerfile = git_extract_dockerfile (
61
- base = base ,
60
+ base = base_tag ,
62
61
directory = directory ,
63
62
archive_url = archive_url ,
64
63
url_reader = url_reader ,
@@ -106,8 +105,7 @@ def copy_dir(
106
105
The generated image.
107
106
"""
108
107
109
- prefix = universal_tag_prefix ()
110
- img_tag = tag if tag .startswith (prefix ) else f"{ prefix } -{ tag } "
108
+ img_tag = prefix_image_tag (tag )
111
109
112
110
dir_str = os .fspath (directory )
113
111
@@ -128,8 +126,9 @@ def copy_dir(
128
126
129
127
# Generate the dockerfile. The source directory will be "." since the build context
130
128
# will be at the source path when the image is built.
129
+ base_tag = prefix_image_tag (base )
131
130
dockerfile : str = insert_dir_dockerfile (
132
- base = base ,
131
+ base = base_tag ,
133
132
target_dir = target_dir ,
134
133
source_dir = "." ,
135
134
)
@@ -176,17 +175,49 @@ def configure_cmake(
176
175
Image
177
176
The generated image.
178
177
"""
178
+ base_tag = prefix_image_tag (base )
179
+
179
180
dockerfile : str = cmake_config_dockerfile (
180
- base = base ,
181
+ base = base_tag ,
181
182
build_type = build_type ,
182
183
with_cuda = not no_cuda ,
183
184
)
184
185
185
- prefix = universal_tag_prefix ()
186
- img_tag = tag if tag .startswith (prefix ) else f"{ prefix } -{ tag } "
186
+ img_tag = prefix_image_tag (tag )
187
187
return Image .build (tag = img_tag , dockerfile_string = dockerfile , no_cache = no_cache )
188
188
189
189
190
+ def compile_cmake (tag : str , base : str , no_cache : bool = False ) -> Image :
191
+ """
192
+ Produces an image with the working directory compiled.
193
+
194
+ Parameters
195
+ ----------
196
+ tag : str
197
+ The image tag.
198
+ base : str
199
+ The base image tag.
200
+ no_cache : bool, optional
201
+ Run Docker build with no cache if True. Defaults to False.
202
+
203
+ Returns
204
+ -------
205
+ Image
206
+ The generated image.
207
+ """
208
+
209
+ prefixed_tag : str = prefix_image_tag (tag )
210
+ prefixed_base_tag : str = prefix_image_tag (base )
211
+
212
+ dockerfile : str = cmake_build_dockerfile (base = prefixed_base_tag )
213
+
214
+ return Image .build (
215
+ tag = prefixed_tag ,
216
+ dockerfile_string = dockerfile ,
217
+ no_cache = no_cache ,
218
+ )
219
+
220
+
190
221
def dropin (tag : str ) -> None :
191
222
"""
192
223
Initiates a drop-in session on an image.
@@ -196,6 +227,7 @@ def dropin(tag: str) -> None:
196
227
tag : str
197
228
The tag or ID of the image.
198
229
"""
230
+ tag = prefix_image_tag (tag )
199
231
image : Image = Image (tag )
200
232
201
233
image .drop_in ()
@@ -234,18 +266,18 @@ def remove(
234
266
235
267
# Search for and delete all images matching each tag or wildcard.
236
268
for tag in tags :
237
- prefix = universal_tag_prefix ()
238
- search = tag if ( tag . startswith ( prefix ) or ignore_prefix ) else f" { prefix } - { tag } "
269
+ if not ignore_prefix :
270
+ tag = prefix_image_tag ( tag )
239
271
if verbose :
240
- print (f"Attempting removal for tag: { search } " )
272
+ print (f"Attempting removal for tag: { tag } " )
241
273
242
274
# Search for all images whose name matches this tag, acquire a list
243
- search_command = split (f'docker images --filter=reference="{ search } " -q' )
275
+ search_command = split (f'docker images --filter=reference="{ tag } " -q' )
244
276
search_result = run (search_command , text = True , stdout = PIPE , stderr = output )
245
277
# An empty return indicates that no such images were found. Skip to the next.
246
278
if search_result .stdout == "" :
247
279
if verbose :
248
- print (f"No images found matching pattern { search } . Proceeding." )
280
+ print (f"No images found matching pattern { tag } . Proceeding." )
249
281
continue
250
282
# The names come in a list delimited by newlines. Reform this to be delimited
251
283
# by spaces to use with `Docker rmi`.
@@ -277,6 +309,7 @@ def make_lockfile(
277
309
The name of the environment. Defaults to "base".
278
310
"""
279
311
cmd : str = mamba_lockfile_command (env_name = env_name )
312
+ tag = prefix_image_tag (tag )
280
313
image : Image = Image (tag )
281
314
lockfile : str = image .run (command = cmd , stdout = PIPE )
282
315
assert isinstance (lockfile , str )
0 commit comments