Skip to content

Commit cdf53d5

Browse files
committed
Restructure gardenlinux.oci to clean up code and logic
Closes: #110 Signed-off-by: Tobias Wolf <[email protected]>
1 parent a57efbd commit cdf53d5

File tree

14 files changed

+875
-837
lines changed

14 files changed

+875
-837
lines changed

src/gardenlinux/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,4 @@
166166

167167
OCI_ANNOTATION_SIGNATURE_KEY = "io.gardenlinux.oci.signature"
168168
OCI_ANNOTATION_SIGNED_STRING_KEY = "io.gardenlinux.oci.signed-string"
169+
OCI_IMAGE_INDEX_MEDIA_TYPE = "application/vnd.oci.image.index.v1+json"

src/gardenlinux/features/cname.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from typing import Optional
44
import re
55

6+
from .parser import Parser
7+
68

79
class CName(object):
810
def __init__(self, cname, arch=None, version=None):
@@ -64,6 +66,10 @@ def commit_id(self) -> Optional[str]:
6466
def flavor(self) -> str:
6567
return self._flavor
6668

69+
@property
70+
def feature_set(self) -> str:
71+
return Parser().filter_as_string(self.flavor)
72+
6773
@property
6874
def version(self) -> Optional[str]:
6975
return self._version

src/gardenlinux/features/parser.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818

1919

2020
class Parser(object):
21+
_GARDENLINUX_ROOT: str = "."
22+
2123
def __init__(
2224
self,
23-
gardenlinux_root: str = ".",
24-
feature_dir_name: str = "features",
25+
gardenlinux_root: Optional[str] = None,
26+
feature_dir_name: Optional[str] = "features",
2527
logger: Optional[logging.Logger] = None,
2628
):
29+
if gardenlinux_root is None:
30+
gardenlinux_root = Parser._GARDENLINUX_ROOT
31+
2732
feature_base_dir = os.path.join(gardenlinux_root, feature_dir_name)
2833

2934
if not os.access(feature_base_dir, os.R_OK):
@@ -248,6 +253,10 @@ def filter_func(a, b):
248253
def _get_graph_node_type(node):
249254
return node.get("content", {}).get("type")
250255

256+
@staticmethod
257+
def set_default_gardenlinux_root_dir(root_dir):
258+
Parser._GARDENLINUX_ROOT = root_dir
259+
251260
@staticmethod
252261
def sort_graph_nodes(graph):
253262
def key_function(node):

src/gardenlinux/oci/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
3+
from .container import Container
4+
from .index import Index
5+
from .layer import Layer
6+
from .manifest import Manifest
7+
8+
__all__ = ["Container", "Index", "Layer", "Manifest"]

src/gardenlinux/oci/__main__.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pygments.lexer import default
77

8-
from .registry import GlociRegistry
8+
from .container import Container
99

1010

1111
@click.group()
@@ -70,17 +70,20 @@ def push_manifest(
7070
insecure,
7171
):
7272
"""push artifacts from a dir to a registry, get the index-entry for the manifest in return"""
73-
container_name = f"{container}:{version}"
74-
registry = GlociRegistry(
75-
container_name=container_name,
73+
container = Container(
74+
f"{container}:{version}",
7675
token=os.getenv("GL_CLI_REGISTRY_TOKEN"),
7776
insecure=insecure,
7877
)
79-
digest = registry.push_from_dir(
80-
arch, version, cname, directory, manifest_file, commit=commit
78+
79+
manifest = container.read_or_generate_manifest(cname, arch, version, commit)
80+
81+
container.push_manifest_and_artifacts_from_directory(
82+
manifest, directory, manifest_file
8183
)
84+
8285
if cosign_file:
83-
print(digest, file=open(cosign_file, "w"))
86+
print(manifest.digest, file=open(cosign_file, "w"))
8487

8588

8689
@cli.command()
@@ -110,13 +113,12 @@ def push_manifest(
110113
)
111114
def update_index(container, version, manifest_folder, insecure):
112115
"""push a index entry from a list of files to an index"""
113-
container_name = f"{container}:{version}"
114-
registry = GlociRegistry(
115-
container_name=container_name,
116+
container = Container(
117+
f"{container}:{version}",
116118
token=os.getenv("GL_CLI_REGISTRY_TOKEN"),
117119
insecure=insecure,
118120
)
119-
registry.update_index(manifest_folder)
121+
container.push_index_from_directory(manifest_folder)
120122

121123

122124
def main():

0 commit comments

Comments
 (0)