Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Installs the given GardenLinux Python library
inputs:
version:
description: GardenLinux Python library version
default: "1.0.3"
default: "1.0.4"
python_version:
description: Python version to setup
default: "3.14"
Expand Down
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gardenlinux"
version = "1.0.3"
version = "1.0.4"
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
authors = ["Garden Linux Maintainers <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -10,7 +10,7 @@ packages = [{ include = "gardenlinux", from = "src" }]
[tool.poetry.dependencies]
python = ">=3.13,!=3.14.1"
apt-repo = "^0.5"
boto3 = "^1.44.2"
boto3 = "^1.44.3"
cryptography = "^49.0.0"
jsonschema = "^4.26.0"
networkx = "^3.7"
Expand All @@ -20,21 +20,21 @@ pygit2 = "^1.21.0"
pygments = "^2.21.0"
PyGithub = "^2.10.0"
PyYAML = "^6.0.3"
semver = "^3.1.1"
semver = "^3.1.2"

[tool.poetry.group.dev.dependencies]
bandit = "^1.9.4"
boto3-stubs = { extras = ["s3"], version = "^1.44.2" }
boto3-stubs = { extras = ["s3"], version = "^1.44.3" }
isort = "^8.0.1"
moto = "^5.2.5"
mypy = "2.4.1"
mypy = "2.1.0"
pre-commit = "^4.7.0"
python-dotenv = "^1.2.2"
pytest = "^9.2.0"
pytest-cov = "^7.1.0"
requests-mock = "^1.12.1"
sphinx = "9.2.0"
types-pyyaml = "^6.0.12.20261111"
types-pyyaml = "^6.0.12.20261113"
types-requests = "^2.33.0.20261030"

[tool.poetry.group.docs.dependencies]
Expand Down
3 changes: 3 additions & 0 deletions src/gardenlinux/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"type": "element",
}

COMMIT_ID_LENGTH = 8
COMMIT_HASH_LENGTH = 40

# GardenLinux flavors schema for validation
GL_FLAVORS_SCHEMA = {
"type": "object",
Expand Down
7 changes: 4 additions & 3 deletions src/gardenlinux/features/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from os import path
from typing import Any, Set

from ..constants import COMMIT_ID_LENGTH
from .artifact_base_name import ArtifactBaseName
from .parser import Parser

Expand Down Expand Up @@ -201,13 +202,13 @@ def main() -> None:
else:
print_output_from_abn_object(args.type, abn_object)
elif args.type == "commit-id":
print(commit_id_or_hash[:8])
print(commit_id_or_hash[:COMMIT_ID_LENGTH])
elif args.type == "container-tag":
print(re.sub("\\W+", "-", f"{version}-{commit_id_or_hash[:8]}"))
print(re.sub("\\W+", "-", f"{version}-{commit_id_or_hash[:COMMIT_ID_LENGTH]}"))
elif args.type == "version":
print(version)
elif args.type == "version_and_commit-id":
print(f"{version}-{commit_id_or_hash[:8]}")
print(f"{version}-{commit_id_or_hash[:COMMIT_ID_LENGTH]}")


def graph_as_mermaid_markup(cname: str | None, graph: Any) -> str:
Expand Down
12 changes: 7 additions & 5 deletions src/gardenlinux/features/artifact_base_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from typing import Optional, Self

from ..constants import (
COMMIT_HASH_LENGTH,
COMMIT_ID_LENGTH,
GL_BUG_REPORT_URL,
GL_COMMIT_SPECIAL_VALUES,
GL_DISTRIBUTION_NAME,
Expand Down Expand Up @@ -60,11 +62,11 @@ def __init__(

commit_id_or_hash = re_match[5]

self._commit_id = commit_id_or_hash[:8]
self._commit_id = commit_id_or_hash[:COMMIT_ID_LENGTH]
self._commit_hash = None

if (
len(commit_id_or_hash) == 40
len(commit_id_or_hash) == COMMIT_HASH_LENGTH
or commit_id_or_hash in GL_COMMIT_SPECIAL_VALUES
): # sha1 hex
self._commit_hash = commit_id_or_hash
Expand Down Expand Up @@ -95,7 +97,7 @@ def commit_hash(self, commit_hash: str) -> None:
if self._commit_id is not None and not commit_hash.startswith(self._commit_id):
raise RuntimeError("Commit hash given differs from commit ID already set")

self._commit_id = commit_hash[:8]
self._commit_id = commit_hash[:COMMIT_ID_LENGTH]
self._commit_hash = commit_hash

@property
Expand Down Expand Up @@ -357,7 +359,7 @@ def get_version_and_commit_id_from_files(

if os.access(gardenlinux_root.joinpath("COMMIT"), os.R_OK):
with gardenlinux_root.joinpath("COMMIT").open("r") as fp:
commit_hash = fp.read().strip()[:8]
commit_hash = fp.read().strip()[:COMMIT_ID_LENGTH]

if os.access(gardenlinux_root.joinpath("VERSION"), os.R_OK):
with gardenlinux_root.joinpath("VERSION").open("r") as fp:
Expand Down Expand Up @@ -434,7 +436,7 @@ def new_instance(
raise RuntimeError("Version does not match the given argument")

if commit_id_or_hash:
commit_id = commit_id_or_hash[:8]
commit_id = commit_id_or_hash[:COMMIT_ID_LENGTH]

if abn_object.commit_hash and abn_object.commit_hash != commit_id_or_hash:
raise RuntimeError("Commit hash does not match the given argument")
Expand Down
9 changes: 8 additions & 1 deletion src/gardenlinux/oci/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from oras.defaults import unknown_config_media_type as UNKNOWN_CONFIG_MEDIA_TYPE
from oras.oci import EmptyManifest

from ..constants import COMMIT_HASH_LENGTH, COMMIT_ID_LENGTH


class Manifest(dict): # type: ignore[type-arg]
"""
Expand Down Expand Up @@ -81,7 +83,12 @@ def commit(self) -> str:
f"Unexpected manifest with missing config annotation '{annotation_commit_key}' found"
)

return self["annotations"][annotation_commit_key] # type: ignore[no-any-return]
commit_id: str = self["annotations"][annotation_commit_key]

if len(commit_id) == COMMIT_HASH_LENGTH:
commit_id = commit_id[:COMMIT_ID_LENGTH]

return commit_id

@commit.setter
def commit(self, value: str) -> None:
Expand Down
15 changes: 8 additions & 7 deletions src/gardenlinux/s3/s3_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def upload_from_directory(
arch = re_object.sub("+", arch)
commit_id_or_hash = abn_object.commit_hash

if commit_id_or_hash is None:
if not commit_id_or_hash:
commit_id_or_hash = abn_object.commit_id

metadata = {
Expand All @@ -231,7 +231,7 @@ def upload_from_directory(
"secureboot": secureboot,
"tpm2": tpm2,
"s3_bucket": self._bucket.name,
"s3_key": f"meta/singles/{base_name}",
"s3_key": f"meta/singles/{abn_object}",
"test_result": None,
"version": abn_object.version,
"paths": [],
Expand All @@ -254,18 +254,19 @@ def upload_from_directory(
if not artifact.match(f"{base_name}*"):
continue

s3_key = f"objects/{base_name}/{artifact.name}"
s3_suffix = artifact.name[base_name_length:]
s3_key = f"objects/{abn_object}/{abn_object}{s3_suffix}"

with artifact.open("rb") as fp:
md5sum = file_digest(fp, "md5").hexdigest()
fp.seek(0)
sha256sum = file_digest(fp, "sha256").hexdigest()

artifact_metadata = {
"name": artifact.name,
"name": f"{abn_object}{s3_suffix}",
"s3_bucket_name": self._bucket.name,
"s3_key": s3_key,
"suffix": re_object.sub("+", artifact.name[base_name_length:]),
"suffix": re_object.sub("+", s3_suffix),
"md5sum": md5sum,
"sha256sum": sha256sum,
}
Expand Down Expand Up @@ -296,7 +297,7 @@ def upload_from_directory(
else:
if delete_before_push:
self._bucket.delete_objects(
Delete={"Objects": [{"Key": f"meta/singles/{base_name}"}]}
Delete={"Objects": [{"Key": f"meta/singles/{abn_object}"}]}
)

with TemporaryFile(mode="wb+") as fp:
Expand All @@ -305,6 +306,6 @@ def upload_from_directory(

self._bucket.upload_fileobj(
fp,
f"meta/singles/{base_name}",
f"meta/singles/{abn_object}",
ExtraArgs={"ContentType": "text/yaml"},
)
5 changes: 3 additions & 2 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path

from gardenlinux.constants import COMMIT_ID_LENGTH
from gardenlinux.git import Repository

TEST_DATA_DIR = "test-data"
Expand All @@ -18,14 +19,14 @@
TEST_ARCHITECTURES = ["arm64", "amd64"]
TEST_FEATURE_STRINGS_SHORT = ["gardener_prod"]
TEST_FEATURE_SET = "_slim,base,container"
TEST_COMMIT = Repository(GL_ROOT_DIR).commit_id[:8]
TEST_COMMIT = Repository(GL_ROOT_DIR).commit_id[:COMMIT_ID_LENGTH]
TEST_VERSION = "1000.0"
TEST_VERSION_STABLE = "1000"

TEST_GARDENLINUX_RELEASE_MAJOR = "2150.0.0"
TEST_GARDENLINUX_RELEASE_MINOR = "1877.3"
TEST_GARDENLINUX_COMMIT = "75df9f401a842914563f312899ec3ce34b24515c"
TEST_GARDENLINUX_COMMIT_SHORT = TEST_GARDENLINUX_COMMIT[:8]
TEST_GARDENLINUX_COMMIT_SHORT = TEST_GARDENLINUX_COMMIT[:COMMIT_ID_LENGTH]
TEST_GARDENLINUX_RELEASE_BUCKET_NAME = "test__gardenlinux__releases"

RELEASE_NOTES_TEST_DATA_DIR = (
Expand Down
20 changes: 20 additions & 0 deletions tests/oci/test_image_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from gardenlinux.oci import ImageManifest, Layer

from ..constants import TEST_GARDENLINUX_COMMIT, TEST_GARDENLINUX_COMMIT_SHORT


def test_ImageManifest_artifact_base_name() -> None:
# Arrange
Expand Down Expand Up @@ -48,6 +50,24 @@ def test_ImageManifest_arch() -> None:
assert manifest.arch == "amd64"


def test_ImageManifest_commit() -> None:
# Arrange
empty_manifest = ImageManifest()

manifest = ImageManifest(
annotations={ImageManifest.ANNOTATION_COMMIT_KEY: TEST_GARDENLINUX_COMMIT}
)

# Assert
with pytest.raises(RuntimeError):
assert empty_manifest.commit == TEST_GARDENLINUX_COMMIT_SHORT

empty_manifest.commit = TEST_GARDENLINUX_COMMIT_SHORT
assert empty_manifest.commit == TEST_GARDENLINUX_COMMIT_SHORT

assert manifest.commit == TEST_GARDENLINUX_COMMIT_SHORT


def test_ImageManifest_cname() -> None:
# Arrange
arch = "amd64"
Expand Down
Loading
Loading