Skip to content

Commit

Permalink
actions: remove the image namer concept from bake-metadata.py
Browse files Browse the repository at this point in the history
  • Loading branch information
multun committed May 29, 2024
1 parent 08271f1 commit cd1ed89
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions .github/scripts/bake-metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from abc import ABC, abstractmethod


EDGE_PREFIX = "ghcr.io/openrailassociation/osrd-edge/"
RELEASE_PREFIX = "ghcr.io/openrailassociation/osrd-stable/"
DEFAULT_EDGE_NAMESPACE = "ghcr.io/openrailassociation/osrd-edge/"
DEFAULT_RELEASE_NAMESPACE = "ghcr.io/openrailassociation/osrd-stable/"


PROTECTED_BRANCHES = {"dev", "staging", "prod"}
Expand Down Expand Up @@ -69,21 +69,6 @@ def registry_cache(image: str) -> str:
return f"type=registry,mode=max,ref={image}-cache"


def edge_image(target: Target) -> str:
return f"{EDGE_PREFIX}osrd-{target.image}"


def release_image(target: Target) -> str:
return f"{RELEASE_PREFIX}osrd-{target.image}"


ImageNamer = Callable[[Target], str]


def tag(target: Target, version: str, namer: ImageNamer = edge_image) -> str:
return f"{namer(target)}:{version}{target.suffix}"


class BaseEvent(ABC):
@abstractmethod
def version_string(self) -> str:
Expand All @@ -93,13 +78,16 @@ def version_string(self) -> str:
def get_stable_version(self) -> str:
pass

def get_stable_image_namer(self) -> ImageNamer:
return edge_image
def get_namespace(self) -> str:
return DEFAULT_EDGE_NAMESPACE

def tag(self, target: Target, version: str) -> str:
image_name = f"{self.get_namespace()}/osrd-{target.image}"
return f"{image_name}:{version}{target.suffix}"

def get_stable_tag(self, target: Target) -> str:
version = self.get_stable_version()
namer = self.get_stable_image_namer()
return tag(target, version, namer)
return self.tag(target, version)

def get_tags(self, target: Target) -> List[str]:
return [self.get_stable_tag(target)]
Expand Down Expand Up @@ -140,7 +128,7 @@ def get_stable_version(self) -> str:

def pr_tag(self, target: Target) -> str:
# edge/osrd-front:pr-42-nginx # pr-42 (merge of XXXX into XXXX)
return tag(target, f"pr-{self.pr_id}")
return self.tag(target, f"pr-{self.pr_id}")

def get_tags(self, target: Target) -> List[str]:
return [*super().get_tags(target), self.pr_tag(target)]
Expand All @@ -150,7 +138,7 @@ def get_cache_to(self, target: Target) -> List[str]:

def get_cache_from(self, target: Target) -> List[str]:
return [
registry_cache(tag(target, self.target_branch)),
registry_cache(self.tag(target, self.target_branch)),
registry_cache(self.pr_tag(target)),
]

Expand All @@ -173,10 +161,10 @@ def get_cache_from(self, target: Target) -> List[str]:
# we can't easily cache from the PRs, as multiple PRs
# can be grouped into one merge group batch, and there's
# no obvious way to figure out which ones
return [registry_cache(tag(target, self.target_branch))]
return [registry_cache(self.tag(target, self.target_branch))]

def get_cache_to(self, target: Target) -> List[str]:
return [registry_cache(tag(target, self.target_branch))]
return [registry_cache(self.tag(target, self.target_branch))]


@dataclass
Expand All @@ -194,7 +182,7 @@ def get_stable_version(self) -> str:

def branch_tag(self, target: Target) -> str:
# edge/osrd-front:dev-nginx # dev XXXX
return tag(target, self.branch_name)
return self.tag(target, self.branch_name)

def get_tags(self, target: Target) -> List[str]:
return [*super().get_tags(target), self.branch_tag(target)]
Expand Down Expand Up @@ -222,8 +210,8 @@ def get_stable_version(self) -> str:
name = f"{name}-draft"
return name

def get_stable_image_namer(self) -> ImageNamer:
return release_image
def get_namespace(self) -> str:
return DEFAULT_RELEASE_NAMESPACE

def get_tags(self, target: Target) -> List[str]:
if not target.release:
Expand Down

0 comments on commit cd1ed89

Please sign in to comment.