Skip to content

Commit

Permalink
collapse mod/img naming for single-image modules
Browse files Browse the repository at this point in the history
vanity purposes lol; don't want ocf/transpire-transpire for example
  • Loading branch information
turtlebasket committed Feb 6, 2025
1 parent 7f7677e commit ace4c6b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions transpire/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import pathlib
import tomllib
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Dict, cast

from transpire.internal.config import GitModuleConfig
from transpire.internal.context import get_app_context
from transpire.types import Image, Module, ContainerRegistry
from transpire.types import ContainerRegistry, Image, Module


def get_revision() -> str | None:
Expand All @@ -19,15 +16,31 @@ def get_images() -> Dict[str, Image]:
return {im.name: im for im in get_app_context().images}


def get_image_tag(name: str, module: Module | None = None) -> str:
"""Retrieves the current Transpire module's images."""
def get_image_tag(
name: str, module: Module | None = None, collapse_image_name: bool = True
) -> str:
"""
Retrieves the current Transpire module's images.
:param name: The name of the image to retrieve.
:param module: The module to retrieve the image from.
:param collapse_image_name: Whether to combine the module and image name when they
are equal. Changes ocf/abc-abc to ocf/abc) when the module only includes one image
of the same name. This is the default behavior for GHCR.
"""
if module is None:
module = get_app_context()
for im in module.images:
if im.name != name:
continue
match im.registry:
case ContainerRegistry.ghcr:
if (
collapse_image_name
and module.name == im.name
and len(module.images) == 1
):
return f"ghcr.io/ocf/{module.name}:{module.revision}"
return f"ghcr.io/ocf/{module.name}-{im.name}:{module.revision}"
case ContainerRegistry.harbor:
return f"harbor.ocf.berkeley.edu/ocf/{module.name}/{im.name}:{module.revision}"
Expand Down

0 comments on commit ace4c6b

Please sign in to comment.