richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Pablo Greco 48fc63
From 2014cb51b6dfe1f7f0b98e62311398c2bf801c2b Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: Frantisek Sumsal <fsumsal@redhat.com>
Pablo Greco 48fc63
Date: Mon, 7 Jan 2019 15:49:45 +0100
Pablo Greco 48fc63
Subject: [PATCH] travis: enable Travis CI on CentOS 7
Pablo Greco 48fc63
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 .travis.yml         | 43 +++++++++++++++++++---------
Pablo Greco 48fc63
 ci/travis-centos.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++
Pablo Greco 48fc63
 ci/travis_wait.bash | 61 +++++++++++++++++++++++++++++++++++++++
Pablo Greco 48fc63
 3 files changed, 159 insertions(+), 14 deletions(-)
Pablo Greco 48fc63
 create mode 100755 ci/travis-centos.sh
Pablo Greco 48fc63
 create mode 100644 ci/travis_wait.bash
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/.travis.yml b/.travis.yml
Pablo Greco 48fc63
index 4ea2bc2d30..fc63887324 100644
Pablo Greco 48fc63
--- a/.travis.yml
Pablo Greco 48fc63
+++ b/.travis.yml
Pablo Greco 48fc63
@@ -1,14 +1,29 @@
Pablo Greco 48fc63
-language: c
Pablo Greco 48fc63
-compiler:
Pablo Greco 48fc63
-  - gcc
Pablo Greco 48fc63
-before_install:
Pablo Greco 48fc63
- - sudo apt-get update -qq
Pablo Greco 48fc63
- - sudo apt-get install autotools-dev automake autoconf libtool libdbus-1-dev libcap-dev libblkid-dev libmount-dev libpam-dev libcryptsetup-dev libaudit-dev libacl1-dev libattr1-dev libselinux-dev liblzma-dev libgcrypt-dev libqrencode-dev libmicrohttpd-dev gtk-doc-tools gperf python2.7-dev
Pablo Greco 48fc63
-script: ./autogen.sh && ./configure --enable-gtk-doc --enable-gtk-doc-pdf && make V=1 && sudo ./systemd-machine-id-setup && make check && make distcheck
Pablo Greco 48fc63
-after_failure: cat test-suite.log
Pablo Greco 48fc63
-notifications:
Pablo Greco 48fc63
-  irc:
Pablo Greco 48fc63
-    channels:
Pablo Greco 48fc63
-      - "irc.freenode.org#systemd"
Pablo Greco 48fc63
-    on_success: change
Pablo Greco 48fc63
-    on_failure: always
Pablo Greco 48fc63
+sudo: required
Pablo Greco 48fc63
+services:
Pablo Greco 48fc63
+    - docker
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+env:
Pablo Greco 48fc63
+    global:
Pablo Greco 48fc63
+        - CI_ROOT="$TRAVIS_BUILD_DIR/ci/"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+jobs:
Pablo Greco 48fc63
+    include:
Pablo Greco 48fc63
+        - stage: Build & test
Pablo Greco 48fc63
+          name: CentOS 7
Pablo Greco 48fc63
+          language: bash
Pablo Greco 48fc63
+          env:
Pablo Greco 48fc63
+              - CENTOS_RELEASE="centos7"
Pablo Greco 48fc63
+              - CONT_NAME="systemd-centos-$CENTOS_RELEASE"
Pablo Greco 48fc63
+              - DOCKER_EXEC="docker exec -ti $CONT_NAME"
Pablo Greco 48fc63
+          before_install:
Pablo Greco 48fc63
+              - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
Pablo Greco 48fc63
+              - docker --version
Pablo Greco 48fc63
+          install:
Pablo Greco 48fc63
+              - $CI_ROOT/travis-centos.sh SETUP
Pablo Greco 48fc63
+          script:
Pablo Greco 48fc63
+              - set -e
Pablo Greco 48fc63
+              # Build systemd
Pablo Greco 48fc63
+              - $CI_ROOT/travis-centos.sh RUN
Pablo Greco 48fc63
+              - set +e
Pablo Greco 48fc63
+          after_script:
Pablo Greco 48fc63
+              - $CI_ROOT/travis-centos.sh CLEANUP
Pablo Greco 48fc63
diff --git a/ci/travis-centos.sh b/ci/travis-centos.sh
Pablo Greco 48fc63
new file mode 100755
Pablo Greco 48fc63
index 0000000000..60bbdf14c2
Pablo Greco 48fc63
--- /dev/null
Pablo Greco 48fc63
+++ b/ci/travis-centos.sh
Pablo Greco 48fc63
@@ -0,0 +1,69 @@
Pablo Greco 48fc63
+#!/bin/bash
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+# Run this script from the root of the systemd's git repository
Pablo Greco 48fc63
+# or set REPO_ROOT to a correct path.
Pablo Greco 48fc63
+#
Pablo Greco 48fc63
+# Example execution on Fedora:
Pablo Greco 48fc63
+# dnf install docker
Pablo Greco 48fc63
+# systemctl start docker
Pablo Greco 48fc63
+# export CONT_NAME="my-fancy-container"
Pablo Greco 48fc63
+# ci/travis-centos.sh SETUP RUN CLEANUP
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+PHASES=(${@:-SETUP RUN CLEANUP})
Pablo Greco 48fc63
+CENTOS_RELEASE="${CENTOS_RELEASE:-latest}"
Pablo Greco 48fc63
+CONT_NAME="${CONT_NAME:-centos-$CENTOS_RELEASE-$RANDOM}"
Pablo Greco 48fc63
+DOCKER_EXEC="${DOCKER_EXEC:-docker exec -it $CONT_NAME}"
Pablo Greco 48fc63
+DOCKER_RUN="${DOCKER_RUN:-docker run}"
Pablo Greco 48fc63
+REPO_ROOT="${REPO_ROOT:-$PWD}"
Pablo Greco 48fc63
+ADDITIONAL_DEPS=(yum-utils iputils hostname libasan libubsan clang llvm)
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+function info() {
Pablo Greco 48fc63
+    echo -e "\033[33;1m$1\033[0m"
Pablo Greco 48fc63
+}
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+set -e
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+source "$(dirname $0)/travis_wait.bash"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+for phase in "${PHASES[@]}"; do
Pablo Greco 48fc63
+    case $phase in
Pablo Greco 48fc63
+        SETUP)
Pablo Greco 48fc63
+            info "Setup phase"
Pablo Greco 48fc63
+            info "Using Travis $CENTOS_RELEASE"
Pablo Greco 48fc63
+            # Pull a Docker image and start a new container
Pablo Greco 48fc63
+            docker pull centos:$CENTOS_RELEASE
Pablo Greco 48fc63
+            info "Starting container $CONT_NAME"
Pablo Greco 48fc63
+            $DOCKER_RUN -v $REPO_ROOT:/build:rw \
Pablo Greco 48fc63
+                        -w /build --privileged=true --name $CONT_NAME \
Pablo Greco 48fc63
+                        -dit --net=host centos:$CENTOS_RELEASE /sbin/init
Pablo Greco 48fc63
+            # Beautiful workaround for Fedora's version of Docker
Pablo Greco 48fc63
+            sleep 1
Pablo Greco 48fc63
+            $DOCKER_EXEC yum makecache
Pablo Greco 48fc63
+            # Install necessary build/test requirements
Pablo Greco 48fc63
+            $DOCKER_EXEC yum -y --exclude selinux-policy\* upgrade
Pablo Greco 48fc63
+            $DOCKER_EXEC yum -y install "${ADDITIONAL_DEPS[@]}"
Pablo Greco 48fc63
+            $DOCKER_EXEC yum-builddep -y systemd
Pablo Greco 48fc63
+            ;;
Pablo Greco 48fc63
+        RUN)
Pablo Greco 48fc63
+            info "Run phase"
Pablo Greco 48fc63
+            # Build systemd
Pablo Greco 48fc63
+            $DOCKER_EXEC ./autogen.sh
Pablo Greco 48fc63
+            $DOCKER_EXEC ./configure --disable-timesyncd --disable-kdbus --disable-terminal \
Pablo Greco 48fc63
+                                     --enable-gtk-doc --enable-compat-libs --disable-sysusers \
Pablo Greco 48fc63
+                                     --disable-ldconfig --enable-lz4 --with-sysvinit-path=/etc/rc.d/init.d
Pablo Greco 48fc63
+            $DOCKER_EXEC make
Pablo Greco 48fc63
+            if ! $DOCKER_EXEC make check; then
Pablo Greco 48fc63
+                $DOCKER_EXEC cat test-suite.log
Pablo Greco 48fc63
+                exit 1
Pablo Greco 48fc63
+            fi
Pablo Greco 48fc63
+            ;;
Pablo Greco 48fc63
+        CLEANUP)
Pablo Greco 48fc63
+            info "Cleanup phase"
Pablo Greco 48fc63
+            docker stop $CONT_NAME
Pablo Greco 48fc63
+            docker rm -f $CONT_NAME
Pablo Greco 48fc63
+            ;;
Pablo Greco 48fc63
+        *)
Pablo Greco 48fc63
+            echo >&2 "Unknown phase '$phase'"
Pablo Greco 48fc63
+            exit 1
Pablo Greco 48fc63
+    esac
Pablo Greco 48fc63
+done
Pablo Greco 48fc63
diff --git a/ci/travis_wait.bash b/ci/travis_wait.bash
Pablo Greco 48fc63
new file mode 100644
Pablo Greco 48fc63
index 0000000000..acf6ad15e4
Pablo Greco 48fc63
--- /dev/null
Pablo Greco 48fc63
+++ b/ci/travis_wait.bash
Pablo Greco 48fc63
@@ -0,0 +1,61 @@
Pablo Greco 48fc63
+# This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash
Pablo Greco 48fc63
+# to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed
Pablo Greco 48fc63
+# as soon as Travis CI has started to provide an easy way to export the functions to bash scripts.
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+travis_jigger() {
Pablo Greco 48fc63
+  local cmd_pid="${1}"
Pablo Greco 48fc63
+  shift
Pablo Greco 48fc63
+  local timeout="${1}"
Pablo Greco 48fc63
+  shift
Pablo Greco 48fc63
+  local count=0
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  echo -e "\\n"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  while [[ "${count}" -lt "${timeout}" ]]; do
Pablo Greco 48fc63
+    count="$((count + 1))"
Pablo Greco 48fc63
+    echo -ne "Still running (${count} of ${timeout}): ${*}\\r"
Pablo Greco 48fc63
+    sleep 60
Pablo Greco 48fc63
+  done
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n"
Pablo Greco 48fc63
+  kill -9 "${cmd_pid}"
Pablo Greco 48fc63
+}
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+travis_wait() {
Pablo Greco 48fc63
+  local timeout="${1}"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  if [[ "${timeout}" =~ ^[0-9]+$ ]]; then
Pablo Greco 48fc63
+    shift
Pablo Greco 48fc63
+  else
Pablo Greco 48fc63
+    timeout=20
Pablo Greco 48fc63
+  fi
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  local cmd=("${@}")
Pablo Greco 48fc63
+  local log_file="travis_wait_${$}.log"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  "${cmd[@]}" &>"${log_file}" &
Pablo Greco 48fc63
+  local cmd_pid="${!}"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  travis_jigger "${!}" "${timeout}" "${cmd[@]}" &
Pablo Greco 48fc63
+  local jigger_pid="${!}"
Pablo Greco 48fc63
+  local result
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  {
Pablo Greco 48fc63
+    set +e
Pablo Greco 48fc63
+    wait "${cmd_pid}" 2>/dev/null
Pablo Greco 48fc63
+    result="${?}"
Pablo Greco 48fc63
+    ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}"
Pablo Greco 48fc63
+    set -e
Pablo Greco 48fc63
+  }
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  if [[ "${result}" -eq 0 ]]; then
Pablo Greco 48fc63
+    echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
Pablo Greco 48fc63
+  else
Pablo Greco 48fc63
+    echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
Pablo Greco 48fc63
+  fi
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n"
Pablo Greco 48fc63
+  cat "${log_file}"
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+  return "${result}"
Pablo Greco 48fc63
+}