2 ##############################################################################
3 # Copyright (c) 2016 Dan Radez (Red Hat) and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
16 $0 Builds the Apex OPNFV Deployment Toolchain
18 usage: $0 [ -c cache_dest_dir ] -r release_name [ --iso | --rpms ]
21 -c cache destination - destination to save tarball of cache
22 -r release name/version of the build result
23 --iso build the iso (implies RPMs too)
26 -h help, prints this help text
29 build -c file:///tmp/cache -r dev123
33 APEX_ROOT=$(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd))
35 CACHE_DIR="${APEX_ROOT}/.cache"
36 CACHE_NAME="apex-cache"
38 REQUIRED_PKGS="rpm-build python-docutils"
42 while [ "${1:0:1}" = "-" ]
59 echo "Building opnfv-apex RPMs and ISO"
64 echo "Buiding opnfv-apex RPMs"
68 RELEASE_RPM=" release-rpm"
69 echo "Buiding opnfv-apex RPMs"
74 echo "Enable debug output"
92 make $MAKE_ARGS -C ${BUILD_DIRECTORY} $1
97 if [ -z "$BUILD_DIRECTORY" ]; then
98 if [ -d "${APEX_ROOT}/build" ]; then
99 BUILD_DIRECTORY="${APEX_ROOT}/build"
101 echo "Cannot find build directory, please provide BUILD_DIRECTORY environment variable...exiting"
104 elif [ ! -d "$BUILD_DIRECTORY" ]; then
105 echo "Provided build directory is invalid: ${BUILD_DIRECTORY} ...exiting"
109 # Add release rpm to make targets if defined
110 MAKE_TARGETS+=$RELEASE_RPM
112 # Install build dependencies
113 for pkg in $REQUIRED_PKGS; do
114 if ! rpm -q $pkg > /dev/null; then
115 if ! sudo yum -y install $pkg > /dev/null; then
116 echo "Required package $pkg missing and installation failed."
122 if [ -n "$RELEASE" ]; then MAKE_ARGS+="RELEASE=$RELEASE "; fi
124 # Get the Old Cache and build new cache history file
125 if [[ -n "$CACHE_DEST" && -n "$MAKE_TARGETS" ]]; then
126 echo "Retrieving Cache"
127 if [ -f $CACHE_DEST/${CACHE_NAME}.tgz ]; then
128 echo "Cache found at ${CACHE_DEST}/${CACHE_NAME}.tgz"
131 echo "Unpacking Cache to ${CACHE_DIR}"
132 tar -xvzf ${CACHE_DEST}/${CACHE_NAME}.tgz -C ${CACHE_DIR}
133 echo "Cache contents after unpack:"
136 echo "No Cache Found"
140 # Ensure the build cache dir exists
141 if [ ! -d "$CACHE_DIR" ]; then
143 echo "Creating Build Cache Directory"
147 # Conditionally execute RPM build checks if the specs change and target is not rpm or iso
148 if [[ "$MAKE_TARGETS" == "images" ]]; then
149 commit_file_list=$(git show --pretty="format:" --name-status)
150 if git show -s | grep "force-build-rpms"; then
151 MAKE_TARGETS+=" rpms"
152 elif [[ $commit_file_list == *"A$(printf '\t')"* || $commit_file_list == *build/Makefile* ]]; then
153 # Makefile forces all rpms to be checked
154 MAKE_TARGETS+=" rpms-check"
156 # Spec files are selective
157 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-undercloud.spec* ]]; then
158 MAKE_TARGETS+=" undercloud-rpm-check"
160 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-release.spec* ]]; then
161 MAKE_TARGETS+=" release-rpm-check"
163 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-common.spec* ]]; then
164 MAKE_TARGETS+=" common-rpm-check"
166 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex.spec* ]]; then
167 MAKE_TARGETS+=" opendaylight-rpm-check"
169 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-onos.spec* ]]; then
170 MAKE_TARGETS+=" onos-rpm-check"
175 # Make sure python is installed
176 if ! rpm -q python34-devel > /dev/null; then
177 sudo yum install -y epel-release
178 if ! sudo yum install -y python34-devel; then
179 echo "Failed to install python34-devel package..."
184 # Execute make against targets
185 for t in $MAKE_TARGETS; do
189 echo "Build Complete"
192 if [ -n "$CACHE_DEST" ]; then
193 echo "Building Cache"
195 # ensure the destination exists
196 mkdir -p ${CACHE_DEST}
197 # roll the cache tarball
198 tar --atime-preserve --dereference -caf ${CACHE_DEST}/${CACHE_NAME}.tgz -C ${CACHE_DIR} .
199 if [ -f "${CACHE_DEST}/${CACHE_NAME}.tgz" ]; then
200 echo "Cache Build Complete"
202 echo "WARN: Cache file did not build correctly"