b08fa3faa4426e1b3b8cacd2036403f22d48c67f
[infra/cicd.git] / jjb / geode-native / apache-geode-native-slave / slave_setup.sh
1 #!/usr/bin/env bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2018-2019 Nordix Foundation.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19 set -o nounset
20 set -o errexit
21 set -o pipefail
22 #set -o xtrace
23
24 # Set build tools versions base on the:
25 # https://github.com/apache/geode-native/blob/develop/docker/Dockerfile
26 CLANG_VERSION="6.0"
27 GEODE_VERSION="1.10.0"
28 RAT_VERSION="0.13"
29 CMAKE_VERSION="3.12.2"
30
31 # Additional repositories and build 3PPs
32 CLANG_SLES_REPO="https://download.opensuse.org/repositories/devel:/languages:/swift/SLE_15/"
33 GAMES_SLES_REPO="https://download.opensuse.org/repositories/games/SLE_15_SP1/"
34 GEODE_LOCATION="https://www.apache.org/dyn/closer.cgi?action=download&filename=geode/${GEODE_VERSION}/apache-geode-${GEODE_VERSION}.tgz"
35 RAT_LOCATION="https://www.apache.org/dyn/closer.cgi?action=download&filename=creadur/apache-rat-${RAT_VERSION}/apache-rat-${RAT_VERSION}-bin.tar.gz"
36 CMAKE_LOCATION="https://cmake.org/files/v${CMAKE_VERSION%.*}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh"
37
38 install_dev_packages() {
39   # Add Swift repository with clang6 compiler.
40   if ! zypper lr -n | egrep Swift-Programming-Language > /dev/null ; then
41     sudo zypper addrepo ${CLANG_SLES_REPO} "Swift-Programming-Language(SLES_15)"
42   fi
43   # Add Games repository with libjsoncpp library.
44   if ! zypper lr -n | egrep Games > /dev/null ; then
45     sudo zypper addrepo ${GAMES_SLES_REPO} "Games(SLE_15_SP1)"
46   fi
47
48   echo "Info: Upgrade SLES and install all available patches"
49   echo "-------------------------------------------------------------"
50   sudo zypper --gpg-auto-import-keys refresh ; sudo zypper -q update -y
51   sudo zypper -q patches
52
53   echo "Info: Install clang development environment"
54   echo "-------------------------------------------------------------"
55   sudo zypper -q install -y \
56     libc++-devel \
57     libc++abi-devel \
58     libopenssl-devel \
59     zlib-devel \
60     clang${CLANG_VERSION%.*} \
61     clang${CLANG_VERSION%.*}-checker \
62     clang${CLANG_VERSION%.*}-devel \
63     gcc \
64     make \
65     patch \
66     doxygen \
67     git \
68     graphviz \
69     java-1_8_0-openjdk-devel \
70     wget
71
72   sudo update-alternatives --install /usr/bin/clang    clang    /usr/bin/clang-${CLANG_VERSION} 999
73   sudo update-alternatives --install /usr/bin/clang++  clang++  /usr/bin/clang++-${CLANG_VERSION} 999
74   sudo update-alternatives --install /usr/bin/cc       cc       /usr/bin/clang-${CLANG_VERSION} 999
75   sudo update-alternatives --install /usr/bin/c++      c++      /usr/bin/clang++-${CLANG_VERSION} 999
76 }
77
78 configure_geode_build() {
79   echo "Info: Install 3PPs required to build geode-native"
80   echo "-------------------------------------------------------------"
81   # The Geode is required on build server to compile geode-native
82   if [[ ! -d /opt/apache-geode-${GEODE_VERSION} ]] ; then
83     wget ${GEODE_LOCATION} -O - | sudo tar xzvf - -C /opt
84   else
85     echo "The Geode ${GEODE_VERSION} already installed."
86   fi
87   echo "-------------------------------------------------------------"
88
89   # The Rat (Apache Release Audit Tool) is required to compile geode-native
90   if [[ ! -d /opt/apache-rat-${RAT_VERSION} ]] ; then
91     wget ${RAT_LOCATION} -O - | sudo tar xzvf - -C /opt
92   else
93     echo "The Apache RAT ${RAT_VERSION} already installed."
94   fi
95   echo "-------------------------------------------------------------"
96
97   # cmake is required to generate a build system for geode-native
98   if [[ ! -f /usr/local/bin/cmake ]] ; then
99     wget ${CMAKE_LOCATION} -O /tmp/cmake
100     sudo bash /tmp/cmake --skip-license --prefix=/usr/local
101     rm -rf /tmp/cmake
102   elif ! /usr/local/bin/cmake -version | grep -q ${CMAKE_VERSION} ; then
103     echo "ERROR: Incorrect cmake version installed"
104     exit 3
105   else
106     echo "The CMAKE ${CMAKE_VERSION} already installed."
107   fi
108
109   # Export 3PPs location for geode-native build
110   export JAVA_HOME="/usr/lib64/jvm/java-openjdk"
111   export GEODE_HOME="/opt/apache-geode-${GEODE_VERSION}"
112   export RAT_HOME="/opt/apache-rat-${RAT_VERSION}"
113   export PATH="$PATH:$GEODE_HOME/bin"
114
115   # Get the latest geode-native build docker image
116   docker pull ${GEODE_NATIVE_DOCKER_IMAGE}
117 }
118
119 # Make sure the build server is SLES15 based
120 source /etc/os-release
121 case ${ID,,} in
122   sles)
123     if [[ "${VERSION}" != "15" ]] ; then
124       echo "ERROR: Incorrect version on SLES on the build server: ${VERSION}"
125       exit 1
126     else
127       install_dev_packages
128       configure_geode_build
129     fi
130   ;;
131   *)
132     echo "ERROR: Only SLES15 can be use as a build server for this build"
133     exit 2
134   ;;
135 esac