From e2c7b61f97465b26c598d655c8717403c0a73726 Mon Sep 17 00:00:00 2001
From: Frantisek Sumsal <frantisek@sumsal.cz>
Date: Sat, 13 Nov 2021 16:35:23 +0100
Subject: [PATCH] ci: introduce C8S based GHA CI
Loosely based on the upstream dracut CI to make things simpler.
rhel-only
---
.github/workflows/container.yml | 52 +++++++++++++++++++++++++++++
.github/workflows/integration.yml | 48 +++++++++++++++++++++++++++
test/container/Dockerfile-CentOS-8-Stream | 54 +++++++++++++++++++++++++++++++
tools/test-github.sh | 49 ++++++++++++++++++++++++++++
4 files changed, 203 insertions(+)
diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml
new file mode 100644
index 00000000..0a4c000f
--- /dev/null
+++ b/.github/workflows/container.yml
@@ -0,0 +1,52 @@
+name: Container
+on:
+ schedule:
+ - cron: '30 11 * * *'
+ push:
+ branches: [ main ]
+ paths:
+ - 'test/container/**'
+ - '.github/workflows/container.yml'
+ pull_request:
+ branches: [ main ]
+ paths:
+ - 'test/container/**'
+ - '.github/workflows/container.yml'
+
+permissions:
+ packages: write
+ contents: read
+
+jobs:
+ push_to_registry:
+ name: Build and push containers image to GitHub Packages
+ runs-on: ubuntu-latest
+ concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.config.dockerfile }}
+ cancel-in-progress: true
+ strategy:
+ fail-fast: false
+ matrix:
+ config:
+ # Use a prefixed image name to not conflict with the "centos"
+ # image from redhat-plumbers/dracut-rhel9
+ - { dockerfile: 'Dockerfile-CentOS-8-Stream', tag: 'rhel8_centos:stream8' }
+ steps:
+ - name: Check out the repo
+ uses: actions/checkout@v2
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v1
+# with:
+# buildkitd-flags: --debug
+ - name: Login to GitHub Container Registry
+ uses: docker/login-action@v1
+ with:
+ registry: ghcr.io
+ username: ${{ github.repository_owner }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ - name: Build and Push Container
+ uses: docker/build-push-action@v2
+ with:
+ file: test/container/${{ matrix.config.dockerfile }}
+ tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.config.tag }}
+ push: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml
new file mode 100644
index 00000000..80a856a2
--- /dev/null
+++ b/.github/workflows/integration.yml
@@ -0,0 +1,48 @@
+name: Integration Test
+
+on:
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ centos-8-stream:
+ runs-on: ubuntu-latest
+ timeout-minutes: 45
+ concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.container }}-${{ matrix.test }}
+ cancel-in-progress: true
+ strategy:
+ matrix:
+ container: [
+ "rhel8_centos:stream8",
+ ]
+ # Disabled tests (due to dropped packages in RHEL/CentOS):
+ # 03, 04, 15: requires btrfs
+ # 14: requires dmraid
+ # 30, 31, 35, 36: requires scsi-target-utils
+ test: [
+ "01",
+ "02",
+ "10",
+ "11",
+ "12",
+ "13",
+ "17",
+ "20",
+ #"21", needs backport (NFS + NM)
+ "40",
+ #"41", needws backport (NBD + NM)
+ "98",
+ ]
+ fail-fast: false
+ container:
+ image: ghcr.io/${{ github.repository_owner }}/${{ matrix.container }}
+ options: "--privileged -v /dev:/dev"
+ steps:
+ - name: "Checkout Repository"
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: "${{ matrix.container }} TEST-${{ matrix.test }}"
+ run: ./tools/test-github.sh "TEST-${{ matrix.test }}" ${{ matrix.test }}
diff --git a/test/container/Dockerfile-CentOS-8-Stream b/test/container/Dockerfile-CentOS-8-Stream
new file mode 100644
index 00000000..0eda4a7e
--- /dev/null
+++ b/test/container/Dockerfile-CentOS-8-Stream
@@ -0,0 +1,54 @@
+FROM quay.io/centos/centos:stream8
+
+MAINTAINER https://github.com/dracutdevs/dracut
+
+ENV container docker
+LABEL RUN="docker run -it --name NAME --privileged --ipc=host --net=host --pid=host -e NAME=NAME -e IMAGE=IMAGE IMAGE"
+
+RUN echo 'export DRACUT_NO_XATTR=1 KVERSION=$(cd /lib/modules; ls -1 | tail -1)' > /etc/profile.d/dracut-test.sh
+
+# Install needed packages for the dracut CI container
+RUN dnf -y install epel-release && \
+ dnf -y install --enablerepo powertools --enablerepo epel --setopt=install_weak_deps=False \
+ qemu-kvm \
+ NetworkManager \
+ asciidoc \
+ bash-completion \
+ bzip2 \
+ cryptsetup \
+ dash \
+ dbus-daemon \
+ dhcp-client \
+ dhcp-server \
+ e2fsprogs \
+ gcc \
+ git \
+ iproute \
+ iputils \
+ iscsi-initiator-utils \
+ kbd \
+ kernel \
+ kmod-devel \
+ lvm2 \
+ make \
+ mdadm \
+ nfs-utils \
+ pigz \
+ python3-imgcreate \
+ rpm-build \
+ strace \
+ sudo \
+ tar \
+ tcpdump \
+ wget \
+ which \
+ xz \
+ && dnf -y update && dnf clean all
+
+# CentOS 8 ships only qemu-kvm, but it disables the KVM accel when it's not
+# available
+RUN ln -sv /usr/libexec/qemu-kvm /usr/bin/qemu-kvm && \
+ ln -sv /usr/libexec/qemu-kvm /usr/bin/qemu-system-$(uname -m)
+
+# Set default command
+CMD ["/usr/bin/bash"]
diff --git a/tools/test-github.sh b/tools/test-github.sh
new file mode 100755
index 00000000..eab59dcc
--- /dev/null
+++ b/tools/test-github.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+set -ex
+
+[[ -d ${0%/*} ]] && cd "${0%/*}"/../
+
+RUN_ID="$1"
+TESTS=$2
+
+./configure
+
+NCPU=$(getconf _NPROCESSORS_ONLN)
+
+if ! [[ $TESTS ]]; then
+ # GitHub workflows fetch a clone of the dracut repository which doesn't
+ # contain git tags, thus "breaking" the RPM build in certain situations
+ # i.e.:
+ # DRACUT_MAIN_VERSION in Makefile is defined as an output of `git describe`,
+ # which in full git clone returns a tag with a numeric version. However,
+ # without tags it returns SHA of the last commit, which later propagates into
+ # `Provides:` attribute of the built RPM and can break dependency tree when
+ # installed
+ [[ -d .git ]] && git fetch --tags && git describe --tags
+ make -j "$NCPU" all syncheck rpm logtee
+else
+ if [[ $TESTS == "99" ]]; then
+ [[ -d .git ]] && git fetch --tags && git describe --tags
+ make_docs=yes
+ else
+ make_docs=no
+ fi
+
+ make -j "$NCPU" enable_documentation=$make_docs all logtee
+
+ cd test
+
+ # shellcheck disable=SC2012
+ time LOGTEE_TIMEOUT_MS=590000 make \
+ enable_documentation=$make_docs \
+ KVERSION="$(
+ cd /lib/modules
+ ls -1 | tail -1
+ )" \
+ DRACUT_NO_XATTR=1 \
+ TEST_RUN_ID="$RUN_ID" \
+ ${TESTS:+TESTS="$TESTS"} \
+ -k V=1 \
+ check
+fi