Repository: opensearch-project/opensearch-build

Issue:
[RPM M1] Add a new block to call the generation code for RPM
Tasks | Estimate | Status | Notes | Dependencies
-- | -- | -- | -- | --
The generation code should pull the artifacts from the build workflow to a temporary location | 1 | Complete |   | Build workflow must provide usable artifacts
The code will call existing install function to install plugins on min artifacts | 1 | Complete |   |  
After installation, the code will execute a tool or utility to wrap all the content into a RPM package | 5 | Complete | Require writing a script to utilize FPM to start with and later implement in pure python code. <br><br>20220204: We might change to rpmbuild directly without using FPM. See comments. | FPM usages
The code will also add dependencies to the RPM package so that things like JDK and additional libs for plugins can be installed and pulled separately | 5 | Complete | Need to study on RPM dependency setups | RPM Build Dependencies and the locations of each dependent artifact
The code will move the RPM package from the temp location to dist folder | 2 | Complete |   |  




Discussion:
20220204: FPM is having some issues along the way:
* Messy handling of folder structure, as it will add every single file under `%files` section instead of owning folders, so erase of the package will not do proper clean up.
* Need to specifically set `--rpm-summary` for RPM, and debian has a different command, which is not suitable for the usages.
* If build on non-linux machine, `--rpm-os` is needed as another specific command that debian version does not own.
* Very large rpm spec file generated during runtimes, lack of many settings, need manual editing during runtime of the tool.
* Cannot source a spec file directly for a build, have to use the existing template.
* Documentation kind of lackluster as there are duplication of commands man page, and I need to dig through issues and issues to find some commands for my needs.

Overall, it is a great tool for quick building an RPM without spec file.
However, for our production usages I think using rpmbuild directly probably better here.

Still testing.

Resolving patch:
diff --git a/src/assemble_workflow/bundle_rpm.py b/src/assemble_workflow/bundle_rpm.py
--- a/src/assemble_workflow/bundle_rpm.py
+++ b/src/assemble_workflow/bundle_rpm.py
@@ -99,7 +99,7 @@ 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 '_architecture_alt {rpm_architecture(build_cls.architecture)}'",
+                f"--define '_architecture {rpm_architecture(build_cls.architecture)}'",
                 f"{self.filename}.rpm.spec",
             ]
         )


Test patch:
diff --git a/tests/tests_assemble_workflow/test_bundle_rpm.py b/tests/tests_assemble_workflow/test_bundle_rpm.py
--- a/tests/tests_assemble_workflow/test_bundle_rpm.py
+++ b/tests/tests_assemble_workflow/test_bundle_rpm.py
@@ -52,5 +52,5 @@ def test_build_rpm(self, check_call_mock: Mock, shutil_move_mock: Mock, builtins
 
         self.assertRaises(KeyError, lambda: os.environ['OPENSEARCH_PATH_CONF'])
         self.assertEqual(check_call_mock.call_count, 1)
-        self.assertEqual(f"rpmbuild -bb --define '_topdir {self.artifacts_path}' --define '_version 1.3.0' --define '_architecture_alt x86_64' opensearch.rpm.spec", args_list[0][0][0])
+        self.assertEqual(f"rpmbuild -bb --define '_topdir {self.artifacts_path}' --define '_version 1.3.0' --define '_architecture x86_64' opensearch.rpm.spec", args_list[0][0][0])
         self.assertEqual(shutil_move_mock.call_count, 3)