Skip to content

Commit 81f9c28

Browse files
committed
Implement gl-metadata to generate release files
Signed-off-by: Tobias Wolf <wolf@b1-systems.de>
1 parent dd70048 commit 81f9c28

File tree

3 files changed

+124
-29
lines changed

3 files changed

+124
-29
lines changed

src/gardenlinux/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@
140140
"secureboot.aws-efivars": "application/io.gardenlinux.cert.secureboot.aws-efivars",
141141
}
142142

143+
GL_BUG_REPORT_URL = "https://github.com/gardenlinux/gardenlinux/issues"
144+
GL_COMMIT_SPECIAL_VALUES = ("local",)
145+
GL_DISTRIBUTION_NAME = "Garden Linux"
146+
GL_HOME_URL = "https://gardenlinux.io"
147+
GL_RELEASE_ID = "gardenlinux"
143148
GL_REPOSITORY_URL = "https://github.com/gardenlinux/gardenlinux"
149+
GL_SUPPORT_URL = "https://github.com/gardenlinux/gardenlinux"
144150

145151
OCI_ANNOTATION_SIGNATURE_KEY = "io.gardenlinux.oci.signature"
146152
OCI_ANNOTATION_SIGNED_STRING_KEY = "io.gardenlinux.oci.signed-string"

src/gardenlinux/features/cname.py

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
from os import PathLike
1111
import re
1212

13-
from ..constants import ARCHS
13+
from ..constants import (
14+
ARCHS,
15+
GL_BUG_REPORT_URL,
16+
GL_COMMIT_SPECIAL_VALUES,
17+
GL_DISTRIBUTION_NAME,
18+
GL_HOME_URL,
19+
GL_RELEASE_ID,
20+
GL_SUPPORT_URL,
21+
)
1422

1523
from .parser import Parser
1624

@@ -87,7 +95,7 @@ def __init__(self, cname, arch=None, commit_hash=None, version=None):
8795
if commit_id_or_hash is not None:
8896
self._commit_id = commit_id_or_hash[:8]
8997

90-
if len(commit_id_or_hash) == 40: # sha1 hex
98+
if len(commit_id_or_hash) == 40: # sha1 hex
9199
self._commit_hash = commit_id_or_hash
92100

93101
@property
@@ -129,7 +137,9 @@ def commit_hash(self) -> str:
129137
"""
130138

131139
if self._commit_hash is None:
132-
raise RuntimeError("GardenLinux canonical name given does not contain the commit hash")
140+
raise RuntimeError(
141+
"GardenLinux canonical name given does not contain the commit hash"
142+
)
133143

134144
return self._commit_hash
135145

@@ -183,6 +193,42 @@ def feature_set(self) -> str:
183193

184194
return Parser().filter_as_string(self.flavor)
185195

196+
@property
197+
def metadata_string(self) -> str:
198+
"""
199+
Returns the metadata describing the given CName instance.
200+
201+
:return: (str) Metadata describing the given CName instance
202+
:since: 0.9.2
203+
"""
204+
205+
features = Parser().filter_as_dict(self.flavor)
206+
207+
elements = ",".join(features["element"])
208+
flags = ",".join(features["flag"])
209+
platforms = ",".join(features["platform"])
210+
211+
metadata = f"""
212+
ID={GL_RELEASE_ID}
213+
NAME="{GL_DISTRIBUTION_NAME}"
214+
PRETTY_NAME="{GL_DISTRIBUTION_NAME} {self.version}"
215+
IMAGE_VERSION={self.version}
216+
VARIANT_ID="{self.flavor}-{self.arch}"
217+
HOME_URL="{GL_HOME_URL}"
218+
SUPPORT_URL="{GL_SUPPORT_URL}"
219+
BUG_REPORT_URL="{GL_BUG_REPORT_URL}"
220+
GARDENLINUX_CNAME="{self.cname}"
221+
GARDENLINUX_FEATURES="{self.feature_set}"
222+
GARDENLINUX_FEATURES_PLATFORMS="{platforms}"
223+
GARDENLINUX_FEATURES_ELEMENTS="{elements}"
224+
GARDENLINUX_FEATURES_FLAGS="{flags}"
225+
GARDENLINUX_VERSION="{self.version}"
226+
GARDENLINUX_COMMIT_ID="{self.commit_id}"
227+
GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}"
228+
""".strip()
229+
230+
return metadata
231+
186232
@property
187233
def platform(self) -> str:
188234
"""
@@ -317,30 +363,5 @@ def save_to_metadata_file(
317363
f"Refused to overwrite existing metadata file: {metadata_file}"
318364
)
319365

320-
features = Parser().filter_as_dict(self.flavor)
321-
322-
elements = ",".join(features["element"])
323-
flags = ",".join(features["flag"])
324-
platforms = ",".join(features["platform"])
325-
326-
metadata = f"""
327-
ID=gardenlinux
328-
NAME="Garden Linux"
329-
PRETTY_NAME="Garden Linux {self.version}"
330-
IMAGE_VERSION={self.version}
331-
VARIANT_ID="{self.flavor}-{self.arch}"
332-
HOME_URL="https://gardenlinux.io"
333-
SUPPORT_URL="https://github.com/gardenlinux/gardenlinux"
334-
BUG_REPORT_URL="https://github.com/gardenlinux/gardenlinux/issues"
335-
GARDENLINUX_CNAME="{self.cname}"
336-
GARDENLINUX_FEATURES="{self.feature_set}"
337-
GARDENLINUX_FEATURES_PLATFORMS="{platforms}"
338-
GARDENLINUX_FEATURES_ELEMENTS="{elements}"
339-
GARDENLINUX_FEATURES_FLAGS="{flags}"
340-
GARDENLINUX_VERSION="{self.version}"
341-
GARDENLINUX_COMMIT_ID="{self.commit_id}"
342-
GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}"
343-
""".strip()
344-
345366
with metadata_file.open("w") as fp:
346-
fp.write(metadata)
367+
fp.write(self.metadata_string)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
gl-metadata main entrypoint
6+
"""
7+
8+
from functools import reduce
9+
from os.path import basename, dirname
10+
import argparse
11+
import logging
12+
import re
13+
14+
from .cname import CName
15+
from .parser import Parser
16+
17+
from .__main__ import (
18+
get_cname_base,
19+
get_minimal_feature_set,
20+
get_version_and_commit_id_from_files,
21+
sort_subset,
22+
)
23+
24+
25+
_ARGS_ACTION_ALLOWED = [
26+
"output-as-json",
27+
"write",
28+
]
29+
30+
31+
def main():
32+
"""
33+
gl-metadata main()
34+
35+
:since: 0.7.0
36+
"""
37+
38+
parser = argparse.ArgumentParser()
39+
40+
parser.add_argument("--arch", dest="arch")
41+
parser.add_argument("--cname", required=True, dest="cname")
42+
parser.add_argument("--commit-hash", dest="commit_hash")
43+
parser.add_argument("--release-file", dest="release_file")
44+
parser.add_argument("--overwrite-file", type=bool, dest="overwrite_file")
45+
parser.add_argument("--version", dest="version")
46+
47+
parser.add_argument(
48+
"action", nargs="?", choices=_ARGS_ACTION_ALLOWED, default="output-as-json"
49+
)
50+
51+
args = parser.parse_args()
52+
53+
cname = CName(
54+
args.cname, arch=args.arch, commit_hash=args.commit_hash, version=args.version
55+
)
56+
57+
if args.commit_hash is not None:
58+
cname.commit_hash = args.commit_hash
59+
60+
if args.action == "write":
61+
cname.save_to_metadata_file(args.release_file, args.overwrite_file)
62+
else:
63+
cname.load_from_metadata_file(args.release_file)
64+
print(cname.metadata_string)
65+
66+
67+
if __name__ == "__main__":
68+
main()

0 commit comments

Comments
 (0)