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