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
1 change: 0 additions & 1 deletion src/gardenlinux/features/cname.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ..constants import (
ARCHS,
GL_BUG_REPORT_URL,
GL_COMMIT_SPECIAL_VALUES,
GL_DISTRIBUTION_NAME,
GL_HOME_URL,
GL_RELEASE_ID,
Expand Down
13 changes: 1 addition & 12 deletions src/gardenlinux/features/metadata_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@
"""

import argparse
import logging
import re
from functools import reduce
from os.path import basename, dirname

from .__main__ import (
get_cname_base,
get_minimal_feature_set,
get_version_and_commit_id_from_files,
sort_subset,
)

from .cname import CName
from .parser import Parser

_ARGS_ACTION_ALLOWED = [
"output-release-metadata",
Expand Down
2 changes: 0 additions & 2 deletions src/gardenlinux/flavors/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""

import json
import os
import sys
from argparse import ArgumentParser
from pathlib import Path
from tempfile import TemporaryDirectory
Expand Down
12 changes: 9 additions & 3 deletions src/gardenlinux/github/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
from gardenlinux.logger import LoggerSetup

from .release import create_github_release, upload_to_github_release_page, write_to_release_id_file
from .release import (
create_github_release,
upload_to_github_release_page,
write_to_release_id_file,
)
from .release_notes import create_github_release_notes

LOGGER = LoggerSetup.get_logger("gardenlinux.github", "INFO")
Expand All @@ -18,7 +22,7 @@ def main():
create_parser.add_argument("--repo", default="gardenlinux")
create_parser.add_argument("--tag", required=True)
create_parser.add_argument("--commit", required=True)
create_parser.add_argument('--latest', action='store_true', default=False)
create_parser.add_argument("--latest", action="store_true", default=False)
create_parser.add_argument("--dry-run", action="store_true", default=False)

upload_parser = subparsers.add_parser("upload")
Expand All @@ -31,7 +35,9 @@ def main():
args = parser.parse_args()

if args.command == "create":
body = create_github_release_notes(args.tag, args.commit, GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME)
body = create_github_release_notes(
args.tag, args.commit, GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
)
if args.dry_run:
print("Dry Run ...")
print("This release would be created:")
Expand Down
8 changes: 5 additions & 3 deletions src/gardenlinux/github/release/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def create_github_release(owner, repo, tag, commitish, latest, body):
"body": body,
"draft": False,
"prerelease": False,
"make_latest": "true" if latest else "false"
"make_latest": "true" if latest else "false",
}

response = requests.post(
f"https://api.github.com/repos/{owner}/{repo}/releases",
headers=headers,
data=json.dumps(data),
timeout=REQUESTS_TIMEOUTS
timeout=REQUESTS_TIMEOUTS,
)

if response.status_code == 201:
Expand Down Expand Up @@ -84,7 +84,9 @@ def upload_to_github_release_page(
LOGGER.error(f"Error reading file {file_to_upload}: {e}")
return

response = requests.post(upload_url, headers=headers, data=file_contents, timeout=REQUESTS_TIMEOUTS)
response = requests.post(
upload_url, headers=headers, data=file_contents, timeout=REQUESTS_TIMEOUTS
)
if response.status_code == 201:
LOGGER.info("Upload successful")
else:
Expand Down
8 changes: 6 additions & 2 deletions src/gardenlinux/github/release_notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
)


def create_github_release_notes(gardenlinux_version, commitish, releases_s3_bucket_name):
def create_github_release_notes(
gardenlinux_version, commitish, releases_s3_bucket_name
):
package_list = get_package_list(gardenlinux_version)

output = ""
Expand All @@ -20,7 +22,9 @@ def create_github_release_notes(gardenlinux_version, commitish, releases_s3_buck
gardenlinux_version, package_list
)

metadata_files = download_all_metadata_files(gardenlinux_version, commitish, releases_s3_bucket_name)
metadata_files = download_all_metadata_files(
gardenlinux_version, commitish, releases_s3_bucket_name
)

output += release_notes_image_ids_section(metadata_files)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME


class DeploymentPlatform():
class DeploymentPlatform:
artifacts_bucket_name = GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME

def short_name(self):
Expand All @@ -25,7 +25,9 @@ def image_extension(self):
return "raw"

def artifact_for_flavor(self, flavor, markdown_format=True):
base_url = f"https://{self.__class__.artifacts_bucket_name}.s3.amazonaws.com/objects"
base_url = (
f"https://{self.__class__.artifacts_bucket_name}.s3.amazonaws.com/objects"
)
filename = f"{flavor}.{self.image_extension()}"
download_url = f"{base_url}/{flavor}/{filename}"
if markdown_format:
Expand All @@ -48,7 +50,9 @@ def region_details(self, image_metadata):
"image_id": image_id,
"image_name": image_name,
}:
details += f"**{region_name}:** {image_id} ({image_name})<br>"
details += (
f"**{region_name}:** {image_id} ({image_name})<br>"
)
case {"region": region_name, "image_id": image_id}:
details += f"**{region_name}:** {image_id}<br>"
case {"details": details_dict}:
Expand Down Expand Up @@ -93,7 +97,9 @@ def summary_text(self, image_metadata):
}:
gallery_count = len(gallery_images)
marketplace_count = len(marketplace_images)
return f"{gallery_count} gallery + {marketplace_count} marketplace images"
return (
f"{gallery_count} gallery + {marketplace_count} marketplace images"
)
case {"gallery_images": gallery_images}:
gallery_count = len(gallery_images)
return f"{gallery_count} gallery images"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportIncompatibleMethodOverride=false
from . import DeploymentPlatform


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportIncompatibleMethodOverride=false
from . import DeploymentPlatform


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportIncompatibleMethodOverride=false
from . import DeploymentPlatform


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportIncompatibleMethodOverride=false
from . import DeploymentPlatform


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportIncompatibleMethodOverride=false
from . import DeploymentPlatform


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyright: reportIncompatibleMethodOverride=false
from .openstack import OpenStack


Expand Down
28 changes: 13 additions & 15 deletions src/gardenlinux/github/release_notes/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ def download_all_metadata_files(version, commitish, s3_bucket_name):

s3_artifacts = S3Artifacts(s3_bucket_name)

commitish_short = commitish[:8]

for flavor in flavors:
cname = CName(flavor[1], flavor[0], "{0}-{1}".format(version, commitish_short))
LOGGER.debug(f"{flavor=} {version=} {commitish=}")
cname = CName(flavor[1], flavor[0], commitish)
# Filter by image variants - only download if the flavor matches one of the variants
flavor_matches_variant = False
for variant_suffix in IMAGE_VARIANTS:
Expand All @@ -86,34 +84,34 @@ def download_all_metadata_files(version, commitish, s3_bucket_name):
continue

try:
commit_short = commitish[:8]
download_metadata_file(
s3_artifacts, cname.cname, version, commitish_short, local_dest_path
s3_artifacts, cname, version, commit_short, local_dest_path
)
except IndexError:
LOGGER.warn(f"No artifacts found for flavor {cname.cname}, skipping...")
LOGGER.warning(f"No artifacts found for flavor {cname.cname}, skipping...")
continue

return [str(artifact) for artifact in local_dest_path.iterdir()]


def download_metadata_file(
s3_artifacts, cname, version, commitish_short, artifacts_dir
):
def download_metadata_file(s3_artifacts, cname, version, commit_short, artifacts_dir):
"""
Download metadata file (s3_metadata.yaml)
"""
LOGGER.debug(
f"{s3_artifacts=} | {cname=} | {version=} | {commitish_short=} | {artifacts_dir=}"
f"{s3_artifacts=} | {cname.cname=} | {version=} | {cname.commit_id=} | {commit_short=} | {artifacts_dir=}"
)
maybe_release_objects = s3_artifacts.bucket.objects.filter(
Prefix=f"meta/singles/{cname.cname}-{version}-{commit_short}"
)
release_object = list(
s3_artifacts._bucket.objects.filter(
Prefix=f"meta/singles/{cname}-{version}-{commitish_short}"
)
)[0]

release_object = list(maybe_release_objects)[0]
LOGGER.debug(f"{release_object.bucket_name=} | {release_object.key=}")

s3_artifacts.bucket.download_file(
release_object.key, artifacts_dir.joinpath(f"{cname}.s3_metadata.yaml")
release_object.key,
artifacts_dir.joinpath(f"{cname.cname}.s3_metadata.yaml"),
)


Expand Down
3 changes: 0 additions & 3 deletions src/gardenlinux/oci/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
gl-oci main entrypoint
"""

import os

import click
from pygments.lexer import default

from .container import Container

Expand Down
6 changes: 2 additions & 4 deletions src/gardenlinux/oci/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from base64 import b64encode
from collections.abc import Sequence
from configparser import UNNAMED_SECTION, ConfigParser
from hashlib import sha256
from os import PathLike, fdopen, getenv
from pathlib import Path
from tempfile import mkstemp
Expand All @@ -18,12 +17,11 @@

import jsonschema
from oras.container import Container as OrasContainer
from oras.defaults import unknown_config_media_type as UNKNOWN_CONFIG_MEDIA_TYPE
from oras.provider import Registry
from oras.utils import extract_targz, make_targz
from requests import Response

from ..constants import GL_MEDIA_TYPE_LOOKUP, OCI_IMAGE_INDEX_MEDIA_TYPE
from ..constants import OCI_IMAGE_INDEX_MEDIA_TYPE
from ..features.cname import CName
from ..logger import LoggerSetup
from .image_manifest import ImageManifest
Expand Down Expand Up @@ -117,7 +115,7 @@ def __init__(

# Login to registry if credentials are provided
if username and password:
self._logger.debug(f"Logging in with username/password")
self._logger.debug("Logging in with username/password")

try:
self.login(username, password)
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import os
import shutil
import subprocess
import sys
from datetime import datetime, timedelta
from tempfile import mkstemp
Expand All @@ -27,7 +26,7 @@
TEST_PLATFORMS,
TEST_VERSION,
)
from .helper import call_command, spawn_background_process
from .helper import spawn_background_process


def generate_test_certificates():
Expand Down
6 changes: 4 additions & 2 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
TEST_GARDENLINUX_COMMIT_SHORT = TEST_GARDENLINUX_COMMIT[:8]
TEST_GARDENLINUX_RELEASE_BUCKET_NAME = "test__gardenlinux__releases"

RELEASE_NOTES_TEST_DATA_DIR = Path(os.path.dirname(__file__)) / ".." / "test-data" / "release_notes"
RELEASE_NOTES_TEST_DATA_DIR = (
Path(os.path.dirname(__file__)) / ".." / "test-data" / "release_notes"
)
RELEASE_NOTES_S3_ARTIFACTS_DIR = RELEASE_NOTES_TEST_DATA_DIR / "s3_bucket_artifacts"

RELEASE_ARTIFACTS_METADATA_FILES = [
Expand Down Expand Up @@ -83,5 +85,5 @@
"openstack-gardener_prod_usi-amd64.s3_metadata.yaml",
"openstack-gardener_prod_usi-arm64.s3_metadata.yaml",
"vmware-gardener_prod-amd64.s3_metadata.yaml",
"vmware-gardener_prod-arm64.s3_metadata.yaml"
"vmware-gardener_prod-arm64.s3_metadata.yaml",
]
4 changes: 3 additions & 1 deletion tests/features/test_cname.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ def test_cname_commit_id_setter():
cname = CName("container", arch="amd64", version="today", commit_hash="local")

# Act / Assert
with pytest.raises(RuntimeError, match="Commit hash given differs from commit ID already set"):
with pytest.raises(
RuntimeError, match="Commit hash given differs from commit ID already set"
):
cname.commit_hash = "broken"
1 change: 0 additions & 1 deletion tests/features/test_cname_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest

import gardenlinux.features.cname_main as cname_main
from gardenlinux.features import CName


def test_main_happy(monkeypatch, capsys):
Expand Down
Loading
Loading