-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This removes a bit of if() condition wars in the BaseContainerImage and delegates it into its own class hierarchy, which allows to build a python container for appcol without having to do more subclasses.
- Loading branch information
1 parent
aaa6f13
commit 7cb148d
Showing
7 changed files
with
126 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Registry classes for container images.""" | ||
|
||
import dataclasses | ||
from abc import ABC | ||
from abc import abstractmethod | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class RegistryABC(ABC): | ||
"""Abstract Base Class for defining Registry specific content.""" | ||
|
||
_: dataclasses.KW_ONLY | ||
"""The base hostname for this registry instance""" | ||
registry: str | ||
"""The vendor that is put into the ``org.opencontainers.image.vendor`` label""" | ||
vendor: str | ||
|
||
@abstractmethod | ||
def url(self, container) -> str: | ||
pass | ||
|
||
@abstractmethod | ||
def registry_prefix(self, *, is_application) -> str: | ||
pass | ||
|
||
|
||
class ApplicationCollectionRegistry(RegistryABC): | ||
"""Registry for the Rancher Application Collection Distribution Platform.""" | ||
|
||
def __init__(self): | ||
super().__init__(registry="dp.apps.rancher.io", vendor="SUSE LLC") | ||
|
||
def url(self, container) -> str: | ||
return f"https://apps.rancher.io/applications/{container.name}" | ||
|
||
def registry_prefix(self, *, is_application) -> str: | ||
return "containers" | ||
|
||
|
||
class SUSERegistry(RegistryABC): | ||
"""Registry for the SUSE Registry.""" | ||
|
||
def __init__(self): | ||
super().__init__(registry="registry.suse.com", vendor="SUSE LLC") | ||
|
||
def url(self, container) -> str: | ||
if container.os_version.is_ltss: | ||
return "https://www.suse.com/products/long-term-service-pack-support/" | ||
return "https://www.suse.com/products/base-container-images/" | ||
|
||
def registry_prefix(self, *, is_application) -> str: | ||
return "suse" if is_application else "bci" | ||
|
||
|
||
class openSUSERegistry(RegistryABC): | ||
"""Registry for the openSUSE registry.""" | ||
|
||
def __init__(self): | ||
super().__init__(registry="registry.opensuse.org", vendor="openSUSE Project") | ||
|
||
def url(self, container) -> str: | ||
return "https://www.opensuse.org" | ||
|
||
def registry_prefix(self, *, is_application) -> str: | ||
return "opensuse" if is_application else "opensuse/bci" | ||
|
||
|
||
def get_registry(container) -> RegistryABC: | ||
"""Return the appropriate registry for the container.""" | ||
if container.os_version.is_tumbleweed: | ||
return openSUSERegistry() | ||
return SUSERegistry() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters