3 # COPYRIGHT NOTICE STARTS HERE
5 # Copyright 2018 © Samsung Electronics Co., Ltd.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # COPYRIGHT NOTICE ENDS HERE
22 # Scope of this packaging script is to generate tarfiles for offline installation
23 # Build of any additional artifacts is out of scope for this script
28 echo "Packaging script finished prematuraly"
35 echo " ./$(basename $0) <project_name> <version> <packaging_target_dir>"
36 echo "Example: ./$(basename $0) onap-me 1.0.1 /tmp/package_onap-me_1.0.0"
37 echo "packaging_target_dir will be created if does not exist. All tars will be produced into it."
45 touch ${tar_name} # Trick to avoid sporadic "tar: .: file changed as we read it" warning message
46 tar --exclude=${tar_name} -cf ../${tar_name} .
47 cd - &> /dev/null # Trick to avoid printing new dir on stdout
49 # Remove packaged folders
50 find ${tar_dir}/* -maxdepth 0 -type d -exec rm -rf '{}' \;
51 # Remove packaged files
52 find ${tar_dir}/* ! -name ${tar_name} -exec rm '{}' \;
53 echo "tar file ${tar_name} created in target dir"
56 function add_metadata {
59 echo "Project name: ${PROJECT_NAME}" >> "${metafile}"
60 echo "Project version: ${PROJECT_VERSION}" >> "${metafile}"
61 echo "Package date: ${TIMESTAMP}" >> "${metafile}"
64 function add_additions {
68 if [ -d "${source}" ]; then
69 mkdir -p "${target}/$(basename $source)"
70 cp -r "${source}" "${target}"
71 echo "Adding directory ... $(basename $source)"
73 if [ -f "${source}" ]; then
74 cp "${source}" "${target}"
75 echo "Adding file ... $(basename $source)"
77 crash 4 "Invalid source specified for packaging: $1"
82 function create_sw_package {
83 local pkg_root="${PACKAGING_TARGET_DIR}/onap"
86 echo "[Creating software package]"
88 # Create directory structure of the sw package
89 mkdir -p "${pkg_root}"
90 cp -r ansible "${pkg_root}"
92 # Add additional files/dirs into package based on package.conf
93 for item in "${SW_PACKAGE_ADDONS[@]}";do
94 # all SW package addons are expected within ./ansible/application folder
95 add_additions "${item}" "${pkg_root}/ansible/application"
98 # Helm charts handling
99 echo "Helm charts handling"
100 # Copy charts available for ansible playbook to use/move them to target server/dir
101 mkdir -p "${pkg_root}"/ansible/application/helm_charts
102 cp -r "${HELM_CHARTS_DIR}"/* "${pkg_root}"/ansible/application/helm_charts
104 # Add metadata to the package
105 add_metadata "${pkg_root}"/package.info
107 # Create sw tar package
108 echo "Creating tar file ..."
109 PACKAGE_BASE_NAME="${SOFTWARE_PACKAGE_BASENAME}"
110 create_tar "${pkg_root}" ${PACKAGE_BASE_NAME}-${PROJECT_NAME}-${PROJECT_VERSION}-sw.tar
114 function create_resource_package {
115 local pkg_root="${PACKAGING_TARGET_DIR}/resources"
117 # Create resource tar package
118 echo "[Creating resource package]"
120 # Create directory structure of the resource package
121 mkdir -p "${pkg_root}"
123 # Add artifacts into resource packagee based on package.conf config
124 for item in "${EXTERNAL_BINARIES_PACKAGE_ADDONS[@]}";do
125 if [ "$(basename $item)" == "resources" ]; then
126 echo "Note: Packaging all resources at once"
127 add_additions "${item}" "${PACKAGING_TARGET_DIR}"
129 add_additions "${item}" "${pkg_root}"
133 # tar file with nexus_data is expected, we should find and untar it
134 # before resource.tar is created
135 for i in `ls -1 ${pkg_root} | grep tar`; do
136 tar tvf "${pkg_root}/${i}" | grep nexus_data &> /dev/null
137 if [ $? -eq 0 ]; then
138 echo "Debug: tar file with nexus blobs detected ${pkg_root}/${i}. Start unarchive ..."
139 tar xf "${pkg_root}/${i}" -C "${pkg_root}" &> /dev/null
140 echo "Debug: unarchive finished. Removing original file"
141 rm -f "${pkg_root}/${i}"
145 echo "Creating tar file ..."
146 PACKAGE_BASE_NAME="${SOFTWARE_PACKAGE_BASENAME}"
147 create_tar "${pkg_root}" "${PACKAGE_BASE_NAME}-${PROJECT_NAME}-${PROJECT_VERSION}-resources.tar"
151 function create_aux_package {
152 local pkg_root="${PACKAGING_TARGET_DIR}/aux"
154 # Create aux resource tar package
155 echo "Creating aux resource package"
157 # Create directory structure of the aux resource package
158 mkdir -p "${pkg_root}"
160 # Add artifacts into resource packagee based on package.conf config
161 for item in "${AUX_BINARIES_PACKAGE_ADDONS[@]}";do
162 add_additions "${item}" "${pkg_root}"
165 echo "Creating tar file ..."
166 PACKAGE_BASE_NAME="${SOFTWARE_PACKAGE_BASENAME}"
167 create_tar "${pkg_root}" "${PACKAGE_BASE_NAME}-${PROJECT_NAME}-${PROJECT_VERSION}-aux-resources.tar"
172 # =================== Main ===================
177 PACKAGING_TARGET_DIR="$3"
179 TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
181 # ensure that package.conf is sourced even when package.sh executed from another place
182 SCRIPT_DIR=$(dirname "${0}")
183 LOCAL_PATH=$(readlink -f "$SCRIPT_DIR")
185 # lets start from script directory as some path in script are relative
186 pushd "${LOCAL_PATH}"
187 source ./package.conf
190 if [ "$#" -lt 3 ]; then
191 echo "Missing some mandatory parameter!"
196 if [ ! -f "./package.conf" ]; then
197 crash 2 "Mandatory config file ./package.conf missing!"
200 # checking bash capability of parsing arrays
201 whotest[0]='test' || (crash 3 "Arrays not supported in this version of bash.")
204 # Prepare output directory for our packaging and create all tars
206 rm -rf ${PACKAGING_TARGET_DIR}
208 create_resource_package
210 # This part will create aux package which consists of
211 # artifacts which can be added into offline nexus during runtime
212 if [ "${PREPARE_AUX_PACKAGE}" == "true" ]; then
215 echo "AUX package won't be created"