fuel-plugin-opendaylight/pre_build_hook

71 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
set -eux
USE_CACHE=${USE_CACHE:-true}
ODL_INTEGRATION_PACKAGING=${ODL_INTEGRATION_PACKAGING:-https://github.com/opendaylight/integration-packaging}
# ODL versions to build, separated by space
# Taken from https://github.com/opendaylight/integration-packaging/blob/master/deb/build_vars.yaml
# If more than one version of ODL are included make sure that local
# fpb contain this commit https://review.openstack.org/#/c/311031/
ODL_VERSIONS=${ODL_VERSIONS:-5.0.0.1 5.2.0.1}
#Networking odl
NETWORKING_ODL_REPO=${NETWORKING_ODL_REPO:-http://ubuntu-cloud.archive.canonical.com/ubuntu/pool/main/n/networking-odl/}
NETWORKING_ODL_DEB=${NETWORKING_ODL_DEB:-python-networking-odl_2.0.1~git20160926.416a5c7-0ubuntu1~cloud0_all.deb}
DIR="$(dirname `readlink -f $0`)"
CACHE_DIR="${DIR}/.cache"
CACHE_DEB_DIR="${CACHE_DIR}/integration-packaging/deb/cache"
# OPNFV builds plugin inside container, in that case
# we need to use sudo to have access to docker
OPNFV_BUILD=${OPNFV_BUILD:-false}
if [ "$OPNFV_BUILD" == true ] ;then
SUDO="sudo"
else
SUDO=" "
fi
function prep_build_env {
docker_build_opts="-t odl_deb"
if [ "$USE_CACHE" != true ] || [ ! -d "${CACHE_DIR}/integration-packaging" ] ;then
rm -rf ${CACHE_DIR}/integration-packaging
git clone ${ODL_INTEGRATION_PACKAGING} ${CACHE_DIR}/integration-packaging
docker_build_opts+=" --no-cache"
fi
$SUDO docker build ${docker_build_opts} ${CACHE_DIR}/integration-packaging/deb
}
function build_odl_deb {
$SUDO docker run -u $(id -u) --rm -v ${CACHE_DIR}/integration-packaging/deb:/build odl_deb -v ${1//./ }
rm -rf ${CACHE_DIR}/integration-packaging/deb/opendaylight
}
function in_cache {
[ -f "${CACHE_DEB_DIR}/${1}" ]
}
function copy_from_cache {
cp ${CACHE_DEB_DIR}/${1} ${DIR}/repositories/ubuntu/${1}
}
command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is required but it's not installed. Aborting."; exit 1; }
mkdir -p "${CACHE_DIR}"
prep_build_env
rm -f ${DIR}/repositories/ubuntu/*.deb
for v in $ODL_VERSIONS
do
deb_name="opendaylight_${v%.*}-${v##*.}_all.deb"
if ! in_cache $deb_name ;then
build_odl_deb $v
fi
copy_from_cache $deb_name
done
if ! in_cache $NETWORKING_ODL_DEB ;then
wget -O ${CACHE_DEB_DIR}/${NETWORKING_ODL_DEB} ${NETWORKING_ODL_REPO}/${NETWORKING_ODL_DEB}
fi
copy_from_cache $NETWORKING_ODL_DEB