Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPM M1] Assemble artifacts based on distribution not file extension #1659

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion src/assemble_workflow/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from assemble_workflow.bundle_recorder import BundleRecorder
from assemble_workflow.dist import Dist
from assemble_workflow.dists import Dists
from manifests.build_manifest import BuildComponent, BuildComponents, BuildManifest
from paths.script_finder import ScriptFinder
from system.temporary_directory import TemporaryDirectory
Expand Down Expand Up @@ -132,7 +133,8 @@ def __get_min_dist(self, build_components: BuildComponents) -> Dist:
min_dist_path = self._copy_component(min_bundle, "dist")
logging.info(f"Copied min bundle to {min_dist_path}.")
min_path = f"{self.build.filename}-{self.build.version}".replace("-SNAPSHOT", "")
min_dist = Dist.from_path(min_bundle.name, min_dist_path, min_path)
logging.info(f"Start creating distribution {self.build.distribution} for {min_bundle.name}.")
min_dist = Dists.create_dist(min_bundle.name, min_dist_path, min_path, self.build.distribution)
logging.info(f"Extracting dist into {self.tmp_dir.name}.")
min_dist.extract(self.tmp_dir.name)
logging.info(f"Extracted dist into {self.tmp_dir.name}.")
Expand Down
13 changes: 11 additions & 2 deletions src/assemble_workflow/bundle_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@


class BundleRecorder:
EXTENSIONS = {
"tar": ".tar.gz",
"zip": ".zip",
}

def __init__(self, build: BuildManifest.Build, output_dir: str, artifacts_dir: str, bundle_location: BundleLocation) -> None:
self.output_dir = output_dir
self.build_id = build.id
self.bundle_location = bundle_location
self.version = build.version
self.distribution = build.distribution
self.package_name = self.__get_package_name(build)
self.artifacts_dir = artifacts_dir
self.architecture = build.architecture
Expand All @@ -27,6 +33,7 @@ def __init__(self, build: BuildManifest.Build, output_dir: str, artifacts_dir: s
build.version,
build.platform,
build.architecture,
build.distribution,
self.__get_package_location(),
)

Expand All @@ -37,7 +44,8 @@ def __get_package_name(self, build: BuildManifest.Build) -> str:
build.platform,
build.architecture,
]
return "-".join(parts) + (".zip" if build.platform == "windows" else ".tar.gz")
extension = self.EXTENSIONS[self.distribution] if self.distribution else self.EXTENSIONS['tar']
return "-".join(parts) + extension

# Assembled output are expected to be served from a separate "dist" folder
# Example: https://ci.opensearch.org/ci/dbc/bundle-build/1.2.0/build-id/linux/x64/dist/
Expand Down Expand Up @@ -66,14 +74,15 @@ def write_manifest(self, folder: str) -> None:
self.get_manifest().to_file(manifest_path)

class BundleManifestBuilder:
def __init__(self, build_id: str, name: str, version: str, platform: str, architecture: str, location: str) -> None:
def __init__(self, build_id: str, name: str, version: str, platform: str, architecture: str, distribution: str, location: str) -> None:
self.data: Dict[str, Any] = {}
self.data["build"] = {}
self.data["build"]["id"] = build_id
self.data["build"]["name"] = name
self.data["build"]["version"] = str(version)
self.data["build"]["platform"] = platform
self.data["build"]["architecture"] = architecture
self.data["build"]["distribution"] = distribution if distribution else "tar"
self.data["build"]["location"] = location
self.data["schema-version"] = "1.1"
# We need to store components as a hash so that we can append artifacts by component name
Expand Down
10 changes: 0 additions & 10 deletions src/assemble_workflow/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ def build(self, name: str, dest: str) -> None:
shutil.copyfile(name, path)
logging.info(f"Published {path}.")

@classmethod
def from_path(cls, name: str, path: str, min_path: str) -> 'Dist':
ext = os.path.splitext(path)[1]
if ext == ".gz":
return DistTar(name, path, min_path)
elif ext == ".zip":
return DistZip(name, path, min_path)
else:
raise ValueError(f'Invalid min "dist" extension in input artifacts: {ext} ({path}).')


class DistZip(Dist):
def __extract__(self, dest: str) -> None:
Expand Down
24 changes: 24 additions & 0 deletions src/assemble_workflow/dists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import logging

from assemble_workflow.dist import Dist, DistTar, DistZip


class Dists:
DISTRIBUTIONS_MAP = {
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
"tar": DistTar,
"zip": DistZip,
}

@classmethod
def create_dist(cls, name: str, path: str, min_path: str, distribution: str) -> Dist:
if distribution is None:
logging.info("Distribution not specified, default to tar")
distribution = 'tar'

return cls.DISTRIBUTIONS_MAP[distribution](name, path, min_path)
2 changes: 2 additions & 0 deletions src/manifests/build_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
version: string
platform: linux, darwin or windows
architecture: x64 or arm64
distribution: tar, zip, and rpm
id: build id
components:
- name: string
repository: URL of git repository
Expand Down
9 changes: 9 additions & 0 deletions src/manifests/bundle_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class BundleManifest(ComponentManifest['BundleManifest', 'BundleComponents']):
version: string
platform: linux, darwin or windows
architecture: x64 or arm64
distribution: tar, zip, and rpm
id: build id
location: /relative/path/to/tarball
components:
- name: string
Expand All @@ -39,6 +41,7 @@ class BundleManifest(ComponentManifest['BundleManifest', 'BundleComponents']):
"schema": {
"platform": {"required": True, "type": "string"}, # added in 1.1
"architecture": {"required": True, "type": "string"},
"distribution": {"type": "string"},
"id": {"required": True, "type": "string"},
"location": {"required": True, "type": "string"},
"name": {"required": True, "type": "string"},
Expand Down Expand Up @@ -80,6 +83,7 @@ def __init__(self, data: Dict[str, str]):
self.version = data["version"]
self.platform = data["platform"]
self.architecture = data["architecture"]
self.distribution: str = data.get('distribution', None)
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
self.location = data["location"]
self.id = data["id"]

Expand All @@ -89,10 +93,15 @@ def __to_dict__(self) -> dict:
"version": self.version,
"platform": self.platform,
"architecture": self.architecture,
"distribution": self.distribution,
"location": self.location,
"id": self.id,
}

@property
def filename(self) -> str:
return self.name.lower().replace(" ", "-")


class BundleComponents(Components['BundleComponent']):
@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This page intentionally left blank.
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading