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_dir ] -r release_name [ --iso | --rpms ]
21 -c cache destination - directory of cached files, defaults to ./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 BUILD_BASE=$(readlink -e ../build/)
36 CACHE_NAME="apex-cache"
38 REQUIRED_PKGS="rpm-build python-docutils"
41 while [ "${1:0:1}" = "-" ]
58 echo "Building opnfv-apex RPMs and ISO"
63 echo "Buiding opnfv-apex RPMs"
68 echo "Enable debug output"
81 make $MAKE_ARGS -C ${BUILD_BASE} $1
86 # Install build dependencies
87 for pkg in $REQUIRED_PKGS; do
88 if ! rpm -q $pkg > /dev/null; then
89 if ! sudo yum -y install $pkg > /dev/null; then
90 echo "Required package $pkg missing and installation failed."
96 if [ -n "$RELEASE" ]; then MAKE_ARGS+="RELEASE=$RELEASE "; fi
99 if [ -n "$CACHE_DEST" ]; then
100 echo "Retrieving Cache"
101 if [ -f $CACHE_DEST/${CACHE_NAME}.tgz ]; then
102 echo "Cache found at ${CACHE_DEST}/${CACHE_NAME}.tgz"
103 rm -rf $BUILD_BASE/$CACHE_DIR
104 echo "Unpacking Cache to $BUILD_BASE"
105 tar -xvzf $CACHE_DEST/${CACHE_NAME}.tgz -C ${BUILD_BASE}
106 echo "Cache contents after unpack:"
107 ls -l $BUILD_BASE/$CACHE_DIR
108 elif [ ! -d $BUILD_BASE/$CACHE_DIR ]; then
109 mkdir $BUILD_BASE/$CACHE_DIR
113 # Conditionally execute RPM build checks if the specs change and target is not rpm or iso
114 if [[ "$MAKE_TARGETS" == "images" ]]; then
115 commit_file_list=$(git show --pretty="format:" --name-only)
116 if git show -s | grep "force-build-rpms"; then
117 MAKE_TARGETS+=" rpms"
118 elif [[ $commit_file_list == *build/Makefile* ]]; then
119 # Makefile forces all rpms to be checked
120 MAKE_TARGETS+=" rpms-check"
122 # Spec files are selective
123 if [[ $commit_file_list == *build/opnfv-apex-undercloud.spec* ]]; then
124 MAKE_TARGETS+=" undercloud-rpm-check"
126 if [[ $commit_file_list == *build/opnfv-apex-common.spec* ]]; then
127 MAKE_TARGETS+=" common-rpm-check"
129 if [[ $commit_file_list == *build/opnfv-apex.spec* ]]; then
130 MAKE_TARGETS+=" opendaylight-rpm-check"
132 if [[ $commit_file_list == *build/opnfv-apex-onos.spec* ]]; then
133 MAKE_TARGETS+=" onos-rpm-check"
135 if [[ $commit_file_list == *build/opnfv-apex-opendaylight-sfc.spec* ]]; then
136 MAKE_TARGETS+=" opendaylight-sfc-rpm-check"
141 # Make sure python is installed
142 if ! rpm -q python34-devel > /dev/null; then
143 sudo yum install -y epel-release
144 if ! sudo yum install -y python34-devel; then
145 echo "Failed to install python34-devel package..."
150 # Execute make against targets
151 for t in $MAKE_TARGETS; do
155 echo "Build Complete"
158 if [ -n "$CACHE_DEST" ]; then
159 echo "Building Cache"
160 if [ ! -d $CACHE_DEST ]; then mkdir -p $CACHE_DEST; fi
161 tar --atime-preserve --dereference -C $BUILD_BASE -caf $BUILD_BASE/${CACHE_NAME}.tgz $CACHE_DIR -C ${CACHE_DEST}/
162 if [ -f "${CACHE_DEST}/${CACHE_NAME}.tgz" ]; then
163 echo "Cache Build Complete"
165 echo "WARN: Cache file did not build correctly"