Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion test/fixtures_isce3.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def isce3_git_repo_image(
dockerfile = git_extract_dockerfile(
base=isce3_env_dev_image_tag,
archive_url=archive,
directory=Path("/src/"),
dst_path=Path("/src/"),
url_reader=url_reader,
)

Expand Down
4 changes: 2 additions & 2 deletions test/test_docker_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_git_dockerfile():
dockerfile = git_extract_dockerfile(
base="base",
archive_url="www.url.com/a.tar.gz",
directory="/",
dst_path="/",
url_reader=url_reader,
)
rough_dockerfile_validity_check(dockerfile=dockerfile)
Expand All @@ -44,7 +44,7 @@ def test_docker_git(
dockerfile = git_extract_dockerfile(
base=init_tag,
archive_url=archive,
directory=Path("/src/"),
dst_path=Path("/src/"),
url_reader=url_reader,
)

Expand Down
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
10 changes: 5 additions & 5 deletions wigwam/_docker_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def git_extract_dockerfile(
base: str,
archive_url: str,
url_reader: URLReader,
directory: str | os.PathLike[str] = Path("repo"),
dst_path: str | os.PathLike[str] = Path("repo"),
) -> str:
"""
Returns a Dockerfile-formatted string with instructions to fetch a Git archive.
Expand All @@ -25,15 +25,15 @@ def git_extract_dockerfile(
The URL of the Git archive. Must be a `tar.gz` file.
url_reader : URLReader
The URL reader program to fetch the archive with.
directory : path-like, optional
The name of the folder to store the repository in. Defaults to "repo".
dst_path : path-like, optional
The prefix of the directory to store the repository in. Defaults to "repo".

Returns
-------
dockerfile : str
The generated Dockerfile.
"""
folder_path_str = os.fspath(directory)
folder_path_str = os.fspath(dst_path)

# Dockerfile preparation:
# Prepare the repository file, ensure proper ownership and permissions.
Expand Down Expand Up @@ -67,7 +67,7 @@ def git_extract_dockerfile(
f"""
RUN {fetch_command} | tar -xvz -C {folder_path_str} --strip-components 1

WORKDIR {directory}
WORKDIR {dst_path}
USER $DEFAULT_USER
"""
).strip()
Expand Down
85 changes: 70 additions & 15 deletions 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 All @@ -45,7 +48,7 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
help='The URL of the Git archive to be fetched. Must be a "tar.gz" file.',
)
archive_params.add_argument(
"--directory",
"--dst-path",
type=Path,
default=Path("/src"),
help="The path to place the contents of the Git archive at on the image.",
Expand Down Expand Up @@ -85,62 +88,62 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
help="Run Docker build with no cache if used.",
)

archive_parser = subparsers.add_parser(
archive_parser: argparse.ArgumentParser = 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")

copy_dir_parser = subparsers.add_parser(
copy_dir_parser: argparse.ArgumentParser = subparsers.add_parser(
"copydir",
parents=[setup_params, no_cache_params],
help="Insert the contents of a directory at the given path.",
formatter_class=help_formatter,
)
add_tag_argument(parser=copy_dir_parser, default="dir-copy")
copy_dir_parser.add_argument(
"--directory",
"--src-path",
"-d",
type=Path,
required=True,
help="The directory to be copied to the image.",
)
copy_dir_parser.add_argument(
"--target-path",
"--dst-path",
"-p",
type=Path,
default=None,
help="The path on the image to copy the source directory to. If not given, "
"the base name of the path given by the directory argument will be used.",
)

config_parser = subparsers.add_parser(
config_parser: argparse.ArgumentParser = subparsers.add_parser(
"cmake-config",
parents=[setup_params, config_params, no_cache_params],
help="Creates an image with a configured compiler.",
formatter_class=help_formatter,
)
add_tag_argument(parser=config_parser, default="configured")

compile_parser = subparsers.add_parser(
compile_parser: argparse.ArgumentParser = subparsers.add_parser(
"cmake-compile",
parents=[setup_params, no_cache_params],
help="Creates an image with the project built.",
formatter_class=help_formatter,
)
add_tag_argument(parser=compile_parser, default="compiled")

install_parser = subparsers.add_parser(
install_parser: argparse.ArgumentParser = subparsers.add_parser(
"cmake-install",
parents=[setup_params, no_cache_params],
help="Creates an image with the project installed.",
formatter_class=help_formatter,
)
add_tag_argument(parser=install_parser, default="installed")

distrib_parser = subparsers.add_parser(
distrib_parser: argparse.ArgumentParser = subparsers.add_parser(
"make-distrib",
parents=[no_cache_params],
help="Creates a distributable image.",
Expand All @@ -151,23 +154,72 @@ def init_build_parsers(subparsers: argparse._SubParsersAction) -> None:
"-t",
default="isce3",
type=str,
help="The complete tag of the Docker image to be created. " 'Default: "isce3"',
help="The complete tag of the Docker image to be created.",
)
distrib_parser.add_argument(
"--base",
"-b",
default="setup-mamba-runtime",
type=str,
help="The complete tag of the Docker image to be created. "
'Default: "setup-mamba-runtime"',
help="The complete tag of the Docker image to be created.",
)
distrib_parser.add_argument(
"--source-tag",
"-s",
default="build-installed",
type=str,
help="The tag or ID of the source image which has the project installed. "
' Defaults to "build-installed".',
help="The tag or ID of the source image which has the project installed.",
)

parser_build_all: argparse.ArgumentParser = 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.",
)
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]-*".',
)
parser_build_all.add_argument(
"--dst-path",
type=Path,
default=Path("/src"),
help="The path to place the contents of the Git archive or copied directory "
"into on the image.",
)
# This group ensures that only one of --archive-url or --src-path is used, since
# this command only builds either the contents of a source directory or the contents
# of a Git archive.
build_all_mutex_group = parser_build_all.add_mutually_exclusive_group(required=True)
build_all_mutex_group.add_argument(
"--src-path",
"-p",
metavar="FILEPATH",
type=str,
default=None,
help="The path to the source prefix on the host to be copied to the image. "
"Cannot be used with --archive-url.",
)
build_all_mutex_group.add_argument(
"--archive-url",
type=str,
metavar="GIT_ARCHIVE",
default=None,
help='The URL of the Git archive to be fetched. Must be a "tar.gz" file. '
"Cannot be used with --src-path.",
)


Expand All @@ -180,6 +232,7 @@ def build_command_names() -> List[str]:
"cmake-compile",
"cmake-install",
"make-distrib",
"build-all",
]


Expand All @@ -196,3 +249,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))
4 changes: 3 additions & 1 deletion wigwam/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def initialize_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(prog=__package__, formatter_class=help_formatter)

# Add arguments
subparsers = parser.add_subparsers(dest="command", required=True)
subparsers: argparse._SubParsersAction = parser.add_subparsers(
dest="command", required=True
)

init_setup_parsers(subparsers, prefix)
init_build_parsers(subparsers)
Expand Down
16 changes: 8 additions & 8 deletions wigwam/cli/setup_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def init_setup_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> N
metavar="REPO_NAME",
)

setup_parser = subparsers.add_parser(
setup_parser: argparse.ArgumentParser = subparsers.add_parser(
"setup", help="Docker image setup commands.", formatter_class=help_formatter
)

setup_subparsers = setup_parser.add_subparsers(
setup_subparsers: argparse._SubParsersAction = setup_parser.add_subparsers(
dest="setup_subcommand", required=True
)

setup_all_parser = setup_subparsers.add_parser(
setup_all_parser: argparse.ArgumentParser = setup_subparsers.add_parser(
"all",
parents=[cuda_run_parse, no_cache_parse],
help="Set up the full Docker image stack.",
Expand Down Expand Up @@ -111,7 +111,7 @@ def init_setup_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> N
help="If used, output informational messages upon completion.",
)

setup_init_parser = setup_subparsers.add_parser(
setup_init_parser: argparse.ArgumentParser = setup_subparsers.add_parser(
"init",
parents=[no_cache_parse],
help="Set up the configuration image.",
Expand All @@ -126,7 +126,7 @@ def init_setup_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> N
)
add_tag_argument(parser=setup_init_parser, default="init")

setup_cuda_parser = setup_subparsers.add_parser(
setup_cuda_parser: argparse.ArgumentParser = setup_subparsers.add_parser(
"cuda",
help="Set up a CUDA image. Designate dev or runtime.",
formatter_class=help_formatter,
Expand Down Expand Up @@ -159,7 +159,7 @@ def init_setup_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> N
)
add_tag_argument(parser=setup_cuda_dev_parser, default="cuda-dev")

setup_conda_parser = setup_subparsers.add_parser(
setup_conda_parser: argparse.ArgumentParser = setup_subparsers.add_parser(
"conda",
help="Set up a conda environment image. Designate dev or runtime.",
formatter_class=help_formatter,
Expand All @@ -168,7 +168,7 @@ def init_setup_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> N
conda_subparsers = setup_conda_parser.add_subparsers(
dest="conda_subcommand", required=True
)
setup_conda_runtime_parser = conda_subparsers.add_parser(
setup_conda_runtime_parser: argparse.ArgumentParser = conda_subparsers.add_parser(
"runtime",
parents=[setup_parse, no_cache_parse],
help="Set up the runtime conda environment image",
Expand All @@ -183,7 +183,7 @@ def init_setup_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> N
)
add_tag_argument(parser=setup_conda_runtime_parser, default="conda-runtime")

setup_conda_dev_parser = conda_subparsers.add_parser(
setup_conda_dev_parser: argparse.ArgumentParser = conda_subparsers.add_parser(
"dev",
parents=[setup_parse, no_cache_parse],
help="Set up the dev conda environment image",
Expand Down
16 changes: 12 additions & 4 deletions wigwam/cli/util_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def init_util_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> No
The image tag prefix.
"""

test_parser = subparsers.add_parser(
test_parser: argparse.ArgumentParser = subparsers.add_parser(
"test", help="Run unit tests on an image.", formatter_class=help_formatter
)
test_parser.add_argument(
Expand All @@ -38,7 +38,7 @@ def init_util_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> No
"--quiet-fail", action="store_true", help="Less verbose output on test failure."
)

dropin_parser = subparsers.add_parser(
dropin_parser: argparse.ArgumentParser = subparsers.add_parser(
"dropin", help="Start a drop-in session.", formatter_class=help_formatter
)
dropin_parser.add_argument(
Expand All @@ -50,8 +50,16 @@ def init_util_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> No
help="Run as the default user on the image. If not used, will run as the "
"current user on the host machine.",
)
dropin_parser.add_argument(
"--no-prefix",
action="store_false",
dest="use_prefix",
default=True,
help="Run as the default user on the image. If not used, will run as the "
"current user on the host machine.",
)

remove_parser = subparsers.add_parser(
remove_parser: argparse.ArgumentParser = subparsers.add_parser(
"remove",
help=f"Remove all Docker images beginning with {prefix}-[IMAGE_TAG] for each "
"image tag provided.",
Expand Down Expand Up @@ -82,7 +90,7 @@ def init_util_parsers(subparsers: argparse._SubParsersAction, prefix: str) -> No
"if not already prefixed.",
)

lockfile_parser = subparsers.add_parser(
lockfile_parser: argparse.ArgumentParser = subparsers.add_parser(
"lockfile",
help="Produce a lockfile for the image.",
formatter_class=help_formatter,
Expand Down
Loading