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

Support release iteration value for assemble workflow rpm #1921

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
%define log_dir %{_localstatedir}/log/%{name}
%define pid_dir %{_localstatedir}/run/%{name}
%{!?_version: %define _version 0.0.0 }
%{!?_release: %define _release 1 }
%{!?_architecture: %define _architecture x86_64 }

Name: opensearch-dashboards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
%define log_dir %{_localstatedir}/log/%{name}
%define pid_dir %{_localstatedir}/run/%{name}
%{!?_version: %define _version 0.0.0 }
%{!?_release: %define _release 1 }
%{!?_architecture: %define _architecture x86_64 }

Name: opensearch
Version: %{_version}
Release: 1
Release: %{_release}
License: Apache-2.0
Summary: An open source distributed and RESTful search engine
URL: https://opensearch.org/
Expand Down
17 changes: 16 additions & 1 deletion src/assemble_workflow/assemble_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@
import logging
from typing import IO


class AssembleArgs:
manifest: IO
keep: bool

def __init__(self) -> None:

def check_positive(value) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add type for the input. value: str

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not allow me to block non-positive inputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this method private.

int_value = int(value)
if int_value <= 0:
raise argparse.ArgumentTypeError(f"{value} is invalid, you must enter a positive integer")
return str(int_value)

parser = argparse.ArgumentParser(description="Assemble an OpenSearch Distribution")
parser.add_argument("manifest", type=argparse.FileType("r"), help="Manifest file.")
parser.add_argument("-b", "--base-url", dest="base_url", help="The base url to download the artifacts.")
parser.add_argument(
"-r",
"--release-iteration",
dest="release_iteration",
type=check_positive,
default="1",
help="The release/iteration number of deb/rpm packages, allow multiple revision of same package version (e.g. 2.0.0-1, 2.0.0-2, 2.0.0-3)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revision -> revisions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help missing period, is too long and has grammar issues. Just say "Release number."

)
parser.add_argument(
"--keep",
dest="keep",
Expand All @@ -38,3 +52,4 @@ def __init__(self) -> None:
self.manifest = args.manifest
self.keep = args.keep
self.base_url = args.base_url
self.release_iteration = args.release_iteration
2 changes: 1 addition & 1 deletion src/assemble_workflow/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def install_plugin(self, plugin: BuildComponent) -> None:
self._execute(install_command)

def package(self, dest: str) -> None:
self.min_dist.build(self.bundle_recorder.package_name, dest)
self.min_dist.build(self.bundle_recorder.package_name, self.bundle_recorder.release_iteration, dest)

def _execute(self, command: str) -> None:
logging.info(f'Executing "{command}" in {self.min_dist.archive_path}')
Expand Down
3 changes: 2 additions & 1 deletion src/assemble_workflow/bundle_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

class BundleRecorder:

def __init__(self, build: BuildManifest.Build, output_dir: str, artifacts_dir: str, bundle_location: BundleLocation) -> None:
def __init__(self, build: BuildManifest.Build, release_iteration: str, 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.release_iteration = release_iteration
self.distribution = build.distribution
self.package_name = self.__get_package_name(build)
self.artifacts_dir = artifacts_dir
Expand Down
4 changes: 3 additions & 1 deletion src/assemble_workflow/bundle_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def extract(self, dest: str) -> None:
with open(min_bin_env_path, 'wb') as fp:
fp.write(min_bin_env_lines.replace('source', '#source').encode('ascii'))

def build(self, name: str, dest: str, archive_path: str, build_cls: BuildManifest.Build) -> None:
def build(self, name: str, dest: str, archive_path: str, build_cls: BuildManifest.Build, release_iteration: str) -> None:
# extract dest and build dest are not the same, this is restoring the extract dest
# mainly due to rpm requires several different setups compares to tarball and zip
ext_dest = os.path.dirname(archive_path)
Expand All @@ -102,11 +102,13 @@ def build(self, name: str, dest: str, archive_path: str, build_cls: BuildManifes
'-bb',
f"--define '_topdir {ext_dest}'",
f"--define '_version {build_cls.version}'",
f"--define '_release {release_iteration}'",
f"--define '_architecture {rpm_architecture(build_cls.architecture)}'",
f"{self.filename}.rpm.spec",
]
)

logging.info(f"Generate {self.filename}-{build_cls.version}-{release_iteration}.{rpm_architecture(build_cls.architecture)}.rpm")
logging.info(f"Execute {bundle_cmd} in {ext_dest}")
subprocess.check_call(bundle_cmd, cwd=ext_dest, shell=True)

Expand Down
8 changes: 4 additions & 4 deletions src/assemble_workflow/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def extract(self, dest: str) -> str:
)
return self.archive_path

def build(self, name: str, dest: str) -> None:
self.__build__(name, dest)
def build(self, name: str, release_iteration: str, dest: str) -> None:
self.__build__(name, release_iteration, dest)
path = os.path.join(dest, name)
shutil.copyfile(name, path)
logging.info(f"Published {path}.")
Expand Down Expand Up @@ -114,5 +114,5 @@ class DistRpm(Dist):
def __extract__(self, dest: str) -> None:
BundleRpm(self.filename, self.path, self.min_path).extract(dest)

def __build__(self, name: str, dest: str) -> None:
BundleRpm(self.filename, self.path, self.min_path).build(name, dest, self.archive_path, self.build_cls)
def __build__(self, name: str, release_iteration: str, dest: str) -> None:
BundleRpm(self.filename, self.path, self.min_path).build(name, dest, self.archive_path, self.build_cls, release_iteration)
2 changes: 2 additions & 0 deletions src/run_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ def main() -> int:
build_manifest = BuildManifest.from_file(args.manifest)
build = build_manifest.build
artifacts_dir = os.path.dirname(os.path.realpath(args.manifest.name))
release_iteration = args.release_iteration

output_dir = AssembleOutputDir(build.filename).dir

logging.info(f"Bundling {build.name} ({build.architecture}) on {build.platform} into {output_dir} ...")

bundle_recorder = BundleRecorder(
build,
release_iteration,
output_dir,
artifacts_dir,
BundleLocations.from_path(args.base_url, os.getcwd(), build.filename)
Expand Down