robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 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 |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 26 | CLANG_VERSION="6.0.1" |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 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 "-------------------------------------------------------------" |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 50 | sudo zypper --gpg-auto-import-keys refresh ; sudo zypper update -y |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 51 | sudo zypper -q patches |
| 52 | |
| 53 | echo "Info: Install clang development environment" |
| 54 | echo "-------------------------------------------------------------" |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 55 | sudo zypper install -y \ |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 56 | libc++-devel \ |
| 57 | libc++abi-devel \ |
| 58 | libopenssl-devel \ |
| 59 | zlib-devel \ |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 60 | clang${CLANG_VERSION:0:1} \ |
| 61 | clang${CLANG_VERSION:0:1}-checker \ |
| 62 | clang${CLANG_VERSION:0:1}-devel \ |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 63 | gcc \ |
| 64 | make \ |
| 65 | patch \ |
| 66 | doxygen \ |
| 67 | git \ |
| 68 | graphviz \ |
| 69 | java-1_8_0-openjdk-devel \ |
| 70 | wget |
| 71 | |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 72 | if [[ ! -L /etc/alternatives/clang ]] ; then |
| 73 | sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 999 |
| 74 | fi |
| 75 | if [[ ! -L /etc/alternatives/clang++ ]] ; then |
| 76 | sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION} 999 |
| 77 | fi |
| 78 | if [[ ! -L /etc/alternatives/clang-tidy ]] ; then |
| 79 | sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${CLANG_VERSION} 999 |
| 80 | fi |
| 81 | if [[ ! -L /etc/alternatives/cc ]] ; then |
| 82 | sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${CLANG_VERSION} 999 |
| 83 | fi |
| 84 | if [[ ! -L /etc/alternatives/cc++ ]] ; then |
| 85 | sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${CLANG_VERSION} 999 |
| 86 | fi |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | configure_geode_build() { |
| 90 | echo "Info: Install 3PPs required to build geode-native" |
| 91 | echo "-------------------------------------------------------------" |
| 92 | # The Geode is required on build server to compile geode-native |
| 93 | if [[ ! -d /opt/apache-geode-${GEODE_VERSION} ]] ; then |
| 94 | wget ${GEODE_LOCATION} -O - | sudo tar xzvf - -C /opt |
| 95 | else |
| 96 | echo "The Geode ${GEODE_VERSION} already installed." |
| 97 | fi |
| 98 | echo "-------------------------------------------------------------" |
| 99 | |
| 100 | # The Rat (Apache Release Audit Tool) is required to compile geode-native |
| 101 | if [[ ! -d /opt/apache-rat-${RAT_VERSION} ]] ; then |
| 102 | wget ${RAT_LOCATION} -O - | sudo tar xzvf - -C /opt |
| 103 | else |
| 104 | echo "The Apache RAT ${RAT_VERSION} already installed." |
| 105 | fi |
| 106 | echo "-------------------------------------------------------------" |
| 107 | |
| 108 | # cmake is required to generate a build system for geode-native |
| 109 | if [[ ! -f /usr/local/bin/cmake ]] ; then |
| 110 | wget ${CMAKE_LOCATION} -O /tmp/cmake |
| 111 | sudo bash /tmp/cmake --skip-license --prefix=/usr/local |
| 112 | rm -rf /tmp/cmake |
| 113 | elif ! /usr/local/bin/cmake -version | grep -q ${CMAKE_VERSION} ; then |
| 114 | echo "ERROR: Incorrect cmake version installed" |
| 115 | exit 3 |
| 116 | else |
| 117 | echo "The CMAKE ${CMAKE_VERSION} already installed." |
| 118 | fi |
| 119 | |
| 120 | # Export 3PPs location for geode-native build |
| 121 | export JAVA_HOME="/usr/lib64/jvm/java-openjdk" |
| 122 | export GEODE_HOME="/opt/apache-geode-${GEODE_VERSION}" |
| 123 | export RAT_HOME="/opt/apache-rat-${RAT_VERSION}" |
| 124 | export PATH="$PATH:$GEODE_HOME/bin" |
| 125 | |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 126 | # Update hosts file with ip6-localhost required by geode-native Integration tests |
| 127 | sudo sed -i '/ipv6-loopback$/s/$/ ip6-localhost/' /etc/hosts |
| 128 | } |
| 129 | |
| 130 | get_geode_build_docker_image() { |
| 131 | echo "Info: Start and enable docker on system" |
| 132 | echo "-------------------------------------------------------------" |
| 133 | sudo systemctl enable docker |
| 134 | sudo systemctl start docker |
| 135 | echo "Info: Remove all previous stopped docker containers and images" |
| 136 | echo "-------------------------------------------------------------" |
| 137 | sudo docker container prune -f |
| 138 | sudo docker image prune -f |
| 139 | echo "Info: Get the latest geode-native build docker image" |
| 140 | echo "-------------------------------------------------------------" |
| 141 | docker pull ${GEODE_NATIVE_DOCKER_IMAGE:-apachegeode/geode-native-build} |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | # Make sure the build server is SLES15 based |
| 145 | source /etc/os-release |
| 146 | case ${ID,,} in |
| 147 | sles) |
| 148 | if [[ "${VERSION}" != "15" ]] ; then |
| 149 | echo "ERROR: Incorrect version on SLES on the build server: ${VERSION}" |
| 150 | exit 1 |
| 151 | else |
| 152 | install_dev_packages |
| 153 | configure_geode_build |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 154 | get_geode_build_docker_image |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 155 | fi |
| 156 | ;; |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 157 | ubuntu) |
| 158 | DPKG_LOCK="/var/lib/dpkg/lock-frontend" |
| 159 | # Wait for other apt process to finish by checking the dpkg lock file. |
| 160 | try=0 |
| 161 | while sudo lsof ${DPKG_LOCK} > /dev/null 2>&1 ; do |
| 162 | echo "DPKG file locked: ${DPKG_LOCK}." |
robert.tomczyk | d90fc4c | 2019-11-18 13:11:54 +0000 | [diff] [blame] | 163 | echo " Waiting for another pkg installation process to finish ..." |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 164 | sleep 10 |
| 165 | if [[ ${try} -gt 60 ]] ; then |
| 166 | echo "ERROR: Max number of re-tries reached, exiting..." |
| 167 | exit 1 |
| 168 | fi |
| 169 | try=$((try + 1)) |
| 170 | done |
| 171 | get_geode_build_docker_image |
| 172 | ;; |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 173 | *) |
robert.tomczyk | 2eac1f4 | 2019-11-14 09:25:33 +0000 | [diff] [blame] | 174 | echo "ERROR: Only SLES15 and Ubuntu OS can be use as a build server geode-native" |
robert.tomczyk | e791f67 | 2019-11-12 12:49:17 +0000 | [diff] [blame] | 175 | exit 2 |
| 176 | ;; |
| 177 | esac |