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 - 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 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"
86 make $MAKE_ARGS -C ${BUILD_BASE} $1
91 # Install build dependencies
92 for pkg in $REQUIRED_PKGS; do
93 if ! rpm -q $pkg > /dev/null; then
94 if ! sudo yum -y install $pkg > /dev/null; then
95 echo "Required package $pkg missing and installation failed."
101 if [ -n "$RELEASE" ]; then MAKE_ARGS+="RELEASE=$RELEASE "; fi
104 if [[ -n "$CACHE_DEST" && -n "$MAKE_TARGETS" ]]; then
105 echo "Retrieving Cache"
106 if [ -f $CACHE_DEST/${CACHE_NAME}.tgz ]; then
107 echo "Cache found at ${CACHE_DEST}/${CACHE_NAME}.tgz"
108 rm -rf $BUILD_BASE/$CACHE_DIR
109 echo "Unpacking Cache to $BUILD_BASE"
110 tar -xvzf $CACHE_DEST/${CACHE_NAME}.tgz -C ${BUILD_BASE}
111 if [ -f $BUILD_BASE/.cache ]; then
112 echo "Rebuilding .cache file"
113 if [ ! -d $BUILD_BASE/$CACHE_DIR ]; then
114 mkdir $BUILD_BASE/$CACHE_DIR
116 for i in $(ls $BUILD_BASE/$CACHE_DIR); do
117 grep $i $BUILD_BASE/.cache >> $BUILD_BASE/$CACHE_DIR/.cache
120 echo "Cache contents after unpack:"
121 ls -l $BUILD_BASE/$CACHE_DIR
123 echo "No Cache Found"
127 # Ensure the build cache dir exists
128 if [ ! -d "$BUILD_BASE/$CACHE_DIR" ]; then
129 echo "Creating Build Cache Directory"
130 mkdir $BUILD_BASE/$CACHE_DIR
133 # Conditionally execute RPM build checks if the specs change and target is not rpm or iso
134 if [[ "$MAKE_TARGETS" == "images" ]]; then
135 commit_file_list=$(git show --pretty="format:" --name-status)
136 if git show -s | grep "force-build-rpms"; then
137 MAKE_TARGETS+=" rpms"
138 elif [[ $commit_file_list == *"A$(printf '\t')"* || $commit_file_list == *build/Makefile* ]]; then
139 # Makefile forces all rpms to be checked
140 MAKE_TARGETS+=" rpms-check"
142 # Spec files are selective
143 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-undercloud.spec* ]]; then
144 MAKE_TARGETS+=" undercloud-rpm-check"
146 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-common.spec* ]]; then
147 MAKE_TARGETS+=" common-rpm-check"
149 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex.spec* ]]; then
150 MAKE_TARGETS+=" opendaylight-rpm-check"
152 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-onos.spec* ]]; then
153 MAKE_TARGETS+=" onos-rpm-check"
158 # Make sure python is installed
159 if ! rpm -q python34-devel > /dev/null; then
160 sudo yum install -y epel-release
161 if ! sudo yum install -y python34-devel; then
162 echo "Failed to install python34-devel package..."
167 # Execute make against targets
168 for t in $MAKE_TARGETS; do
172 echo "Build Complete"
175 if [ -n "$CACHE_DEST" ]; then
176 echo "Building Cache"
177 ls -lh $BUILD_BASE/$CACHE_DIR/
178 # ensure the destination exists
179 if [ ! -d $CACHE_DEST ]; then mkdir -p $CACHE_DEST; fi
180 # ensure a sub cache dir exists to mirror the build base for extraction
181 if [ ! -d $BUILD_BASE/$CACHE_DIR/$CACHE_DIR/ ]; then mkdir -p $BUILD_BASE/$CACHE_DIR/$CACHE_DIR/; fi
182 # move directly cached files to cache dir for future extraction
183 for i in $(cat $BUILD_BASE/$CACHE_DIR/.cache | awk '{ print $2 }'); do
184 if [ -f $i ]; then mv $i $BUILD_BASE/$CACHE_DIR/$CACHE_DIR/; fi
186 # roll the cache tarball
187 tar --atime-preserve --dereference -C ${BUILD_BASE}/$CACHE_DIR -caf $CACHE_DEST/${CACHE_NAME}.tgz .
188 if [ -f "${CACHE_DEST}/${CACHE_NAME}.tgz" ]; then
189 echo "Cache Build Complete"
191 echo "WARN: Cache file did not build correctly"