blob: 4b216c1bc6a658248e0414c7bb899c67a5809ee0 [file] [log] [blame]
#!/usr/bin/env bash
# ============LICENSE_START=======================================================
# Copyright (C) 2018-2019 Nordix Foundation.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
set -o nounset
set -o errexit
set -o pipefail
#set -o xtrace
# Set build tools versions base on the:
# https://github.com/apache/geode-native/blob/develop/docker/Dockerfile
CLANG_VERSION="6.0.1"
GEODE_VERSION="1.10.0"
RAT_VERSION="0.13"
CMAKE_VERSION="3.12.2"
# Additional repositories and build 3PPs
CLANG_SLES_REPO="https://download.opensuse.org/repositories/devel:/languages:/swift/SLE_15/"
GAMES_SLES_REPO="https://download.opensuse.org/repositories/games/SLE_15_SP1/"
GEODE_LOCATION="https://www.apache.org/dyn/closer.cgi?action=download&filename=geode/${GEODE_VERSION}/apache-geode-${GEODE_VERSION}.tgz"
RAT_LOCATION="https://www.apache.org/dyn/closer.cgi?action=download&filename=creadur/apache-rat-${RAT_VERSION}/apache-rat-${RAT_VERSION}-bin.tar.gz"
CMAKE_LOCATION="https://cmake.org/files/v${CMAKE_VERSION%.*}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh"
install_dev_packages() {
# Add Swift repository with clang6 compiler.
if ! zypper lr -n | egrep Swift-Programming-Language > /dev/null ; then
sudo zypper addrepo ${CLANG_SLES_REPO} "Swift-Programming-Language(SLES_15)"
fi
# Add Games repository with libjsoncpp library.
if ! zypper lr -n | egrep Games > /dev/null ; then
sudo zypper addrepo ${GAMES_SLES_REPO} "Games(SLE_15_SP1)"
fi
echo "Info: Upgrade SLES and install all available patches"
echo "-------------------------------------------------------------"
sudo zypper --gpg-auto-import-keys refresh ; sudo zypper update -y
sudo zypper -q patches
echo "Info: Install clang development environment"
echo "-------------------------------------------------------------"
sudo zypper install -y \
libc++-devel \
libc++abi-devel \
libopenssl-devel \
zlib-devel \
clang${CLANG_VERSION:0:1} \
clang${CLANG_VERSION:0:1}-checker \
clang${CLANG_VERSION:0:1}-devel \
gcc \
make \
patch \
doxygen \
git \
graphviz \
java-1_8_0-openjdk-devel \
wget
if [[ ! -L /etc/alternatives/clang ]] ; then
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 999
fi
if [[ ! -L /etc/alternatives/clang++ ]] ; then
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION} 999
fi
if [[ ! -L /etc/alternatives/clang-tidy ]] ; then
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${CLANG_VERSION} 999
fi
if [[ ! -L /etc/alternatives/cc ]] ; then
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999
fi
if [[ ! -L /etc/alternatives/cc++ ]] ; then
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${CLANG_VERSION} 999
fi
}
configure_geode_build() {
echo "Info: Install 3PPs required to build geode-native"
echo "-------------------------------------------------------------"
# The Geode is required on build server to compile geode-native
if [[ ! -d /opt/apache-geode-${GEODE_VERSION} ]] ; then
wget ${GEODE_LOCATION} -O - | sudo tar xzvf - -C /opt
else
echo "The Geode ${GEODE_VERSION} already installed."
fi
echo "-------------------------------------------------------------"
# The Rat (Apache Release Audit Tool) is required to compile geode-native
if [[ ! -d /opt/apache-rat-${RAT_VERSION} ]] ; then
wget ${RAT_LOCATION} -O - | sudo tar xzvf - -C /opt
else
echo "The Apache RAT ${RAT_VERSION} already installed."
fi
echo "-------------------------------------------------------------"
# cmake is required to generate a build system for geode-native
if [[ ! -f /usr/local/bin/cmake ]] ; then
wget ${CMAKE_LOCATION} -O /tmp/cmake
sudo bash /tmp/cmake --skip-license --prefix=/usr/local
rm -rf /tmp/cmake
elif ! /usr/local/bin/cmake -version | grep -q ${CMAKE_VERSION} ; then
echo "ERROR: Incorrect cmake version installed"
exit 3
else
echo "The CMAKE ${CMAKE_VERSION} already installed."
fi
# Export 3PPs location for geode-native build
export JAVA_HOME="/usr/lib64/jvm/java-openjdk"
export GEODE_HOME="/opt/apache-geode-${GEODE_VERSION}"
export RAT_HOME="/opt/apache-rat-${RAT_VERSION}"
export PATH="$PATH:$GEODE_HOME/bin"
# Update hosts file with ip6-localhost required by geode-native Integration tests
sudo sed -i '/ipv6-loopback$/s/$/ ip6-localhost/' /etc/hosts
}
get_geode_build_docker_image() {
echo "Info: Start and enable docker on system"
echo "-------------------------------------------------------------"
sudo systemctl enable docker
sudo systemctl start docker
echo "Info: Remove all previous stopped docker containers and images"
echo "-------------------------------------------------------------"
sudo docker container prune -f
sudo docker image prune -f
echo "Info: Get the latest geode-native build docker image"
echo "-------------------------------------------------------------"
docker pull ${GEODE_NATIVE_DOCKER_IMAGE:-apachegeode/geode-native-build}
}
# Make sure the build server is SLES15 based
source /etc/os-release
case ${ID,,} in
sles)
if [[ "${VERSION}" != "15" ]] ; then
echo "ERROR: Incorrect version on SLES on the build server: ${VERSION}"
exit 1
else
install_dev_packages
configure_geode_build
get_geode_build_docker_image
fi
;;
ubuntu)
DPKG_LOCK="/var/lib/dpkg/lock-frontend"
# Wait for other apt process to finish by checking the dpkg lock file.
try=0
while sudo lsof ${DPKG_LOCK} > /dev/null 2>&1 ; do
echo "DPKG file locked: ${DPKG_LOCK}."
echo " Waiting for another pkg installation process to finish ..."
sleep 10
if [[ ${try} -gt 60 ]] ; then
echo "ERROR: Max number of re-tries reached, exiting..."
exit 1
fi
try=$((try + 1))
done
get_geode_build_docker_image
;;
*)
echo "ERROR: Only SLES15 and Ubuntu OS can be use as a build server geode-native"
exit 2
;;
esac