Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wigwam/_docker_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def generate_runtime_dockerfile(
).strip()
+ "\n\n"
+ install_lines
+ "\n\n"
+ "USER $DEFAULT_USER"
)

Expand Down
54 changes: 53 additions & 1 deletion wigwam/cli/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from typing import List

from ..commands import (
build_all,
cmake_install,
compile_cmake,
configure_cmake,
copy_dir,
get_archive,
make_distrib,
)
from ..defaults import universal_tag_prefix
from ._utils import add_tag_argument, help_formatter


Expand All @@ -26,6 +28,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
cmake-config,
cmake-compile,
cmake-install,
build-all,
and more are being added.

Parameters
Expand Down Expand Up @@ -88,7 +91,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
archive_parser = subparsers.add_parser(
"get-archive",
parents=[setup_params, archive_params, no_cache_params],
help="Set up the GitHub repository image, in [USER]/[REPO_NAME] format.",
help="Set up the GitHub repository image.",
formatter_class=help_formatter,
)
add_tag_argument(parser=archive_parser, default="repo")
Expand Down Expand Up @@ -170,6 +173,52 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
' Defaults to "build-installed".',
)

parser_build_all = subparsers.add_parser(
"build-all",
parents=[config_params, no_cache_params],
help="Performs the complete compilation process, from initial GitHub checkout "
"to installation.",
formatter_class=help_formatter,
)
parser_build_all.add_argument(
"--base",
"-b",
type=str,
default="setup-mamba-dev",
help='The name of the parent Docker image. Default is "setup-mamba-dev".',
)
parser_build_all.add_argument(
"--tag",
"-t",
default="build",
type=str,
help="The sub-prefix of the Docker images to be created. Generated images will "
f'have tags fitting "{universal_tag_prefix()}-[TAG]-*". Default: "build"',
)
parser_build_all.add_argument(
"--copy-path",
"-p",
metavar="FILEPATH",
type=str,
default=None,
help="The path to be copied to the image. If used, no github image will be "
"copied. Defaults to None.",
)
parser_build_all.add_argument(
"--archive-url",
type=str,
metavar="GIT_ARCHIVE",
help='The URL of the Git archive to be fetched. Must be a "tar.gz" file.'
"Ignored if --copy-path is used.",
)
parser_build_all.add_argument(
"--directory",
type=Path,
default=Path("/src"),
help="The path to place the contents of the Git archive or copied directory "
"into on the image.",
)


def build_command_names() -> List[str]:
"""Returns a list of all build command names."""
Expand All @@ -180,6 +229,7 @@ def build_command_names() -> List[str]:
"cmake-compile",
"cmake-install",
"make-distrib",
"build-all",
]


Expand All @@ -196,3 +246,5 @@ def run_build(args: argparse.Namespace, command: str) -> None:
cmake_install(**vars(args))
elif command == "make-distrib":
make_distrib(**vars(args))
elif command == "build-all":
build_all(**vars(args))
112 changes: 112 additions & 0 deletions wigwam/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,118 @@ def make_distrib(tag: str, base: str, source_tag: str, no_cache: bool = False) -
return Image.build(tag=tag, dockerfile_string=dockerfile, no_cache=no_cache)


def build_all(
tag: str,
base: str,
copy_path: os.PathLike | None,
archive_url: str | None,
directory: os.PathLike,
build_type: str,
no_cuda: bool,
no_cache: bool = False,
) -> dict[str, Image]:
"""
Fully compiles and builds a Git repo with cmake.

Parameters
----------
tag : str
The image tag prefix.
base : str
The base image tag.
copy_path : str
The path to a directory to copy to an image.
archive_url : str or None
The URL of the Git archive to install on an image. No archive will be installed
if `copy_dir` is given.
directory : str
The path to place the contents of the Git archive or copied directory to.
build_type : str
The CMake build type. See
`here <https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html>`_
for possible values.
no_cuda : bool
If True, build without CUDA.
no_cache : bool, optional
Run Docker build with no cache if True. Defaults to False.

Returns
-------
dict[str, Image]
A dict of images produced by this process.
"""

prefixed_tag: str = prefix_image_tag(tag)
prefixed_base_tag: str = prefix_image_tag(base)

images: dict[str, Image] = {}

# If the user has indicated a path to copy, the code should copy that.
# Otherwise, the code should fetch a git repository.
is_insert = copy_path is not None

initial_tag: str = ""
if is_insert:
assert isinstance(copy_path, str)
path_absolute = os.path.abspath(copy_path)
if os.path.isdir(copy_path):
top_dir = os.path.basename(path_absolute)
else:
top_dir = os.path.basename(os.path.dirname(path_absolute))

insert_tag = f"{prefixed_tag}-file-{top_dir}"
insert_image = copy_dir(
base=prefixed_base_tag,
tag=insert_tag,
directory=directory,
target_path=copy_path,
no_cache=no_cache,
)
images[insert_tag] = insert_image
initial_tag = insert_tag
else:
git_repo_tag = f"{prefixed_tag}-git-repo"
assert archive_url is not None

git_repo_image = get_archive(
base=prefixed_base_tag,
tag=git_repo_tag,
archive_url=archive_url,
directory=directory,
no_cache=no_cache,
)
images[git_repo_tag] = git_repo_image
initial_tag = git_repo_tag

configure_tag = f"{prefixed_tag}-configured"
configure_image = configure_cmake(
tag=configure_tag,
base=initial_tag,
build_type=build_type,
no_cuda=no_cuda,
no_cache=no_cache,
)
images[configure_tag] = configure_image

build_tag = f"{prefixed_tag}-built"
build_image = compile_cmake(
tag=build_tag,
base=configure_tag,
no_cache=no_cache,
)
images[build_tag] = build_image

install_tag = f"{prefixed_tag}-installed"
install_image = cmake_install(
tag=install_tag,
base=build_tag,
no_cache=no_cache,
)
images[install_tag] = install_image

return images


def test(
tag: str,
output_xml: os.PathLike[str] | str,
Expand Down