Skip to content

Commit

Permalink
[Bundle] post-install for core applications
Browse files Browse the repository at this point in the history
Adding install script for OpenSearch and OpenSearch Dashboards so
the bundles include default files.

These files include:
* opensearch-tar-install.sh
* config/opensearch_dashboards.yml

However, we did not want to include opensearch-tar-install.sh into
the OpenSearch Dashboards bundle because the script will fail to
execute as it is only expected to be an OpenSearch project.

Issue resolved:
#610

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Oct 19, 2021
1 parent d087733 commit 7e81e24
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 30 deletions.
40 changes: 40 additions & 0 deletions scripts/components/OpenSearch-Dashboards/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# 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.

set -ex

function usage() {
echo "Usage: $0 [args]"
echo ""
echo "Arguments:"
echo -e "-a ARTIFACTS\t[Required] Location of build artifacts."
echo -e "-o OUTPUT\t[Required] Output path."
echo -e "-h help"
}

while getopts ":h:a:o:" arg; do
case $arg in
o)
OUTPUT=$OPTARG
;;
a)
ARTIFACTS=$OPTARG
;;
h)
usage
exit 1
;;
?)
echo "Invalid option: -${arg}"
exit 1
;;
esac
done

## Setup default config
(DIR="$(dirname "$0")"; echo $DIR; cd $DIR; cp ../../../config/opensearch_dashboards.yml "$OUTPUT/config/")
40 changes: 40 additions & 0 deletions scripts/components/OpenSearch/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# 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.

set -ex

function usage() {
echo "Usage: $0 [args]"
echo ""
echo "Arguments:"
echo -e "-a ARTIFACTS\t[Required] Location of build artifacts."
echo -e "-o OUTPUT\t[Required] Output path."
echo -e "-h help"
}

while getopts ":h:a:o:" arg; do
case $arg in
o)
OUTPUT=$OPTARG
;;
a)
ARTIFACTS=$OPTARG
;;
h)
usage
exit 1
;;
?)
echo "Invalid option: -${arg}"
exit 1
;;
esac
done

## Copy the tar installation script into the bundle
(DIR="$(dirname "$0")"; echo $DIR; cd $DIR; cp ../../../scripts/legacy/tar/linux/opensearch-tar-install.sh "$OUTPUT/")
6 changes: 6 additions & 0 deletions src/assemble_workflow/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def __init__(self, build_manifest, artifacts_dir, bundle_recorder):
self.min_tarball_path = self._copy_component(self.min_tarball, "dist")
self.__unpack_min_tarball(self.tmp_dir.name)

def install_core(self):
post_install_script = ScriptFinder.find_install_script(self.min_tarball.name)
self._execute(
f'{post_install_script} -a "{self.artifacts_dir}" -o "{self.archive_path}"'
)

def install_plugins(self):
for plugin in self.plugins:
logging.info(f"Installing {plugin.name}")
Expand Down
21 changes: 1 addition & 20 deletions src/run_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ def main():

console.configure(level=args.logging_level)

tarball_installation_script = os.path.realpath(
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../scripts/legacy/tar/linux/opensearch-tar-install.sh",
)
)
if not os.path.isfile(tarball_installation_script):
logging.error(
f"No installation script found at path: {tarball_installation_script}"
)
exit(1)

build_manifest = BuildManifest.from_file(args.manifest)
build = build_manifest.build
artifacts_dir = os.path.dirname(os.path.realpath(args.manifest.name))
Expand All @@ -64,17 +52,10 @@ def main():

bundle = Bundles.create(build_manifest, artifacts_dir, bundle_recorder)

bundle.install_core()
bundle.install_plugins()
logging.info(f"Installed plugins: {bundle.installed_plugins}")

# Copy the tar installation script into the bundle
shutil.copy2(
tarball_installation_script,
os.path.join(
bundle.archive_path, os.path.basename(tarball_installation_script)
),
)

# Save a copy of the manifest inside of the tar
bundle_recorder.write_manifest(bundle.archive_path)
bundle.build_tar(output_dir)
Expand Down
11 changes: 1 addition & 10 deletions tests/test_run_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,9 @@ def test_main(self, mock_copy, mock_temp, mock_recorder, mock_bundles, *mocks):

main()

mock_bundle.install_core.assert_called()
mock_bundle.install_plugins.assert_called()

mock_copy.assert_called_with(
os.path.realpath(
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../scripts/legacy/tar/linux/opensearch-tar-install.sh",
)
),
"path/opensearch-tar-install.sh",
)

mock_bundle.build_tar.assert_called_with("curdir/bundle")

mock_recorder.return_value.write_manifest.assert_has_calls(
Expand Down
24 changes: 24 additions & 0 deletions tests/tests_assemble_workflow/test_bundle_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ def test_bundle_opensearch(self):
)
self.assertIsNotNone(bundle.archive_path)

def test_bundle_install_core(self):
manifest_path = os.path.join(
os.path.dirname(__file__), "data/opensearch-build-1.1.0.yml"
)
artifacts_path = os.path.join(os.path.dirname(__file__), "data/artifacts")
bundle = BundleOpenSearch(
BuildManifest.from_path(manifest_path), artifacts_path, MagicMock()
)

with patch("subprocess.check_call") as mock_check_call:
bundle.install_core()

self.assertEqual(mock_check_call.call_count, 1)

mock_check_call.assert_has_calls(
[
call(
f'{ScriptFinder.find_install_script("OpenSearch")} -a "{artifacts_path}" -o "{bundle.archive_path}"',
cwd=bundle.archive_path,
shell=True,
),
]
)

@patch.object(BundleOpenSearch, "install_plugin")
def test_bundle_install_plugins(self, mocks_bundle):
manifest_path = os.path.join(
Expand Down
24 changes: 24 additions & 0 deletions tests/tests_assemble_workflow/test_bundle_opensearch_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ def test_bundle_opensearch_dashboards(self):
)
self.assertIsNotNone(bundle.archive_path)

def test_bundle_install_core(self):
manifest_path = os.path.join(
os.path.dirname(__file__), "data/opensearch-dashboards-build-1.1.0.yml"
)
artifacts_path = os.path.join(os.path.dirname(__file__), "data/artifacts")
bundle = BundleOpenSearchDashboards(
BuildManifest.from_path(manifest_path), artifacts_path, MagicMock()
)

with patch("subprocess.check_call") as mock_check_call:
bundle.install_core()

self.assertEqual(mock_check_call.call_count, 1)

mock_check_call.assert_has_calls(
[
call(
f'{ScriptFinder.find_install_script("OpenSearch-Dashboards")} -a "{artifacts_path}" -o "{bundle.archive_path}"',
cwd=bundle.archive_path,
shell=True,
),
]
)

@patch("os.path.isfile", return_value=True)
def test_bundle_install_plugin(self, *mocks):
manifest_path = os.path.join(
Expand Down

0 comments on commit 7e81e24

Please sign in to comment.