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