[librsvg: 1/2] Add tools dir with Docker test scripts This allows someone to use docker to run the librsvg check su




commit 7f675237d2d8ee2577b26556c77182514a58479d
Author: Madds H <madds hollandart io>
Date:   Sat Jun 26 01:20:03 2021 -0500

    Add tools dir with Docker test scripts
    This allows someone to use docker to run the librsvg check suite
    with choice of 3 OS images, opensuse, fedora, or debian
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/557>

 .gitignore                                    |   6 +
 tools/docker/README.md                        |  42 +++++
 tools/docker/build-librsvg.sh                 |   4 +
 tools/docker/debian/Dockerfile                |   5 +
 tools/docker/docker-test.sh                   | 249 ++++++++++++++++++++++++++
 tools/docker/fedora/Dockerfile                |   5 +
 tools/docker/librsvg-base/debian/Dockerfile   |   6 +
 tools/docker/librsvg-base/fedora/Dockerfile   |   6 +
 tools/docker/librsvg-base/opensuse/Dockerfile |   6 +
 tools/docker/opensuse/Dockerfile              |   5 +
 10 files changed, 334 insertions(+)
---
diff --git a/.gitignore b/.gitignore
index 0849d20b..de909c2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -83,3 +83,9 @@ librsvg-*.tar.xz
 librsvg-*.tar.bz2
 _rsvg_dummy.c
 include/librsvg/rsvg-version.h
+tools/docker/debian/build-librsvg.sh
+tools/docker/debian/librsvg.tar.gz
+tools/docker/opensuse/build-librsvg.sh
+tools/docker/opensuse/librsvg.tar.gz
+tools/docker/fedora/build-librsvg.sh
+tools/docker/fedora/librsvg.tar.gz
\ No newline at end of file
diff --git a/tools/docker/README.md b/tools/docker/README.md
new file mode 100644
index 00000000..70a8ef68
--- /dev/null
+++ b/tools/docker/README.md
@@ -0,0 +1,42 @@
+### Librsvg Docker Tests
+
+Run the librsvg test suite inside a docker container. Run the script from within this directory. The Librsvg 
CI runs on opensuse, so this is a simple-ish way to run the test suite locally on the same packages that are 
used by the Gitlab integration. 
+
+The build-librsvg.sh script is used internally by the docker-test.sh script, do not run it by itself. (It's 
not harmful but can unexpectedly modify some files in your tmp directory.)
+
+Usage:
+```
+This tool lets you run Librsvg's test suite under a couple different docker containers for testing, it 
requires sudo privleges, which it will ask for in the terminal (this is by the docker commands, which require 
root)
+
+Use -d [DIRECTORY] pointing at your librsvg directory
+Use -s [SYSTEM] to determine what docker container to use (Fedora, OpenSUSE, or Debian)
+use -h to return this help
+use -i to have it pause periodically to check output
+use -r to rebuild the docker image forcefully
+use -p to repackage the librsvg image (use in conjunction with -r otherwise the cache will stop changes from 
taking
+use -t to specify a temporary directory (default: /tmp/librsvg)
+```
+
+Example:
+```
+If the librsvg folder is in your home directory:
+./docker-test.sh -d ~/librsvg -s opensuse -i 
+
+This will run it pointing at /home/Username/librsvg with opensuse tumbleweed docker image, and interactive, 
meaning it pauses and has the user input a keystroke before continuing, useful for debugging. 
+```
+
+
+Cleanup:
+```
+To do a full cleanup of the docker images:
+./docker-test.sh -c
+This requires user input
+
+I would then suggest either manually rm -r the temp directory you're using (if different than default) or 
restarting your system to clear out /tmp
+
+Also:
+docker image prune
+
+removes any dangling (not attached to an tagged image) docker containers
+```
+
diff --git a/tools/docker/build-librsvg.sh b/tools/docker/build-librsvg.sh
new file mode 100755
index 00000000..490e2e5d
--- /dev/null
+++ b/tools/docker/build-librsvg.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+cd /tmp/librsvg/
+sh /tmp/librsvg/autogen.sh
+make check
diff --git a/tools/docker/debian/Dockerfile b/tools/docker/debian/Dockerfile
new file mode 100644
index 00000000..0e8f9869
--- /dev/null
+++ b/tools/docker/debian/Dockerfile
@@ -0,0 +1,5 @@
+FROM librsvg/librsvg-base-debian
+MAINTAINER librsvg
+ADD librsvg.tar.gz /tmp/librsvg/
+ADD build-librsvg.sh /tmp/librsvg/
+CMD ["bash","/tmp/librsvg/build-librsvg.sh"]
diff --git a/tools/docker/docker-test.sh b/tools/docker/docker-test.sh
new file mode 100755
index 00000000..3d019a81
--- /dev/null
+++ b/tools/docker/docker-test.sh
@@ -0,0 +1,249 @@
+#!/bin/bash
+REPACKAGE=false
+INT=false
+SYS="no"
+REBUILD=false
+DIR=no
+TMPDIR=/tmp/librsvg
+CLEANUP=false
+
+function usage {
+        echo "This tool lets you run Librsvg's test suite under a couple different"
+        echo "docker containers for testing, it requires sudo privleges (for the docker commands)"
+        echo "Use -d [DIRECTORY] pointing at your librsvg Directory"
+        echo "Use -s [SYSTEM] to determine what docker container to use (Fedora, OpenSUSE, Debian)"
+        echo "Use -h to return this Help"
+        echo "Use -i to have it Interactively pause periodically to check output"
+        echo "Use -r to Rebuild the docker image forcefully"
+        echo "Use -p to rePackage the librsvg tar (use in conjunction with -r otherwise the cache will stop 
changes from taking"
+               echo "Use -t to specify a Temporary directory (default: /tmp/librsvg)"
+               echo "Use -c to Cleanup ALL related docker images (this will not run the test suite)"
+}
+
+function copy_build_script {
+       #echo $PWD
+       echo "Copying build-librsvg.sh to $SYS folder"
+       cp $PWD/build-librsvg.sh $SYS/
+}
+
+#Package librsvg for inclusion in the Docker image
+function package_librsvg {
+       echo "Packaging Librsvg"
+
+       if [[ ! -f "$SYS/librsvg.tar.gz" ]]
+       then
+               if [[ $INT == true ]]
+               then
+                       read -p "Making a copy, then running make clean and packaging Librsvg, press any key 
to continue" -n1 -s
+               fi
+
+               mkdir $TMPDIR
+               echo "Copying librsvg to $TMPDIR"
+               cp -r $LIBDIR/. $TMPDIR
+               cd $TMPDIR
+
+               #Run autogen, this prepares librsvg for building, and allows make clean to be ran
+               ./autogen.sh
+               #run make clean which makes the resulting tar much smaller.
+               make clean
+               cd $DIR
+               tar -cvzf $SYS/librsvg.tar.gz -C $TMPDIR . --xform='s!^\./!!'
+       fi
+
+       if [[ $REPACKAGE == true ]]
+       then
+               echo "Repackaging Librsvg"
+               mkdir $TMPDIR
+               echo "Copying librsvg to $TMPDIR"
+               cp -r $LIBDIR/. $TMPDIR
+               cd $TMPDIR
+
+               #Run autogen, this prepares librsvg for building, and allows make clean to be ran
+               ./autogen.sh
+               #run make clean which makes the resulting tar much smaller.
+               make clean
+               cd $DIR
+               tar -cvzf $SYS/librsvg.tar.gz -C $TMPDIR . --xform='s!^\./!!'
+       fi
+}
+
+#build the base image, this contains the dependencies for librsvg to be built, and is used to build the 
system image
+function build_base_image {
+       sudo docker build -t librsvg/librsvg-base-$SYS -f librsvg-base/$SYS/Dockerfile librsvg-base/$SYS/.    
  
+}
+
+#build the system image, this is the image which librsvg goes into and is built with
+function build_system_image {
+       sudo docker build -t librsvg/librsvg-$SYS -f $SYS/Dockerfile $SYS/.
+}
+
+#removes the system image and rebuilds it, this doesn't touch the system images
+function rebuild_docker {
+       echo "removing old image"
+       sudo docker rmi librsvg/librsvg-$SYS
+       sudo docker build -t librsvg/librsvg-$SYS --no-cache -f $SYS/Dockerfile $SYS/.
+}
+
+#Build the docker image, using $SYS and $LIBDIR to determine where and what library
+function build_docker {
+       if [[ $REBUILD == false ]]
+       then
+               if [[ $INT == true ]]
+               then
+                       read -p "Building Docker with cache and settings $SYS, $LIBDIR Press any key to 
continue" -n1 -s
+               fi
+               echo "Building Docker System $SYS with cache"
+               build_system_image
+       else
+               if [[ $INT == true ]]
+               then
+                       read -p "Rebuilding Docker with settings $SYS, $LIBDIR Press any key to continue" -n1 
-s
+               fi
+
+               rebuild_docker
+       fi
+}
+
+#removes the designated system image
+function remove_system_image {
+       echo "removing system image librsvg-base-$SYS"
+       sudo docker rmi librsvg/librsvg-base-$SYS
+}
+
+function remove_librsvg_image {
+       echo "removing librsvg image librsvg-$SYS"
+       sudo docker rmi librsvg/librsvg-$SYS
+}
+
+function cleanup {
+       if [[ $CLEANUP == true ]]
+       then
+               confirm
+               SYS=opensuse
+               remove_librsvg_image
+               remove_system_image
+               rm $SYS/librsvg.tar.gz
+               rm $SYS/build-librsvg.sh
+               SYS=fedora
+               remove_librsvg_image
+               remove_system_image
+               rm $SYS/librsvg.tar.gz
+               rm $SYS/build-librsvg.sh
+               SYS=debian
+               emove_librsvg_image
+               remove_system_image
+               rm $SYS/librsvg.tar.gz
+               rm $SYS/build-rsvg.sh
+               exit 0
+       fi
+       
+}
+
+function confirm {
+       echo "Are you sure? This will remove all Docker images and the packaged librsvg.tar.gz"
+       select yn in "Yes" "No"; do
+       case $yn in
+           Yes ) break;;
+           No ) exit 1;;
+               esac
+       done
+}
+
+#runs the built docker image, this runs build_librsvg.sh automatically attached to the console
+function run_docker {
+       sudo docker run -it librsvg/librsvg-$SYS
+}
+
+function check_dir {
+       echo "Checking if $LIBDIR exists"
+       if [[ ! -d "$LIBDIR" ]]
+       then
+               echo "$LIBDIR does not exist, exiting"
+               exit 2
+       fi
+       
+       if [[ $LIBDIR == */ ]]
+       then
+               echo "Directory is good!"
+       else
+               echo "Directory missing last /, adding"
+               LIBDIR+="/"
+       fi
+       
+       DIR=$PWD
+}
+
+function check_system {
+       echo "Checking what system $SYSTEM is"
+       if [[ $SYSTEM == "fedora" ]]
+       then
+               echo "Fedora"
+               SYS="fedora"
+       elif [[ $SYSTEM == "Fedora" ]]
+       then
+               echo "Fedora"
+               SYS="fedora"
+       elif [[ $SYSTEM == "opensuse" ]]
+       then
+               echo "OpenSUSE"
+               SYS="opensuse"
+       elif [[ $SYSTEM == "OpenSUSE" ]]
+       then
+               echo "OpenSUSE"
+               SYS="opensuse"
+       elif [[ $SYSTEM == "Debian" ]]
+       then
+               echo "Debian"
+               SYS="debian"
+       elif [[ $SYSTEM == "debian" ]]
+       then
+               echo "Debian"
+               SYS="debian"
+       else 
+               echo "Wrong system selected, must be fedora, opensuse, or debian"
+               echo $flag
+               exit 2
+       fi
+}
+
+if [[ ${#} -eq 0 ]]; then
+   usage
+   exit 1
+fi
+
+while getopts "d:s:irpt:ch" flag; do
+       case "${flag}" in
+               d) LIBDIR=${OPTARG};;
+               s) SYSTEM=${OPTARG};;
+               i) INT=true;;
+               r) REBUILD=true; echo "Rebuilding";;
+               p) REPACKAGE=true; echo "Repackaging";;
+               t) TMPDIR=${OPTARG};;
+               c) CLEANUP=true;;
+               h) usage; exit 0;;
+               ?) usage; echo "Error: $flag"; exit 1;;
+       esac
+done
+
+# Runs the script then cleans up (if there's write permissions, which there should be)
+function main {
+       cleanup
+       check_dir
+       check_system
+       copy_build_script
+       package_librsvg
+       build_base_image
+       build_docker
+       run_docker
+
+       if [[ $INT == true ]]
+       then
+               read -p "Tests finished, press any key to exit" -n1 -s
+               exit 0
+       fi
+
+       echo "Tests finished, exiting"
+       exit 0
+}
+
+main
\ No newline at end of file
diff --git a/tools/docker/fedora/Dockerfile b/tools/docker/fedora/Dockerfile
new file mode 100644
index 00000000..51f82b6b
--- /dev/null
+++ b/tools/docker/fedora/Dockerfile
@@ -0,0 +1,5 @@
+FROM librsvg/librsvg-base-fedora
+MAINTAINER librsvg
+ADD librsvg.tar.gz /tmp/librsvg/
+ADD build-librsvg.sh /tmp/librsvg/
+CMD ["bash","/tmp/librsvg/build-librsvg.sh"]
diff --git a/tools/docker/librsvg-base/debian/Dockerfile b/tools/docker/librsvg-base/debian/Dockerfile
new file mode 100644
index 00000000..bfe91add
--- /dev/null
+++ b/tools/docker/librsvg-base/debian/Dockerfile
@@ -0,0 +1,6 @@
+FROM debian:testing
+MAINTAINER librsvg
+RUN apt-get update && apt-get install -y gcc make rustc cargo \
+automake autoconf libtool gtk-doc-tools git \
+libgdk-pixbuf2.0-dev libgirepository1.0-dev \
+libxml2-dev libcairo2-dev libpango1.0-dev
\ No newline at end of file
diff --git a/tools/docker/librsvg-base/fedora/Dockerfile b/tools/docker/librsvg-base/fedora/Dockerfile
new file mode 100644
index 00000000..fd526ba4
--- /dev/null
+++ b/tools/docker/librsvg-base/fedora/Dockerfile
@@ -0,0 +1,6 @@
+FROM fedora
+MAINTAINER librsvg
+RUN dnf update && dnf install -y gcc rust rust-std-static cargo make \
+automake autoconf libtool gtk-doc git redhat-rpm-config \
+gdk-pixbuf2-devel gobject-introspection-devel \
+libxml2-devel cairo-devel cairo-gobject-devel pango-devel
diff --git a/tools/docker/librsvg-base/opensuse/Dockerfile b/tools/docker/librsvg-base/opensuse/Dockerfile
new file mode 100644
index 00000000..1d5d2f2f
--- /dev/null
+++ b/tools/docker/librsvg-base/opensuse/Dockerfile
@@ -0,0 +1,6 @@
+FROM opensuse/tumbleweed
+MAINTAINER librsvg
+RUN zypper refresh && zypper install -y gcc rust rust-std cargo make \
+automake autoconf libtool gtk-doc git \
+gdk-pixbuf-devel gobject-introspection-devel \
+libxml2-devel cairo-devel pango-devel
diff --git a/tools/docker/opensuse/Dockerfile b/tools/docker/opensuse/Dockerfile
new file mode 100644
index 00000000..83bc68b5
--- /dev/null
+++ b/tools/docker/opensuse/Dockerfile
@@ -0,0 +1,5 @@
+FROM librsvg/librsvg-base-opensuse
+MAINTAINER librsvg
+ADD librsvg.tar.gz /tmp/librsvg/
+ADD build-librsvg.sh /tmp/librsvg/
+CMD ["bash","/tmp/librsvg/build-librsvg.sh"]


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