From 271d72037ca84c6e2dedbb2d051f31a5b01a3c9c Mon Sep 17 00:00:00 2001 From: chriscohoat Date: Sun, 24 Mar 2024 12:04:55 -0400 Subject: [PATCH 1/2] Added the ability to customize the image prefix, which allows the use of other Docker image locations. --- pyproject.toml | 2 +- toltec/__main__.py | 13 ++++++++++++- toltec/builder.py | 20 ++++++++++++++++---- toltec/hooks/strip.py | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index eaa8bb7..21304f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "toltecmk" -version = "0.3.0" +version = "0.3.1" authors = [ { name="Mattéo Delabre", email="git.matteo@delab.re" }, { name="Eeems", email="eeems@eeems.email" }, diff --git a/toltec/__main__.py b/toltec/__main__.py index 26f6968..34057e8 100644 --- a/toltec/__main__.py +++ b/toltec/__main__.py @@ -73,6 +73,17 @@ def main() -> int: # pylint:disable=too-many-branches either a dot or a slash""", ) + # add an argument for image_prefix, which defaults to "ghcr.io/toltec-dev/" + + parser.add_argument( + "-I", + "--image-prefix", + metavar="IMAGEPREFIX", + default="ghcr.io/toltec-dev/", + help="""prefix to use for the container image name (default: + ghcr.io/toltec-dev/)""", + ) + util.argparse_add_verbose(parser) util.argparse_add_warning(parser) args = parser.parse_args() @@ -80,7 +91,7 @@ def main() -> int: # pylint:disable=too-many-branches recipe_bundle = parse_recipe(args.recipe_dir) - with Builder(args.work_dir, args.dist_dir) as builder: + with Builder(args.work_dir, args.dist_dir, args.image_prefix) as builder: if args.hook: for ident in args.hook: if ident and ident[0] in (".", "/"): diff --git a/toltec/builder.py b/toltec/builder.py index bfd53ea..70546e1 100644 --- a/toltec/builder.py +++ b/toltec/builder.py @@ -31,9 +31,20 @@ class Builder: # pylint: disable=too-few-public-methods URL_REGEX = re.compile(r"[a-z]+://") # Prefix for all Toltec Docker images - IMAGE_PREFIX = "ghcr.io/toltec-dev/" - - def __init__(self, work_dir: str, dist_dir: str) -> None: + # For example, https://ghcr.io/toltec-dev/rust:v3 which resolves to + # https://github.com/toltec-dev/toolchain/pkgs/container/rust + DEFAULT_IMAGE_PREFIX = "ghcr.io/toltec-dev/" + + def get_image_prefix(self) -> str: + """Get the prefix for all Toltec Docker images.""" + if self.image_prefix: + # If the image prefix doesn't end with a slash, add one. + if not self.image_prefix.endswith("/"): + return self.image_prefix + "/" + return self.image_prefix + return self.DEFAULT_IMAGE_PREFIX + + def __init__(self, work_dir: str, dist_dir: str, image_prefix: str) -> None: """ Create a builder helper. @@ -42,6 +53,7 @@ def __init__(self, work_dir: str, dist_dir: str) -> None: """ self.work_dir = work_dir self.dist_dir = dist_dir + self.image_prefix = image_prefix try: self.docker = docker.from_env() @@ -348,7 +360,7 @@ def _build(self, recipe: Recipe, src_dir: str) -> None: logs = bash.run_script_in_container( self.docker, - image=self.IMAGE_PREFIX + recipe.image, + image=self.get_image_prefix() + recipe.image, mounts=[ docker.types.Mount( type="bind", diff --git a/toltec/hooks/strip.py b/toltec/hooks/strip.py index 7cb0e0d..46d6014 100644 --- a/toltec/hooks/strip.py +++ b/toltec/hooks/strip.py @@ -45,7 +45,7 @@ def run_in_container( """Run a script in a container and log output""" logs = bash.run_script_in_container( builder.docker, - image=builder.IMAGE_PREFIX + TOOLCHAIN, + image=builder.get_image_prefix() + TOOLCHAIN, mounts=[ docker.types.Mount( type="bind", From c74200e5e30994f1f4c170edd3a3a047b866a125 Mon Sep 17 00:00:00 2001 From: chriscohoat Date: Tue, 26 Mar 2024 09:49:58 -0400 Subject: [PATCH 2/2] Updated to latest toolchain version --- toltec/hooks/strip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toltec/hooks/strip.py b/toltec/hooks/strip.py index 46d6014..8a03401 100644 --- a/toltec/hooks/strip.py +++ b/toltec/hooks/strip.py @@ -19,7 +19,7 @@ logger = logging.getLogger(__name__) MOUNT_SRC = "/src" -TOOLCHAIN = "toolchain:v1.3.1" +TOOLCHAIN = "toolchain:latest" def walk_elfs(src_dir: str, for_each: Callable) -> None: