Skip to content

Commit d988445

Browse files
yeoldegroveNotTheEvilOne
authored andcommitted
allow adding additional tags to OCI index and manifests (#111)
* add a retry_on_error decoration for gardenlinux.oci * add make targets test-debug and test-trace adds the possibility to get debug logs for pytest e.g. debug which OCI tags exist * generate test data in a pythonic way add create_test_data to conftest remove generate_test_certificates from helper as it is on conftest already * add gardenlinux.oci.registry.push_additional_tags_manifest enables pushing additional tags to OCI manifest * update gardenlinux.oci.registry.update_index enables pushing additional tags to OCI index * rename src/gardenlinux/oci/helper.py src/gardenlinux/oci/wrapper.py
1 parent fb6cde7 commit d988445

File tree

22 files changed

+1921
-1451
lines changed

22 files changed

+1921
-1451
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ install-test: install-dev
4646
test: install-test
4747
$(POETRY) run pytest -k "not kms"
4848

49+
test-debug: install-test
50+
$(POETRY) run pytest -k "not kms" -vvv -s
51+
52+
test-trace: install-test
53+
$(POETRY) run pytest -k "not kms" -vvv --log-cli-level=DEBUG
54+
4955
format: install-dev
5056
$(POETRY) run black --extend-exclude test-data/gardenlinux .
5157

poetry.lock

Lines changed: 426 additions & 413 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readme = "README.md"
88
packages = [{include = "gardenlinux", from="src"}, {include = "python_gardenlinux_lib", from="src"}]
99

1010
[tool.poetry.dependencies]
11-
python = "^3.10"
11+
python = "^3.13"
1212
networkx = "^3.3"
1313
PyYAML = "^6.0.2"
1414
pytest = "^8.3.2"
@@ -19,11 +19,12 @@ oras = { git = "https://github.com/oras-project/oras-py.git", rev="caf8db5b2793
1919
python-dotenv = "^1.0.1"
2020
cryptography = "^44.0.0"
2121
boto3 = "*"
22+
click = "^8.2.0"
23+
pygments = "^2.19.1"
2224

2325
[tool.poetry.group.dev.dependencies]
2426
bandit = "^1.8.3"
2527
black = "^24.8.0"
26-
opencontainers = "^0.0.14"
2728

2829
[tool.poetry.group.docs.dependencies]
2930
sphinx-rtd-theme = "^2.0.0"

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
@@ -5,6 +5,8 @@
55

66
from ..constants import ARCHS
77

8+
from .parser import Parser
9+
810

911
class CName(object):
1012
def __init__(self, cname, arch=None, version=None):
@@ -66,6 +68,10 @@ def commit_id(self) -> Optional[str]:
6668
def flavor(self) -> str:
6769
return self._flavor
6870

71+
@property
72+
def feature_set(self) -> str:
73+
return Parser().filter_as_string(self.flavor)
74+
6975
@property
7076
def version(self) -> Optional[str]:
7177
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: 28 additions & 12 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()
@@ -58,6 +58,12 @@ def cli():
5858
default=False,
5959
help="Use HTTP to communicate with the registry",
6060
)
61+
@click.option(
62+
"--additional_tag",
63+
required=False,
64+
multiple=True,
65+
help="Additional tag to push the manifest with",
66+
)
6167
def push_manifest(
6268
container,
6369
version,
@@ -68,19 +74,23 @@ def push_manifest(
6874
cosign_file,
6975
manifest_file,
7076
insecure,
77+
additional_tag,
7178
):
7279
"""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,
80+
container = Container(
81+
f"{container}:{version}",
7682
token=os.getenv("GL_CLI_REGISTRY_TOKEN"),
7783
insecure=insecure,
7884
)
79-
digest = registry.push_from_dir(
80-
arch, version, cname, directory, manifest_file, commit=commit
85+
86+
manifest = container.read_or_generate_manifest(cname, arch, version, commit)
87+
88+
container.push_manifest_and_artifacts_from_directory(
89+
manifest, directory, manifest_file, additional_tag
8190
)
91+
8292
if cosign_file:
83-
print(digest, file=open(cosign_file, "w"))
93+
print(manifest.digest, file=open(cosign_file, "w"))
8494

8595

8696
@cli.command()
@@ -108,15 +118,21 @@ def push_manifest(
108118
default=False,
109119
help="Use HTTP to communicate with the registry",
110120
)
111-
def update_index(container, version, manifest_folder, insecure):
121+
@click.option(
122+
"--additional_tag",
123+
required=False,
124+
multiple=True,
125+
help="Additional tag to push the index with",
126+
)
127+
def update_index(container, version, manifest_folder, insecure, additional_tag):
112128
"""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,
129+
container = Container(
130+
f"{container}:{version}",
116131
token=os.getenv("GL_CLI_REGISTRY_TOKEN"),
117132
insecure=insecure,
118133
)
119-
registry.update_index(manifest_folder)
134+
135+
container.push_index_from_directory(manifest_folder, additional_tag)
120136

121137

122138
def main():

0 commit comments

Comments
 (0)