ryantimwilson / rpms / systemd

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