1
1
import pathlib
2
2
import tomllib
3
- from dataclasses import dataclass
4
- from datetime import datetime , timezone
5
3
from typing import Dict , cast
6
4
7
- from transpire .internal .config import GitModuleConfig
8
5
from transpire .internal .context import get_app_context
9
- from transpire .types import Image , Module , ContainerRegistry
6
+ from transpire .types import ContainerRegistry , Image , Module
10
7
11
8
12
9
def get_revision () -> str | None :
@@ -19,15 +16,31 @@ def get_images() -> Dict[str, Image]:
19
16
return {im .name : im for im in get_app_context ().images }
20
17
21
18
22
- def get_image_tag (name : str , module : Module | None = None ) -> str :
23
- """Retrieves the current Transpire module's images."""
19
+ def get_image_tag (
20
+ name : str , module : Module | None = None , collapse_image_name : bool = True
21
+ ) -> str :
22
+ """
23
+ Retrieves the current Transpire module's images.
24
+
25
+ :param name: The name of the image to retrieve.
26
+ :param module: The module to retrieve the image from.
27
+ :param collapse_image_name: Whether to combine the module and image name when they
28
+ are equal. Changes ocf/abc-abc to ocf/abc) when the module only includes one image
29
+ of the same name. This is the default behavior for GHCR.
30
+ """
24
31
if module is None :
25
32
module = get_app_context ()
26
33
for im in module .images :
27
34
if im .name != name :
28
35
continue
29
36
match im .registry :
30
37
case ContainerRegistry .ghcr :
38
+ if (
39
+ collapse_image_name
40
+ and module .name == im .name
41
+ and len (module .images ) == 1
42
+ ):
43
+ return f"ghcr.io/ocf/{ module .name } :{ module .revision } "
31
44
return f"ghcr.io/ocf/{ module .name } -{ im .name } :{ module .revision } "
32
45
case ContainerRegistry .harbor :
33
46
return f"harbor.ocf.berkeley.edu/ocf/{ module .name } /{ im .name } :{ module .revision } "
0 commit comments