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