[libadwaita/wip/exalm/abi-checker: 11/11] ci: Use a container image for abi checker




commit 6087f07d9f84d188762a00d501a98b03bfa8cb8a
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Mar 25 17:28:53 2021 +0500

    ci: Use a container image for abi checker
    
    Borrow a script from GTK.

 .gitlab-ci.yml                    |  10 +--
 .gitlab-ci/README.md              |  10 +++
 .gitlab-ci/abi-checker.Dockerfile |  19 ++++++
 .gitlab-ci/run-docker.sh          | 136 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 167 insertions(+), 8 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f24cb27..e2bfd11 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,6 +6,7 @@ variables:
   MANIFEST_PATH: 'examples/org.gnome.Adwaita.Demo.json'
   FLATPAK_MODULE: 'libadwaita'
   FLATPAK_BUILD_DIR: build
+  ABI_CHECKER_IMAGE: "registry.gitlab.gnome.org/gnome/libadwaita/abi-checker:v1"
 
 stages:
   - build
@@ -46,17 +47,10 @@ build-flatpak:
     BUNDLE: 'org.gnome.Adwaita.Demo.flatpak'
 
 abi-check:
-  # See https://sourceware.org/bugzilla/show_bug.cgi?id=27267
-  image: fedora:33
+  image: $ABI_CHECKER_IMAGE
   stage: build
   variables:
-    DEPS: libabigail git gcc meson pkgconfig(gtk4) vala gobject-introspection
     LAST_ABI_BREAK: "c6ded459e635154ec8b8e2c175b1937f9618fd01"
-  before_script:
-    - dnf -y update
-    - dnf -y install @development-tools redhat-rpm-config dnf-plugins-core $DEPS
-    # See https://sourceware.org/bugzilla/show_bug.cgi?id=27269
-    - rpm -Uvh --oldpackage 
https://kojipkgs.fedoraproject.org//packages/libabigail/1.7/2.fc33/x86_64/libabigail-1.7-2.fc33.x86_64.rpm
   script:
     - ./.gitlab-ci/check-abi ${LAST_ABI_BREAK} $(git rev-parse HEAD)
 
diff --git a/.gitlab-ci/README.md b/.gitlab-ci/README.md
new file mode 100644
index 0000000..c21f289
--- /dev/null
+++ b/.gitlab-ci/README.md
@@ -0,0 +1,10 @@
+### Checklist for Updating the Docker images
+
+ - [ ] Update the `${image}.Dockerfile` file with the dependencies
+ - [ ] Run `./run-docker.sh build --base ${image} --version ${number}`
+ - [ ] Run `./run-docker.sh push --base ${image} --version ${number}`
+   once the Docker image is built; you may need to log in by using
+   `docker login` or `podman login`
+ - [ ] Update the `image` keys in the `.gitlab-ci.yml` file with the new
+   image tag
+ - [ ] Open a merge request with your changes and let it run
diff --git a/.gitlab-ci/abi-checker.Dockerfile b/.gitlab-ci/abi-checker.Dockerfile
new file mode 100644
index 0000000..589f3e0
--- /dev/null
+++ b/.gitlab-ci/abi-checker.Dockerfile
@@ -0,0 +1,19 @@
+# See https://sourceware.org/bugzilla/show_bug.cgi?id=27267
+FROM fedora:33
+
+RUN dnf -y update \
+ && dnf -y install \
+    @development-tools \
+    dnf-plugins-core \
+    gcc \
+    git \
+    gobject-introspection \
+    gtk4-devel \
+    libabigail \
+    meson \
+    redhat-rpm-config \
+    vala \
+ && dnf clean all
+
+# See https://sourceware.org/bugzilla/show_bug.cgi?id=27269
+RUN rpm -Uvh --oldpackage 
https://kojipkgs.fedoraproject.org//packages/libabigail/1.7/2.fc33/x86_64/libabigail-1.7-2.fc33.x86_64.rpm
diff --git a/.gitlab-ci/run-docker.sh b/.gitlab-ci/run-docker.sh
new file mode 100755
index 0000000..d491364
--- /dev/null
+++ b/.gitlab-ci/run-docker.sh
@@ -0,0 +1,136 @@
+#!/bin/bash
+
+read_arg() {
+    # $1 = arg name
+    # $2 = arg value
+    # $3 = arg parameter
+    local rematch='^[^=]*=(.*)$'
+    if [[ $2 =~ $rematch ]]; then
+        read "$1" <<< "${BASH_REMATCH[1]}"
+    else
+        read "$1" <<< "$3"
+        # There is no way to shift our callers args, so
+        # return 1 to indicate they should do it instead.
+        return 1
+    fi
+}
+
+set -e
+
+build=0
+run=0
+push=0
+list=0
+print_help=0
+no_login=0
+
+while (($# > 0)); do
+        case "${1%%=*}" in
+                build) build=1;;
+                run) run=1;;
+                push) push=1;;
+                list) list=1;;
+                help) print_help=1;;
+                --base|-b) read_arg base "$@" || shift;;
+                --version|-v) read_arg base_version "$@" || shift;;
+                --no-login) no_login=1;;
+                *) echo -e "\e[1;31mERROR\e[0m: Unknown option '$1'"; exit 1;;
+        esac
+        shift
+done
+
+if [ $print_help == 1 ]; then
+        echo "$0 - Build and run Docker images"
+        echo ""
+        echo "Usage: $0 <command> [options] [basename]"
+        echo ""
+        echo "Available commands"
+        echo ""
+        echo "  build --base=<BASENAME> - Build Docker image <BASENAME>.Dockerfile"
+        echo "  run --base=<BASENAME>   - Run Docker image <BASENAME>"
+        echo "  push --base=<BASENAME>  - Push Docker image <BASENAME> to the registry"
+        echo "  list                    - List available images"
+        echo "  help                    - This help message"
+        echo ""
+        exit 0
+fi
+
+cd "$(dirname "$0")"
+
+if [ $list == 1 ]; then
+        echo "Available Docker images:"
+        for f in *.Dockerfile; do
+                filename=$( basename -- "$f" )
+                basename="${filename%.*}"
+
+                echo -e "  \e[1;39m$basename\e[0m"
+        done
+        exit 0
+fi
+
+# All commands after this require --base to be set
+if [ -z $base ]; then
+        echo "Usage: $0 <command>"
+        exit 1
+fi
+
+if [ ! -f "$base.Dockerfile" ]; then
+        echo -e "\e[1;31mERROR\e[0m: Dockerfile for '$base' not found"
+        exit 1
+fi
+
+if [ -z $base_version ]; then
+        base_version="latest"
+elif [ $base_version != "latest" ]; then
+        base_version="v$base_version"
+fi
+
+if [ ! -x "$(command -v docker)" ] || [ docker --help |& grep -q podman ]; then
+        # Docker is actually implemented by podman, and its OCI output
+        # is incompatible with some of the dockerd instances on GitLab
+        # CI runners.
+        echo "Using: Podman"
+        format="--format docker"
+        CMD="podman"
+else
+        echo "Using: Docker"
+        format=""
+        CMD="sudo docker"
+fi
+
+REGISTRY="registry.gitlab.gnome.org"
+REPO="gnome/libadwaita"
+TAG="${REGISTRY}/${REPO}/${base}:${base_version}"
+
+if [ $build == 1 ]; then
+        echo -e "\e[1;32mBUILDING\e[0m: ${base} as ${TAG}"
+        ${CMD} build \
+                ${format} \
+                --build-arg HOST_USER_ID="$UID" \
+                --tag "${TAG}" \
+                --file "${base}.Dockerfile" .
+        exit $?
+fi
+
+if [ $push == 1 ]; then
+        echo -e "\e[1;32mPUSHING\e[0m: ${base} as ${TAG}"
+
+        if [ $no_login == 0 ]; then
+                ${CMD} login ${REGISTRY}
+        fi
+
+        ${CMD} push ${TAG}
+        exit $?
+fi
+
+if [ $run == 1 ]; then
+        echo -e "\e[1;32mRUNNING\e[0m: ${base} as ${TAG}"
+        ${CMD} run \
+                --rm \
+                --volume "$(pwd)/..:/home/user/app" \
+                --workdir "/home/user/app" \
+                --tty \
+                --interactive "${TAG}" \
+                bash
+        exit $?
+fi


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]