Skip to content

Commit 0500ffa

Browse files
Added build-all command
1 parent 35c2b1b commit 0500ffa

File tree

2 files changed

+172
-2
lines changed

2 files changed

+172
-2
lines changed

wigwam/cli/build_commands.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from typing import List
44

55
from ..commands import (
6+
build_all,
67
cmake_install,
78
compile_cmake,
89
configure_cmake,
910
copy_dir,
1011
get_archive,
1112
)
13+
from ..defaults import universal_tag_prefix
1214
from ._utils import add_tag_argument, help_formatter
1315

1416

@@ -25,6 +27,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
2527
cmake-config,
2628
cmake-compile,
2729
cmake-install,
30+
build-all,
2831
and more are being added.
2932
3033
Parameters
@@ -87,7 +90,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
8790
archive_parser = subparsers.add_parser(
8891
"get-archive",
8992
parents=[setup_params, archive_params, no_cache_params],
90-
help="Set up the GitHub repository image, in [USER]/[REPO_NAME] format.",
93+
help="Set up the GitHub repository image.",
9194
formatter_class=help_formatter,
9295
)
9396
add_tag_argument(parser=archive_parser, default="repo")
@@ -139,10 +142,63 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
139142
)
140143
add_tag_argument(parser=install_parser, default="installed")
141144

145+
parser_build_all = subparsers.add_parser(
146+
"build-all",
147+
parents=[config_params, no_cache_params],
148+
help="Performs the complete compilation process, from initial GitHub checkout "
149+
"to installation.",
150+
formatter_class=help_formatter,
151+
)
152+
parser_build_all.add_argument(
153+
"--base",
154+
"-b",
155+
type=str,
156+
default="setup-mamba-dev",
157+
help='The name of the parent Docker image. Default is "setup-mamba-dev".',
158+
)
159+
parser_build_all.add_argument(
160+
"--tag",
161+
"-t",
162+
default="build",
163+
type=str,
164+
help="The sub-prefix of the Docker images to be created. Generated images will "
165+
f'have tags fitting "{universal_tag_prefix()}-[TAG]-*". Default: "build"',
166+
)
167+
parser_build_all.add_argument(
168+
"--copy-path",
169+
"-p",
170+
metavar="FILEPATH",
171+
type=str,
172+
default=None,
173+
help="The path to be copied to the image. If used, no github image will be "
174+
"copied. Defaults to None.",
175+
)
176+
parser_build_all.add_argument(
177+
"--archive-url",
178+
type=str,
179+
metavar="GIT_ARCHIVE",
180+
help='The URL of the Git archive to be fetched. Must be a "tar.gz" file.'
181+
"Ignored if --copy-path is used.",
182+
)
183+
parser_build_all.add_argument(
184+
"--directory",
185+
type=Path,
186+
default=Path("/src"),
187+
help="The path to place the contents of the Git archive or copied directory "
188+
"into on the image.",
189+
)
190+
142191

143192
def build_command_names() -> List[str]:
144193
"""Returns a list of all build command names."""
145-
return ["get-archive", "copydir", "cmake-config", "cmake-compile", "cmake-install"]
194+
return [
195+
"get-archive",
196+
"copydir",
197+
"cmake-config",
198+
"cmake-compile",
199+
"cmake-install",
200+
"build-all",
201+
]
146202

147203

148204
def run_build(args: argparse.Namespace, command: str) -> None:
@@ -156,3 +212,5 @@ def run_build(args: argparse.Namespace, command: str) -> None:
156212
compile_cmake(**vars(args))
157213
elif command == "cmake-install":
158214
cmake_install(**vars(args))
215+
elif command == "build-all":
216+
build_all(**vars(args))

wigwam/commands.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,118 @@ def cmake_install(tag: str, base: str, no_cache: bool = False) -> Image:
252252
)
253253

254254

255+
def build_all(
256+
tag: str,
257+
base: str,
258+
copy_path: os.PathLike | None,
259+
archive_url: str | None,
260+
directory: os.PathLike,
261+
build_type: str,
262+
no_cuda: bool,
263+
no_cache: bool = False,
264+
) -> dict[str, Image]:
265+
"""
266+
Fully compiles and builds a Git repo with cmake.
267+
268+
Parameters
269+
----------
270+
tag : str
271+
The image tag prefix.
272+
base : str
273+
The base image tag.
274+
copy_path : str
275+
The path to a directory to copy to an image.
276+
archive_url : str or None
277+
The URL of the Git archive to install on an image. No archive will be installed
278+
if `copy_dir` is given.
279+
directory : str
280+
The path to place the contents of the Git archive or copied directory to.
281+
build_type : str
282+
The CMake build type. See
283+
`here <https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html>`_
284+
for possible values.
285+
no_cuda : bool
286+
If True, build without CUDA.
287+
no_cache : bool, optional
288+
Run Docker build with no cache if True. Defaults to False.
289+
290+
Returns
291+
-------
292+
dict[str, Image]
293+
A dict of images produced by this process.
294+
"""
295+
296+
prefixed_tag: str = prefix_image_tag(tag)
297+
prefixed_base_tag: str = prefix_image_tag(base)
298+
299+
images: dict[str, Image] = {}
300+
301+
# If the user has indicated a path to copy, the code should copy that.
302+
# Otherwise, the code should fetch a git repository.
303+
is_insert = copy_path is not None
304+
305+
initial_tag: str = ""
306+
if is_insert:
307+
assert isinstance(copy_path, str)
308+
path_absolute = os.path.abspath(copy_path)
309+
if os.path.isdir(copy_path):
310+
top_dir = os.path.basename(path_absolute)
311+
else:
312+
top_dir = os.path.basename(os.path.dirname(path_absolute))
313+
314+
insert_tag = f"{prefixed_tag}-file-{top_dir}"
315+
insert_image = copy_dir(
316+
base=prefixed_base_tag,
317+
tag=insert_tag,
318+
directory=directory,
319+
target_path=copy_path,
320+
no_cache=no_cache,
321+
)
322+
images[insert_tag] = insert_image
323+
initial_tag = insert_tag
324+
else:
325+
git_repo_tag = f"{prefixed_tag}-git-repo"
326+
assert archive_url is not None
327+
328+
git_repo_image = get_archive(
329+
base=prefixed_base_tag,
330+
tag=git_repo_tag,
331+
archive_url=archive_url,
332+
directory=directory,
333+
no_cache=no_cache,
334+
)
335+
images[git_repo_tag] = git_repo_image
336+
initial_tag = git_repo_tag
337+
338+
configure_tag = f"{prefixed_tag}-configured"
339+
configure_image = configure_cmake(
340+
tag=configure_tag,
341+
base=initial_tag,
342+
build_type=build_type,
343+
no_cuda=no_cuda,
344+
no_cache=no_cache,
345+
)
346+
images[configure_tag] = configure_image
347+
348+
build_tag = f"{prefixed_tag}-built"
349+
build_image = compile_cmake(
350+
tag=build_tag,
351+
base=configure_tag,
352+
no_cache=no_cache,
353+
)
354+
images[build_tag] = build_image
355+
356+
install_tag = f"{prefixed_tag}-installed"
357+
install_image = cmake_install(
358+
tag=install_tag,
359+
base=build_tag,
360+
no_cache=no_cache,
361+
)
362+
images[install_tag] = install_image
363+
364+
return images
365+
366+
255367
def dropin(tag: str) -> None:
256368
"""
257369
Initiates a drop-in session on an image.

0 commit comments

Comments
 (0)