summaryrefslogtreecommitdiffstats
path: root/build/package.sh
diff options
context:
space:
mode:
authorTomáš Levora <t.levora@partner.samsung.com>2019-01-29 14:25:04 +0100
committerTomáš Levora <t.levora@partner.samsung.com>2019-02-07 14:41:23 +0100
commitade405a53f37d03866556bd87daf7a7af740fb74 (patch)
tree00072f3854818cc6f1b5b33100b93d506d98d22d /build/package.sh
parentc2a14cfae6d19c3c6c09394ca710f1871a48983d (diff)
Create offline data lists to cover Casablanca
Adding casablanca related data lists and changing the lists naming rule Modifying related download scripts accordingly Adding parameters for project version to download scripts to be able to use version specific lists Removing download-oom.sh as it should be done in helm charts preparation and patching steps Moving additional build related stuff to build directory Adding missing tags Issue-ID: OOM-1615 Change-Id: Ic5902f646a1f0f40ba615562f8d9b1a43cf8480b Signed-off-by: Tomáš Levora <t.levora@partner.samsung.com>
Diffstat (limited to 'build/package.sh')
-rwxr-xr-xbuild/package.sh228
1 files changed, 228 insertions, 0 deletions
diff --git a/build/package.sh b/build/package.sh
new file mode 100755
index 00000000..ee985339
--- /dev/null
+++ b/build/package.sh
@@ -0,0 +1,228 @@
+#! /usr/bin/env bash
+
+# COPYRIGHT NOTICE STARTS HERE
+#
+# Copyright 2018 © Samsung Electronics Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# COPYRIGHT NOTICE ENDS HERE
+
+
+# Scope of this packaging script is to generate tarfiles for offline installation
+# Build of any additional artifacts is out of scope for this script
+
+crash () {
+ local exit_code="$1"
+ local cause="$2"
+ echo "Packaging script finished prematuraly"
+ echo "Cause: $2"
+ exit "${exit_code}"
+}
+
+usage () {
+ echo "Usage:"
+ echo " ./$(basename $0) <project_name> <version> <packaging_target_dir>"
+ echo "Example: ./$(basename $0) onap 1.0.1 /tmp/package_onap_1.0.0"
+ echo "packaging_target_dir will be created if does not exist. All tars will be produced into it."
+}
+
+function create_tar {
+ local tar_dir="$1"
+ local tar_name="$2"
+
+ cd ${tar_dir}
+ touch ${tar_name} # Trick to avoid sporadic "tar: .: file changed as we read it" warning message
+ tar --exclude=${tar_name} -cf ../${tar_name} .
+ cd - &> /dev/null # Trick to avoid printing new dir on stdout
+
+ # Remove packaged folders
+ find ${tar_dir}/* -maxdepth 0 -type d -exec rm -rf '{}' \;
+ # Remove packaged files
+ find ${tar_dir}/* ! -name ${tar_name} -exec rm '{}' \;
+ echo "tar file ${tar_name} created in target dir"
+}
+
+function add_metadata {
+ local metafile="$1"
+
+ echo "Project name: ${PROJECT_NAME}" >> "${metafile}"
+ echo "Project version: ${PROJECT_VERSION}" >> "${metafile}"
+ echo "Package date: ${TIMESTAMP}" >> "${metafile}"
+}
+
+function add_additions {
+ local source="$1"
+ local target="$2"
+
+ if [ -d "${source}" ]; then
+ mkdir -p "${target}/$(basename $source)"
+ cp -r "${source}" "${target}"
+ echo "Adding directory ... $(basename $source)"
+ else
+ if [ -f "${source}" ]; then
+ cp "${source}" "${target}"
+ echo "Adding file ... $(basename $source)"
+ else
+ crash 4 "Invalid source specified for packaging: $1"
+ fi
+ fi
+}
+
+function build_sw_artifacts {
+ cd ../ansible/docker
+ ./build_ansible_image.sh
+ if [ $? -ne 0 ]; then
+ crash 5 "Building of ansible runner image failed."
+ fi
+ cd -
+}
+
+function create_sw_package {
+ local pkg_root="${PACKAGING_TARGET_DIR}/onap"
+
+ # Create tar package
+ echo "[Creating software package]"
+
+ # Create directory structure of the sw package
+ mkdir -p "${pkg_root}"
+ cp -r ansible "${pkg_root}"
+
+ # Add additional files/dirs into package based on package.conf
+ for item in "${SW_PACKAGE_ADDONS[@]}";do
+ # all SW package addons are expected within ./ansible/application folder
+ add_additions "${item}" "${pkg_root}/ansible/application"
+ done
+
+ # Helm charts handling
+ echo "Helm charts handling"
+ # Copy charts available for ansible playbook to use/move them to target server/dir
+ mkdir -p "${pkg_root}"/ansible/application/helm_charts
+ cp -r "${HELM_CHARTS_DIR}"/* "${pkg_root}"/ansible/application/helm_charts
+
+ # Add metadata to the package
+ add_metadata "${pkg_root}"/package.info
+
+ # Create sw tar package
+ echo "Creating tar file ..."
+ PACKAGE_BASE_NAME="${SOFTWARE_PACKAGE_BASENAME}"
+ create_tar "${pkg_root}" ${PACKAGE_BASE_NAME}-${PROJECT_NAME}-${PROJECT_VERSION}-sw.tar
+ rm -rf "${pkg_root}"
+}
+
+function create_resource_package {
+ local pkg_root="${PACKAGING_TARGET_DIR}/resources"
+
+ # Create resource tar package
+ echo "[Creating resource package]"
+
+ # Create directory structure of the resource package
+ mkdir -p "${pkg_root}"
+
+ # Add artifacts into resource packagee based on package.conf config
+ for item in "${EXTERNAL_BINARIES_PACKAGE_ADDONS[@]}";do
+ if [ "$(basename $item)" == "resources" ]; then
+ echo "Note: Packaging all resources at once"
+ add_additions "${item}" "${PACKAGING_TARGET_DIR}"
+ else
+ add_additions "${item}" "${pkg_root}"
+ fi
+ done
+
+ # tar file with nexus_data is expected, we should find and untar it
+ # before resource.tar is created
+ for i in `ls -1 ${pkg_root} | grep tar`; do
+ tar tvf "${pkg_root}/${i}" | grep nexus_data &> /dev/null
+ if [ $? -eq 0 ]; then
+ echo "Debug: tar file with nexus blobs detected ${pkg_root}/${i}. Start unarchive ..."
+ tar xf "${pkg_root}/${i}" -C "${pkg_root}" &> /dev/null
+ echo "Debug: unarchive finished. Removing original file"
+ rm -f "${pkg_root}/${i}"
+ fi
+ done
+
+ echo "Creating tar file ..."
+ PACKAGE_BASE_NAME="${SOFTWARE_PACKAGE_BASENAME}"
+ create_tar "${pkg_root}" "${PACKAGE_BASE_NAME}-${PROJECT_NAME}-${PROJECT_VERSION}-resources.tar"
+ rm -rf "${pkg_root}"
+}
+
+function create_aux_package {
+ local pkg_root="${PACKAGING_TARGET_DIR}/aux"
+
+ # Create aux resource tar package
+ echo "Creating aux resource package"
+
+ # Create directory structure of the aux resource package
+ mkdir -p "${pkg_root}"
+
+ # Add artifacts into resource packagee based on package.conf config
+ for item in "${AUX_BINARIES_PACKAGE_ADDONS[@]}";do
+ add_additions "${item}" "${pkg_root}"
+ done
+
+ echo "Creating tar file ..."
+ PACKAGE_BASE_NAME="${SOFTWARE_PACKAGE_BASENAME}"
+ create_tar "${pkg_root}" "${PACKAGE_BASE_NAME}-${PROJECT_NAME}-${PROJECT_VERSION}-aux-resources.tar"
+ rm -rf "${pkg_root}"
+}
+
+#
+# =================== Main ===================
+#
+
+PROJECT_NAME="$1"
+PROJECT_VERSION="$2"
+PACKAGING_TARGET_DIR="$3"
+
+TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
+
+# ensure that package.conf is sourced even when package.sh executed from another place
+SCRIPT_DIR=$(dirname "${0}")
+LOCAL_PATH=$(readlink -f "$SCRIPT_DIR")
+
+# lets start from script directory as some path in script are relative
+pushd "${LOCAL_PATH}"
+source ./package.conf
+
+
+if [ "$#" -lt 3 ]; then
+ echo "Missing some mandatory parameter!"
+ usage
+ exit 1
+fi
+
+if [ ! -f "./package.conf" ]; then
+ crash 2 "Mandatory config file ./package.conf missing!"
+fi
+
+# checking bash capability of parsing arrays
+whotest[0]='test' || (crash 3 "Arrays not supported in this version of bash.")
+
+
+# Prepare output directory for our packaging and create all tars
+
+rm -rf ${PACKAGING_TARGET_DIR}
+build_sw_artifacts
+create_sw_package
+create_resource_package
+
+# This part will create aux package which consists of
+# artifacts which can be added into offline nexus during runtime
+if [ "${PREPARE_AUX_PACKAGE}" == "true" ]; then
+ create_aux_package
+else
+ echo "AUX package won't be created"
+fi
+
+popd