summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Ospalý <p.ospaly@partner.samsung.com>2018-12-20 16:40:58 +0100
committerPetr Ospalý <p.ospaly@partner.samsung.com>2018-12-20 16:44:19 +0100
commit170d94b0a8fde81800705e5db04938a283f39a6a (patch)
tree5ab197035e01be710cabba4e7c8ebb74837027ee
parent8e5a7da840ed7420f46bef9054a4d257ee6d4a7b (diff)
Add the package.sh with a template
It can be used to distribution of a project via tars. What is part of the package is defined in package.conf Issue-ID: OOM-1551 Change-Id: I8f5509bfb37d5cad510c0c151d49f6944fc6511c Signed-off-by: Petr Ospalý <p.ospaly@partner.samsung.com>
-rwxr-xr-xansible/group_vars/all.yml6
-rw-r--r--package.conf71
-rwxr-xr-xpackage.sh218
3 files changed, 292 insertions, 3 deletions
diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index fad84e07..425f4f14 100755
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -71,11 +71,11 @@ app_name:
# prebuilt nexus blob in installation time
# Component name must match with tar filename
# e.g.
-# aaiadapter-0.0.1.tar is expected in aux_data_path for aaiadapter image
+# aaa-component-0.0.1.tar is expected in aux_data_path for aaa-component image
#runtime_images:
-# aaiadapter-0.0.1:
+ # aaa-component-0.0.1:
# registry: "nexus3.onap.org:10001"
-# path: "/onap/aaiadapter/aaiadapter"
+# path: "/onap/components/aaa-component"
# tag: "latest"
runtime_images:
diff --git a/package.conf b/package.conf
new file mode 100644
index 00000000..1141798b
--- /dev/null
+++ b/package.conf
@@ -0,0 +1,71 @@
+# For the packaging script it is expected that all artifacts are present on local file system
+# (e.g. they can be mounted) Downloading stuff from internet is currently not supported.
+# Furthermore we don't want to replicate content of our static data_lists for download in there
+# and those are downloaded before this packaging script is supposed to be run.
+# Therefore we can limit number of artifacts to be added into packages just to couple of items.
+
+###########################
+# Project specific params #
+###########################
+
+# Final package name will be ${SOFTWARE_PACKAGE_BASENAME}-${PROJECT_NAME}-${PROJECT_VERSION}.tar
+SOFTWARE_PACKAGE_BASENAME="onap-offline"
+
+########################
+# Helm charts handling #
+########################
+
+# directory with helm charts
+HELM_CHARTS_DIR="/root/oom"
+
+
+###################
+# Packages addons #
+###################
+
+# in there we define array of files/directories to be added into particular packages
+# SW_PACKAGE_ADDONS are offline installer specific entries which are supposed to be inserted
+# into ./ansible/application directory which is the only place where installer expects SW addons
+# if directory is specified, whole dir will be copied into ./ansible/application inc. subdirs
+# if file is specified it will be just copied into ./ansible/application folder.
+#
+SW_PACKAGE_ADDONS=(
+ '/root/ansible/application/onap-me-patch-role'
+ '/root/ansible/application/application_configuration.yml'
+)
+
+# following array contains directories and files from where offline installer can get required artifacts
+# following binaries and files are expected:
+# <path_to_downloads>/downloads ... path to directory with application binaries (e.g. rancher, kubectl, jq, helm)
+# <path_to_git-repo>/git-repo ... path to directory with git repos
+# <path_to_http>/http ... path to directory with http files
+# <path_to_offline_data>/offline_data ... path to directory with infra specific docker images
+# <path_to_pkg>/pkg ... path to directory with rpm/deb packages
+# <path_to_nexus_blob>/nexus_data.tar ... path to tar file with collected nexus blobs (output of different script)
+#
+# alternatively and if all above is available just ./resources folder with contain all of those might be used
+# <path_to_complete_resources_folder>/resources
+#
+
+EXTERNAL_BINARIES_PACKAGE_ADDONS=(
+ '/root/resources'
+)
+#EXTERNAL_BINARIES_PACKAGE_ADDONS=(
+# '/root/resources/downloads'
+# '/root/resources/git-repo'
+# '/root/resources/http'
+# '/root/resources/offline_data'
+# '/root/resources/pkg'
+# '/root/resources/nexus_data.tar'
+#)
+
+# this param should be set to true if additional application package is supposed to be created
+#
+PREPARE_AUX_PACKAGE="true"
+
+# tar files with additional application images supposed to be inserted into nexus during runtime are expected
+#
+#AUX_BINARIES_PACKAGE_ADDONS=(
+# '/root/resource_aux/aaa-component-0.0.1.tar'
+# '/root/resource_aux/xyz-component-0.0.1.tar'
+#)
diff --git a/package.sh b/package.sh
new file mode 100755
index 00000000..3a4d12bc
--- /dev/null
+++ b/package.sh
@@ -0,0 +1,218 @@
+#! /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-me 1.0.1 /tmp/package_onap-me_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 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}
+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