Blame SOURCES/0063-travis-enable-Travis-CI-on-CentOS-7.patch

a3e2b5
From 5638e18196be1fabd9e78d4c506402bf700fe569 Mon Sep 17 00:00:00 2001
a3e2b5
From: Frantisek Sumsal <fsumsal@redhat.com>
a3e2b5
Date: Mon, 7 Jan 2019 15:49:45 +0100
a3e2b5
Subject: [PATCH] travis: enable Travis CI on CentOS 7
a3e2b5
a3e2b5
(cherry picked from commit 2014cb51b6dfe1f7f0b98e62311398c2bf801c2b)
a3e2b5
---
a3e2b5
 .travis.yml         | 86 ++++++++++-----------------------------------
a3e2b5
 ci/travis-centos.sh | 69 ++++++++++++++++++++++++++++++++++++
a3e2b5
 ci/travis_wait.bash | 61 ++++++++++++++++++++++++++++++++
a3e2b5
 3 files changed, 149 insertions(+), 67 deletions(-)
a3e2b5
 create mode 100755 ci/travis-centos.sh
a3e2b5
 create mode 100644 ci/travis_wait.bash
a3e2b5
a3e2b5
diff --git a/.travis.yml b/.travis.yml
a3e2b5
index d980038181..fc63887324 100644
a3e2b5
--- a/.travis.yml
a3e2b5
+++ b/.travis.yml
a3e2b5
@@ -1,77 +1,29 @@
a3e2b5
 sudo: required
a3e2b5
-
a3e2b5
 services:
a3e2b5
     - docker
a3e2b5
 
a3e2b5
-language: c
a3e2b5
+env:
a3e2b5
+    global:
a3e2b5
+        - CI_ROOT="$TRAVIS_BUILD_DIR/ci/"
a3e2b5
 
a3e2b5
 jobs:
a3e2b5
     include:
a3e2b5
-        - stage: coverity scan
a3e2b5
-          before_script:
a3e2b5
-              - sudo apt-get update
a3e2b5
+        - stage: Build & test
a3e2b5
+          name: CentOS 7
a3e2b5
+          language: bash
a3e2b5
+          env:
a3e2b5
+              - CENTOS_RELEASE="centos7"
a3e2b5
+              - CONT_NAME="systemd-centos-$CENTOS_RELEASE"
a3e2b5
+              - DOCKER_EXEC="docker exec -ti $CONT_NAME"
a3e2b5
+          before_install:
a3e2b5
               - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
a3e2b5
               - docker --version
a3e2b5
-              - env > .env
a3e2b5
-          env:
a3e2b5
-              - COVERITY_SCAN_PROJECT_NAME="$TRAVIS_REPO_SLUG"
a3e2b5
-              - COVERITY_SCAN_NOTIFICATION_EMAIL="${AUTHOR_EMAIL}"
a3e2b5
-              - COVERITY_SCAN_BRANCH_PATTERN="$TRAVIS_BRANCH"
a3e2b5
-              # Encrypted token for systemd/systemd Coverity Scan Analysis,
a3e2b5
-              # generated by "travis encrypt -r systemd/systemd COVERITY_SCAN_TOKEN=<TOKEN>"
a3e2b5
-              - secure: "lM0IVP2zOG5Ywk3YCbDCQL4WioyzzwtdtpZ+hKDy4BWCZDBJ/FVwIeBsXdMDvlTa3xi+GQ1b7kS2OmTfmG4aSlhU7isuH8SMq1Y4GR5AxfhkR+irUA1A1fntlvhbjIumDGW5wjs0Dt8KogMWS+ZD4eGE59lrVO/TrhMzIe1eHENVLFQJdNq+ZJXU8wxMfHf8lXk0xA8SJTid0XvZBNc4JN6pjJRA8LaOrMNhQYfygFmVQ598kwlu7gf5vbCKFPnIgJAxdIhz12XS9utGohV28IYj9d1DdUGUT+ar3OfADj3X8KFBP4Ymc02pcln3wVgdPtrDbFZh1R9jbmfdXGAH/6tTOJVn8aFySS2Vq9QiBiprWdPsAOLcWMNhnp0lMkASxs9/W26nU7Czo8VbAVWXM1w35plDpnDGR6lk/06dmOZpqu5p3AYr5xIKACIAdPDn0rNpnSWqC750WZ8ZWbHnKuZC5TWML7scVaPiEi7D7rbwqML2rdwx4ZoTZmCHiGByXCIWTfhf0JNQAix5WW3znl+BmDesumPgPj2mX+y6J1WYJrIz12m7qh7KhV/a1ODKM+I91A9rkOA/bPnmhmSSUR7CwgvZt1fC/VwBnaFFtAz9/70kN9Q8tDBXtXidExZwh1e3t5vDG72k3lXwNqpKRvdW3LOxK6lFvqEdMWVUJls="
a3e2b5
+          install:
a3e2b5
+              - $CI_ROOT/travis-centos.sh SETUP
a3e2b5
           script:
a3e2b5
-                # Copy content of CI_DIR into WORKDIR
a3e2b5
-              - find $CI_DIR -maxdepth 1 -type f -exec cp -t . {} +
a3e2b5
-                # Build container for current user
a3e2b5
-              - $CI_SCRIPT_DIR/build-docker-image.sh
a3e2b5
-
a3e2b5
-                # For kernel version 4.8+
a3e2b5
-              - sudo sysctl vsyscall=emulate || true
a3e2b5
-                # Prepare environment for Coverity tool
a3e2b5
-              - |
a3e2b5
-                  PLATFORM=`uname`
a3e2b5
-                  export TOOL_BASE="/tmp/coverity-scan-analysis"
a3e2b5
-                  export SCAN_URL="https://scan.coverity.com"
a3e2b5
-                  export UPLOAD_URL="https://scan.coverity.com/builds"
a3e2b5
-                  export TOOL_ARCHIVE="/tmp/cov-analysis-${PLATFORM}.tgz"
a3e2b5
-
a3e2b5
-                # Get Coverity tool
a3e2b5
-              - $CI_TOOL_DIR/get-coverity.sh
a3e2b5
-              - TOOL_DIR="$(find $TOOL_BASE -type d -name 'cov-analysis*')"
a3e2b5
-
a3e2b5
-                # Export env variables for Coverity scan
a3e2b5
-              - env | grep -E "TRAVIS|COV|TOOL|URL" > .cov-env
a3e2b5
-              - |
a3e2b5
-                  docker run -dit --env-file .cov-env \
a3e2b5
-                  -v ${TOOL_BASE}:${TOOL_BASE}:ro \
a3e2b5
-                  --name travis_coverity_scan coverity-${TRAVIS_COMMIT}:latest bash
a3e2b5
-                # Make sure Coverity script is executable
a3e2b5
-              - docker cp tools/coverity.sh travis_coverity_scan:/usr/local/bin
a3e2b5
-                # Preconfigure with meson to prevent Coverity from capturing meson metadata
a3e2b5
-                # Set compiler flag to prevent emit failure
a3e2b5
-              - docker exec -it travis_coverity_scan sh -c "CFLAGS='-D_Float128=long\ double -D_Float64=double -D_Float64x=long\ double -D_Float32=float -D_Float32x=double' meson cov-build -Dman=false"
a3e2b5
-                # Run Coverity Analysis
a3e2b5
-              - docker exec -it travis_coverity_scan coverity.sh build
a3e2b5
-              - docker exec -it travis_coverity_scan coverity.sh upload
a3e2b5
-
a3e2b5
-# Specify the order of stages and conditions
a3e2b5
-stages:
a3e2b5
-    - name: coverity scan
a3e2b5
-      if: type = cron
a3e2b5
-
a3e2b5
-env:
a3e2b5
-    global:
a3e2b5
-        - ADMIN_EMAIL=macermak@redhat.com
a3e2b5
-
a3e2b5
-        - AUTHOR_NAME="$(git log -1 $TRAVIS_COMMIT --pretty=\"%aN\")"
a3e2b5
-        - AUTHOR_EMAIL="$(git log -1 $TRAVIS_COMMIT --pretty=\"%aE\")"
a3e2b5
-
a3e2b5
-        - CI_DIR="$TRAVIS_BUILD_DIR/travis-ci"
a3e2b5
-        - CI_TOOL_DIR="$CI_DIR/tools"
a3e2b5
-        - CI_SCRIPT_DIR="$CI_DIR/scripts"
a3e2b5
-
a3e2b5
-notifications:
a3e2b5
-  email:
a3e2b5
-    recipients:
a3e2b5
-      - ${ADMIN_EMAIL}
a3e2b5
+              - set -e
a3e2b5
+              # Build systemd
a3e2b5
+              - $CI_ROOT/travis-centos.sh RUN
a3e2b5
+              - set +e
a3e2b5
+          after_script:
a3e2b5
+              - $CI_ROOT/travis-centos.sh CLEANUP
a3e2b5
diff --git a/ci/travis-centos.sh b/ci/travis-centos.sh
a3e2b5
new file mode 100755
a3e2b5
index 0000000000..60bbdf14c2
a3e2b5
--- /dev/null
a3e2b5
+++ b/ci/travis-centos.sh
a3e2b5
@@ -0,0 +1,69 @@
a3e2b5
+#!/bin/bash
a3e2b5
+
a3e2b5
+# Run this script from the root of the systemd's git repository
a3e2b5
+# or set REPO_ROOT to a correct path.
a3e2b5
+#
a3e2b5
+# Example execution on Fedora:
a3e2b5
+# dnf install docker
a3e2b5
+# systemctl start docker
a3e2b5
+# export CONT_NAME="my-fancy-container"
a3e2b5
+# ci/travis-centos.sh SETUP RUN CLEANUP
a3e2b5
+
a3e2b5
+PHASES=(${@:-SETUP RUN CLEANUP})
a3e2b5
+CENTOS_RELEASE="${CENTOS_RELEASE:-latest}"
a3e2b5
+CONT_NAME="${CONT_NAME:-centos-$CENTOS_RELEASE-$RANDOM}"
a3e2b5
+DOCKER_EXEC="${DOCKER_EXEC:-docker exec -it $CONT_NAME}"
a3e2b5
+DOCKER_RUN="${DOCKER_RUN:-docker run}"
a3e2b5
+REPO_ROOT="${REPO_ROOT:-$PWD}"
a3e2b5
+ADDITIONAL_DEPS=(yum-utils iputils hostname libasan libubsan clang llvm)
a3e2b5
+
a3e2b5
+function info() {
a3e2b5
+    echo -e "\033[33;1m$1\033[0m"
a3e2b5
+}
a3e2b5
+
a3e2b5
+set -e
a3e2b5
+
a3e2b5
+source "$(dirname $0)/travis_wait.bash"
a3e2b5
+
a3e2b5
+for phase in "${PHASES[@]}"; do
a3e2b5
+    case $phase in
a3e2b5
+        SETUP)
a3e2b5
+            info "Setup phase"
a3e2b5
+            info "Using Travis $CENTOS_RELEASE"
a3e2b5
+            # Pull a Docker image and start a new container
a3e2b5
+            docker pull centos:$CENTOS_RELEASE
a3e2b5
+            info "Starting container $CONT_NAME"
a3e2b5
+            $DOCKER_RUN -v $REPO_ROOT:/build:rw \
a3e2b5
+                        -w /build --privileged=true --name $CONT_NAME \
a3e2b5
+                        -dit --net=host centos:$CENTOS_RELEASE /sbin/init
a3e2b5
+            # Beautiful workaround for Fedora's version of Docker
a3e2b5
+            sleep 1
a3e2b5
+            $DOCKER_EXEC yum makecache
a3e2b5
+            # Install necessary build/test requirements
a3e2b5
+            $DOCKER_EXEC yum -y --exclude selinux-policy\* upgrade
a3e2b5
+            $DOCKER_EXEC yum -y install "${ADDITIONAL_DEPS[@]}"
a3e2b5
+            $DOCKER_EXEC yum-builddep -y systemd
a3e2b5
+            ;;
a3e2b5
+        RUN)
a3e2b5
+            info "Run phase"
a3e2b5
+            # Build systemd
a3e2b5
+            $DOCKER_EXEC ./autogen.sh
a3e2b5
+            $DOCKER_EXEC ./configure --disable-timesyncd --disable-kdbus --disable-terminal \
a3e2b5
+                                     --enable-gtk-doc --enable-compat-libs --disable-sysusers \
a3e2b5
+                                     --disable-ldconfig --enable-lz4 --with-sysvinit-path=/etc/rc.d/init.d
a3e2b5
+            $DOCKER_EXEC make
a3e2b5
+            if ! $DOCKER_EXEC make check; then
a3e2b5
+                $DOCKER_EXEC cat test-suite.log
a3e2b5
+                exit 1
a3e2b5
+            fi
a3e2b5
+            ;;
a3e2b5
+        CLEANUP)
a3e2b5
+            info "Cleanup phase"
a3e2b5
+            docker stop $CONT_NAME
a3e2b5
+            docker rm -f $CONT_NAME
a3e2b5
+            ;;
a3e2b5
+        *)
a3e2b5
+            echo >&2 "Unknown phase '$phase'"
a3e2b5
+            exit 1
a3e2b5
+    esac
a3e2b5
+done
a3e2b5
diff --git a/ci/travis_wait.bash b/ci/travis_wait.bash
a3e2b5
new file mode 100644
a3e2b5
index 0000000000..acf6ad15e4
a3e2b5
--- /dev/null
a3e2b5
+++ b/ci/travis_wait.bash
a3e2b5
@@ -0,0 +1,61 @@
a3e2b5
+# This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash
a3e2b5
+# to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed
a3e2b5
+# as soon as Travis CI has started to provide an easy way to export the functions to bash scripts.
a3e2b5
+
a3e2b5
+travis_jigger() {
a3e2b5
+  local cmd_pid="${1}"
a3e2b5
+  shift
a3e2b5
+  local timeout="${1}"
a3e2b5
+  shift
a3e2b5
+  local count=0
a3e2b5
+
a3e2b5
+  echo -e "\\n"
a3e2b5
+
a3e2b5
+  while [[ "${count}" -lt "${timeout}" ]]; do
a3e2b5
+    count="$((count + 1))"
a3e2b5
+    echo -ne "Still running (${count} of ${timeout}): ${*}\\r"
a3e2b5
+    sleep 60
a3e2b5
+  done
a3e2b5
+
a3e2b5
+  echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n"
a3e2b5
+  kill -9 "${cmd_pid}"
a3e2b5
+}
a3e2b5
+
a3e2b5
+travis_wait() {
a3e2b5
+  local timeout="${1}"
a3e2b5
+
a3e2b5
+  if [[ "${timeout}" =~ ^[0-9]+$ ]]; then
a3e2b5
+    shift
a3e2b5
+  else
a3e2b5
+    timeout=20
a3e2b5
+  fi
a3e2b5
+
a3e2b5
+  local cmd=("${@}")
a3e2b5
+  local log_file="travis_wait_${$}.log"
a3e2b5
+
a3e2b5
+  "${cmd[@]}" &>"${log_file}" &
a3e2b5
+  local cmd_pid="${!}"
a3e2b5
+
a3e2b5
+  travis_jigger "${!}" "${timeout}" "${cmd[@]}" &
a3e2b5
+  local jigger_pid="${!}"
a3e2b5
+  local result
a3e2b5
+
a3e2b5
+  {
a3e2b5
+    set +e
a3e2b5
+    wait "${cmd_pid}" 2>/dev/null
a3e2b5
+    result="${?}"
a3e2b5
+    ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}"
a3e2b5
+    set -e
a3e2b5
+  }
a3e2b5
+
a3e2b5
+  if [[ "${result}" -eq 0 ]]; then
a3e2b5
+    echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
a3e2b5
+  else
a3e2b5
+    echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
a3e2b5
+  fi
a3e2b5
+
a3e2b5
+  echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n"
a3e2b5
+  cat "${log_file}"
a3e2b5
+
a3e2b5
+  return "${result}"
a3e2b5
+}