Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom image prefixes #45

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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 pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "toltecmk"
version = "0.3.0"
version = "0.3.1"
authors = [
{ name="Mattéo Delabre", email="[email protected]" },
{ name="Eeems", email="[email protected]" },
Expand Down
13 changes: 12 additions & 1 deletion toltec/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ 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()
util.setup_logging(args)

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 (".", "/"):
Expand Down
20 changes: 16 additions & 4 deletions toltec/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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()
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions toltec/hooks/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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",
Expand Down