Skip to content

Commit cd0c991

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

File tree

6 files changed

+128
-16
lines changed

6 files changed

+128
-16
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: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ def cli():
3030
type=click.Path(),
3131
help="Container Name",
3232
)
33+
@click.option(
34+
"--cname", required=True, type=click.Path(), help="Canonical Name of Image"
35+
)
36+
@click.option(
37+
"--arch",
38+
required=False,
39+
type=click.Path(),
40+
help="Target Image CPU Architecture",
41+
)
3342
@click.option(
3443
"--version",
35-
required=True,
44+
required=False,
3645
type=click.Path(),
3746
help="Version of image",
3847
)
@@ -43,15 +52,6 @@ def cli():
4352
default=None,
4453
help="Commit of image",
4554
)
46-
@click.option(
47-
"--arch",
48-
required=True,
49-
type=click.Path(),
50-
help="Target Image CPU Architecture",
51-
)
52-
@click.option(
53-
"--cname", required=True, type=click.Path(), help="Canonical Name of Image"
54-
)
5555
@click.option("--dir", "directory", required=True, help="path to the build artifacts")
5656
@click.option(
5757
"--cosign_file",
@@ -76,10 +76,10 @@ def cli():
7676
)
7777
def push_manifest(
7878
container,
79+
cname,
80+
arch,
7981
version,
8082
commit,
81-
arch,
82-
cname,
8383
directory,
8484
cosign_file,
8585
manifest_file,
@@ -107,6 +107,70 @@ def push_manifest(
107107
print(manifest.digest, file=open(cosign_file, "w"))
108108

109109

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

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)