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"
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_BASE} $1
97 # Add release rpm to make targets if defined
98 MAKE_TARGETS+=$RELEASE_RPM
100 # Install build dependencies
101 for pkg in $REQUIRED_PKGS; do
102 if ! rpm -q $pkg > /dev/null; then
103 if ! sudo yum -y install $pkg > /dev/null; then
104 echo "Required package $pkg missing and installation failed."
110 if [ -n "$RELEASE" ]; then MAKE_ARGS+="RELEASE=$RELEASE "; fi
113 if [[ -n "$CACHE_DEST" && -n "$MAKE_TARGETS" ]]; then
114 echo "Retrieving Cache"
115 if [ -f $CACHE_DEST/${CACHE_NAME}.tgz ]; then
116 echo "Cache found at ${CACHE_DEST}/${CACHE_NAME}.tgz"
117 rm -rf $BUILD_BASE/$CACHE_DIR
118 echo "Unpacking Cache to $BUILD_BASE"
119 tar -xvzf $CACHE_DEST/${CACHE_NAME}.tgz -C ${BUILD_BASE}
120 if [ -f $BUILD_BASE/.cache ]; then
121 echo "Rebuilding .cache file"
122 if [ ! -d $BUILD_BASE/$CACHE_DIR ]; then
123 mkdir $BUILD_BASE/$CACHE_DIR
125 for i in $(ls $BUILD_BASE/$CACHE_DIR); do
126 grep $i $BUILD_BASE/.cache >> $BUILD_BASE/$CACHE_DIR/.cache
129 echo "Cache contents after unpack:"
130 ls -l $BUILD_BASE/$CACHE_DIR
132 echo "No Cache Found"
136 # Ensure the build cache dir exists
137 if [ ! -d "$BUILD_BASE/$CACHE_DIR" ]; then
138 echo "Creating Build Cache Directory"
139 mkdir $BUILD_BASE/$CACHE_DIR
142 # Conditionally execute RPM build checks if the specs change and target is not rpm or iso
143 if [[ "$MAKE_TARGETS" == "images" ]]; then
144 commit_file_list=$(git show --pretty="format:" --name-status)
145 if git show -s | grep "force-build-rpms"; then
146 MAKE_TARGETS+=" rpms"
147 elif [[ $commit_file_list == *"A$(printf '\t')"* || $commit_file_list == *build/Makefile* ]]; then
148 # Makefile forces all rpms to be checked
149 MAKE_TARGETS+=" rpms-check"
151 # Spec files are selective
152 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-undercloud.spec* ]]; then
153 MAKE_TARGETS+=" undercloud-rpm-check"
155 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-release.spec* ]]; then
156 MAKE_TARGETS+=" release-rpm-check"
158 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-common.spec* ]]; then
159 MAKE_TARGETS+=" common-rpm-check"
161 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex.spec* ]]; then
162 MAKE_TARGETS+=" opendaylight-rpm-check"
164 if [[ $commit_file_list == *build/rpm_specs/opnfv-apex-onos.spec* ]]; then
165 MAKE_TARGETS+=" onos-rpm-check"
170 # Make sure python is installed
171 if ! rpm -q python34-devel > /dev/null; then
172 sudo yum install -y epel-release
173 if ! sudo yum install -y python34-devel; then
174 echo "Failed to install python34-devel package..."
179 # Execute make against targets
180 for t in $MAKE_TARGETS; do
184 echo "Build Complete"
187 if [ -n "$CACHE_DEST" ]; then
188 echo "Building Cache"
189 ls -lh $BUILD_BASE/$CACHE_DIR/
190 # ensure the destination exists
191 if [ ! -d $CACHE_DEST ]; then mkdir -p $CACHE_DEST; fi
192 # ensure a sub cache dir exists to mirror the build base for extraction
193 if [ ! -d $BUILD_BASE/$CACHE_DIR/$CACHE_DIR/ ]; then mkdir -p $BUILD_BASE/$CACHE_DIR/$CACHE_DIR/; fi
194 # move directly cached files to cache dir for future extraction
195 for i in $(cat $BUILD_BASE/$CACHE_DIR/.cache | awk '{ print $2 }'); do
196 if [ -f $i ]; then mv $i $BUILD_BASE/$CACHE_DIR/$CACHE_DIR/; fi
198 # roll the cache tarball
199 tar --atime-preserve --dereference -C ${BUILD_BASE}/$CACHE_DIR -caf $CACHE_DEST/${CACHE_NAME}.tgz .
200 if [ -f "${CACHE_DEST}/${CACHE_NAME}.tgz" ]; then
201 echo "Cache Build Complete"
203 echo "WARN: Cache file did not build correctly"