anitazha / rpms / systemd

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