Skip to content

Commit 7649e71

Browse files
committed
Add support to additionally tag an existing OCI manifest
Signed-off-by: Tobias Wolf <[email protected]>
1 parent c67c28b commit 7649e71

File tree

7 files changed

+153
-26
lines changed

7 files changed

+153
-26
lines changed

.github/actions/features_parse/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ outputs:
1111
runs:
1212
using: composite
1313
steps:
14-
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].0
14+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].1
1515
- id: result
1616
shell: bash
1717
run: |

.github/actions/flavors_parse/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ outputs:
1313
runs:
1414
using: composite
1515
steps:
16-
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].0
16+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].1
1717
- id: matrix
1818
shell: bash
1919
run: |

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Installs the given GardenLinux Python library
44
inputs:
55
version:
66
description: GardenLinux Python library version
7-
default: "0.9.0"
7+
default: "0.9.1"
88
python_version:
99
description: Python version to setup
1010
default: "3.13"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "gardenlinux"
3-
version = "0.9.0"
3+
version = "0.9.1"
44
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
55
authors = ["Garden Linux Maintainers <[email protected]>"]
66
license = "Apache-2.0"

src/gardenlinux/oci/__main__.py

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,28 @@ def cli():
3131
help="Container Name",
3232
)
3333
@click.option(
34-
"--version",
35-
required=True,
36-
type=click.Path(),
37-
help="Version of image",
34+
"--cname", required=True, type=click.Path(), help="Canonical Name of Image"
3835
)
3936
@click.option(
40-
"--commit",
37+
"--arch",
4138
required=False,
4239
type=click.Path(),
4340
default=None,
44-
help="Commit of image",
41+
help="Target Image CPU Architecture",
4542
)
4643
@click.option(
47-
"--arch",
48-
required=True,
44+
"--version",
45+
required=False,
4946
type=click.Path(),
50-
help="Target Image CPU Architecture",
47+
default=None,
48+
help="Version of image",
5149
)
5250
@click.option(
53-
"--cname", required=True, type=click.Path(), help="Canonical Name of Image"
51+
"--commit",
52+
required=False,
53+
type=click.Path(),
54+
default=None,
55+
help="Commit of image",
5456
)
5557
@click.option("--dir", "directory", required=True, help="path to the build artifacts")
5658
@click.option(
@@ -76,10 +78,10 @@ def cli():
7678
)
7779
def push_manifest(
7880
container,
81+
cname,
82+
arch,
7983
version,
8084
commit,
81-
arch,
82-
cname,
8385
directory,
8486
cosign_file,
8587
manifest_file,
@@ -107,6 +109,76 @@ def push_manifest(
107109
print(manifest.digest, file=open(cosign_file, "w"))
108110

109111

112+
@cli.command()
113+
@click.option(
114+
"--container",
115+
required=True,
116+
type=click.Path(),
117+
help="Container Name",
118+
)
119+
@click.option(
120+
"--cname",
121+
required=False,
122+
type=click.Path(),
123+
default=None,
124+
help="Canonical Name of Image"
125+
)
126+
@click.option(
127+
"--arch",
128+
required=False,
129+
type=click.Path(),
130+
default=None,
131+
help="Target Image CPU Architecture",
132+
)
133+
@click.option(
134+
"--version",
135+
required=False,
136+
type=click.Path(),
137+
default=None,
138+
help="Version of image",
139+
)
140+
@click.option(
141+
"--commit",
142+
required=False,
143+
type=click.Path(),
144+
default=None,
145+
help="Commit of image",
146+
)
147+
@click.option(
148+
"--insecure",
149+
default=False,
150+
help="Use HTTP to communicate with the registry",
151+
)
152+
@click.option(
153+
"--tag",
154+
required=True,
155+
multiple=True,
156+
help="Tag to push the manifest with",
157+
)
158+
def push_manifest_tags(
159+
container,
160+
cname,
161+
arch,
162+
version,
163+
commit,
164+
insecure,
165+
tag,
166+
):
167+
"""
168+
Push artifacts and the manifest from a directory to a registry.
169+
170+
:since: 0.7.0
171+
"""
172+
173+
container = Container(
174+
f"{container}:{version}",
175+
insecure=insecure,
176+
)
177+
178+
manifest = container.read_or_generate_manifest(cname, arch, version, commit)
179+
container.push_manifest_for_tags(manifest, tag)
180+
181+
110182
@cli.command()
111183
@click.option(
112184
"--container",

src/gardenlinux/oci/container.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,14 @@ def read_or_generate_index(self):
520520

521521
def read_or_generate_manifest(
522522
self,
523-
cname: str,
523+
cname: Optional[str] = None,
524524
architecture: Optional[str] = None,
525525
version: Optional[str] = None,
526526
commit: Optional[str] = None,
527527
feature_set: Optional[str] = None,
528528
) -> Manifest:
529529
"""
530-
Reads from registry or generates the OCI image manifest.
530+
Reads from registry or generates the OCI manifest.
531531
532532
:param cname: Canonical name of the manifest
533533
:param architecture: Target architecture of the manifest
@@ -539,19 +539,26 @@ def read_or_generate_manifest(
539539
:since: 0.7.0
540540
"""
541541

542-
if architecture is None:
543-
architecture = CName(cname, architecture, version).arch
542+
if cname is None:
543+
response = self._get_manifest_without_response_parsing(self._container_version)
544+
else:
545+
if architecture is None:
546+
architecture = CName(cname, architecture, version).arch
544547

545-
response = self._get_manifest_without_response_parsing(
546-
f"{self._container_version}-{cname}-{architecture}"
547-
)
548+
response = self._get_manifest_without_response_parsing(
549+
f"{self._container_version}-{cname}-{architecture}"
550+
)
551+
#
548552

549553
if response.ok:
550554
manifest = Manifest(**response.json())
551555
elif response.status_code == 404:
552-
manifest = self.generate_manifest(
553-
cname, architecture, version, commit, feature_set
554-
)
556+
if cname is None:
557+
manifest = Manifest()
558+
else:
559+
manifest = self.generate_manifest(
560+
cname, architecture, version, commit, feature_set
561+
)
555562
else:
556563
response.raise_for_status()
557564

tests/oci/test_oci.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,41 @@ def push_manifest(runner, version, arch, cname, additional_tags=None):
6666
return False
6767

6868

69+
def push_manifest_tags(runner, version, arch, cname, tags=None):
70+
"""Push manifest to registry and return success status"""
71+
print(f"Pushing manifest for {cname} {arch}")
72+
73+
cmd = [
74+
"push-manifest-tags",
75+
"--container",
76+
CONTAINER_NAME_ZOT_EXAMPLE,
77+
"--version",
78+
version,
79+
"--arch",
80+
arch,
81+
"--cname",
82+
cname,
83+
"--insecure",
84+
"True",
85+
]
86+
87+
if tags:
88+
for tag in tags:
89+
cmd.extend(["--tag", tag])
90+
91+
try:
92+
result = runner.invoke(
93+
gl_oci,
94+
cmd,
95+
catch_exceptions=False,
96+
)
97+
print(f"Push manifest tags output: {result.output}")
98+
return result.exit_code == 0
99+
except Exception as e:
100+
print(f"Error during push manifest tags: {str(e)}")
101+
return False
102+
103+
69104
def update_index(runner, version, additional_tags=None):
70105
"""Update index in registry and return success status"""
71106
print("Updating index")
@@ -278,12 +313,25 @@ def test_push_manifest_and_index(
278313
repo_name = "gardenlinux-example"
279314
combined_tag = f"{version}-{cname}-{arch}"
280315

316+
post_push_manifest_tags = []
317+
281318
# Push manifest and update index
319+
if cname.startswith(f"{TEST_PLATFORMS[1]}-"):
320+
post_push_manifest_tags = additional_tags_manifest
321+
additional_tags_manifest = []
322+
282323
push_successful = push_manifest(
283324
runner, version, arch, cname, additional_tags_manifest
284325
)
285326
assert push_successful, "Manifest push should succeed"
286327

328+
if len(post_push_manifest_tags) > 0:
329+
push_successful = push_manifest_tags(
330+
runner, version, arch, cname, post_push_manifest_tags
331+
)
332+
assert push_successful, "Manifest tags push should succeed"
333+
#
334+
287335
if push_successful:
288336
update_index_successful = update_index(runner, version, additional_tags_index)
289337
assert update_index_successful, "Index update should succeed"

0 commit comments

Comments
 (0)