[librsvg: 6/7] Pass through temp directory, clean up images Now this uses a docker-run command to run the docker co




commit dab1044f011156c6f7340857c465781a700126dc
Author: Madds H <madds hollandart io>
Date:   Tue Aug 24 15:13:07 2021 -0500

    Pass through temp directory, clean up images
    Now this uses a docker-run command to run the docker container
    Any rendered files can now be accessed in the temp directory on the host
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/579>

 tools/docker/README.md           |  22 ++--
 tools/docker/build-librsvg.sh    |   4 -
 tools/docker/debian/Dockerfile   |   5 -
 tools/docker/docker-test.sh      | 270 +++++++++++++++++++++------------------
 tools/docker/fedora/Dockerfile   |   5 -
 tools/docker/opensuse/Dockerfile |   5 -
 6 files changed, 163 insertions(+), 148 deletions(-)
---
diff --git a/tools/docker/README.md b/tools/docker/README.md
index bce12ac6..d750981a 100644
--- a/tools/docker/README.md
+++ b/tools/docker/README.md
@@ -10,23 +10,29 @@ Docker requires root for nearly all of its commands so the script will ask for r
 ```
 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)
+Use -d [DIRECTORY] pointing at your librsvg Directory
+Use -s [SYSTEM] to determine what docker container to use (Fedora, OpenSUSE, Debian)
+Use -h to return this Help
+Use -i to have it Interactively pause periodically to check output (the cleanup scripts is always 
interactive unless -y is passed)
+Use -p to recoPy the librsvg library folder to the tmp directory, removing everything that is there, useful 
for cleaning the cargo cache
+Use -r to Rebuild the build dependencies docker image forcefully
+Use -t to specify a Temporary directory (default: /tmp/librsvg)
+Use -y to answer Yes to any prompts (This currently only includes the cleanup scripts)
+Use -c to Cleanup ALL related docker images (this will not run the test suite)
 ```
 
 ### Example:
 ```
 If the librsvg folder is in your home directory:
-./docker-test.sh -d ~/librsvg -s opensuse -i 
+~/librsvg/tools/docker/docker-test.sh -d ~/librsvg -s opensuse -i 
 
 This will run it pointing at /home/Username/librsvg (-d) with opensuse tumbleweed docker image (-s), and 
interactive (-i), meaning it pauses and has the user input a keystroke before continuing, useful for 
debugging or catching typos. 
 
 The first run will take some time as Docker downloads and installs the system, updates the packages, and 
installs the build requirements, but it's set up so that it won't re-download the system image each time, 
which takes more disk space but saves on bandwidth.
+
+What I use, from the librsvg directory:
+
+tools/docker/docker-test.sh -s opensuse
 ```
 
 
diff --git a/tools/docker/docker-test.sh b/tools/docker/docker-test.sh
index c4fc6dc5..32e5c2dd 100755
--- a/tools/docker/docker-test.sh
+++ b/tools/docker/docker-test.sh
@@ -5,7 +5,13 @@ SYS="no"
 REBUILD=false
 DIR=no
 TMPDIR=/tmp/librsvg
+
+YES=false
+
 CLEANUP=false
+RMDISTRO=false
+RMSYSTEMIMG=false
+RMTMP=false
 
 function usage {
         echo "This tool lets you run Librsvg's test suite under a couple different"
@@ -13,52 +19,56 @@ function usage {
         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 -i to have it Interactively pause periodically to check output (the cleanup scripts is 
always interactive unless -y is passed)"
+        echo "Use -p to recoPy the librsvg library folder to the tmp directory, removing everything that is 
there, useful for cleaning the cargo cache"        
+               echo "Use -r to Rebuild the build dependencies docker image forcefully"
                echo "Use -t to specify a Temporary directory (default: /tmp/librsvg)"
+               echo "Use -y to answer Yes to any prompts (This currently only includes the cleanup scripts)"
                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 prepare_librsvg {
-       echo "Packaging Librsvg"
+       echo "Preparing Librsvg"
 
-       if [[ ! -f "$SYS/librsvg.tar.gz" ]]
-       then
-               if [[ $REPACKAGE == false ]] 
+       if [[ $REPACKAGE == false ]] 
                then
                        if [[ $INT == true ]]
                        then
                                read -p "Making a copy, then running make clean and packaging Librsvg, press 
any key to continue" -n1 -s
+                               echo " "
                        fi
 
                        mkdir $TMPDIR
                        echo "Copying librsvg to $TMPDIR"
                        rsync -av --exclude '.git' --exclude 'target' $LIBDIR/ $TMPDIR/
+
                        #Uncomment this line if your distro doesn't have rsync, it'll make a lot of text when 
copying the git folder, but works
                        #cp -r $LIBDIR/. $TMPDIR 
                        cd $TMPDIR
 
+                       if [[ $INT == true ]]
+                       then
+                               read -p "Running autogen to prepare for building in $TMPDIR, then running 
make clean, press any key to continue" -n1 -s
+                               echo " "
+                       fi
+
                        #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!^\./!!'
+       else
+               echo "Recopying Librsvg"
+               if [[ ! -d "$TMPDIR" ]] 
+               then
+                       echo "$TMPDIR does not exist, creating"
+                       mkdir $TMPDIR
+               else
+                       echo "Erasing $TMPDIR and recreating"
+                       clean_tmp_dir
+                       mkdir $TMPDIR
                fi
-       fi
 
-       if [[ $REPACKAGE == true ]]
-       then
-               echo "Repackaging Librsvg"
-               mkdir $TMPDIR
                echo "Copying librsvg to $TMPDIR"
                rsync -av --exclude '.git' --exclude 'target' $LIBDIR/ $TMPDIR/
 
@@ -66,154 +76,173 @@ function prepare_librsvg {
                #cp -r $LIBDIR/. $TMPDIR
                cd $TMPDIR
 
+               if [[ $INT == true ]]
+               then
+                       read -p "Running autogen to prepare for building in $TMPDIR, then running make clean, 
press any key to continue" -n1 -s
+                       echo " "
+               fi
+
                #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.
+               #run make clean to clean up the folder
                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/.    
  
+       fi      
 }
 
-#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/.
+function confirm {
+       if [[ $YES == false ]] 
+       then
+               echo "Would you like to remove the librsvg docker image with the build dependencies (it will 
take a while to rebuild if removed)"
+               select yn in "Yes" "No"; do
+               case $yn in
+                   Yes ) RMSYSTEMIMG=true;;
+                   No ) RMSYSTEMIMG=false;;
+                       esac
+               done
+               echo " "
+       fi
 }
 
-#removes the system image and rebuilds it, this doesn't touch the system images
-function rebuild_docker {
-       echo "removing old image"
-       sudo docker rmi --force librsvg/librsvg-$SYS
-       sudo docker build -t librsvg/librsvg-$SYS --no-cache -f $SYS/Dockerfile $SYS/.
+function confirm_rm_dir {
+       if [[ $YES == false ]] 
+       then
+               echo "Would you like to remove the librsvg files from the tmp directory: $TMPDIR"
+               select yn in "Yes" "No"; do
+               case $yn in
+                   Yes ) RMTMP=true;;
+                   No ) RMTMP=false;;
+                       esac
+               done
+               echo " "
+       fi
 }
 
-#Build the docker image, using $SYS and $LIBDIR to determine where and what library
-function build_docker {
-       if [[ $REBUILD == false ]]
+function confirm_rm_distro {
+       if [[ $YES == false ]] 
        then
-               if [[ $INT == true ]]
+               echo "Would you like to remove the base docker system images ie. opensuse (do this if you 
don't plan to build librsvg with this tool in the future, otherwise keep them, it takes a while to build)"
+               select yn in "Yes" "No"; do
+               case $yn in
+                   Yes ) RMDISTROIMG=true;;
+                   No ) RMDISTROIMG=false;;
+                       esac
+               done
+               echo " "
+       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 {
+
+       if [[ $REBUILD == 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
+                       then
+                               read -p "Rebuilding the Librsvg build dependencies docker container, this 
will take a moment" -n1 -s
+                               echo " "
                fi
 
-               rebuild_docker
+               clean_base_image
+               sudo docker build -t librsvg/librsvg-$SYS-base -f tools/docker/librsvg-base/$SYS/Dockerfile 
tools/docker/librsvg-base/$SYS/.    
+
        fi
-}
 
-#removes the designated system image
-function remove_system_image {
-       echo "removing system image librsvg-base-$SYS"
-       sudo docker rmi --force librsvg/librsvg-base-$SYS
+       if [[ $INT == true ]]
+       then
+               read -p "Building the Librsvg build dependencies docker container, this will take a moment, 
press any key to continue" -n1 -s
+               echo " "
+       fi
+
+       sudo docker build -t librsvg/librsvg-$SYS-base -f tools/docker/librsvg-base/$SYS/Dockerfile 
tools/docker/librsvg-base/$SYS/.    
 }
 
-#removes the librsvg image
-function remove_librsvg_image {
-       echo "removing librsvg image librsvg-$SYS"
-       sudo docker rmi --force librsvg/librsvg-$SYS
+#removes the designated base system image
+function clean_base_image {
+       echo "removing system image librsvg-base-$SYS"
+       sudo docker rmi --force librsvg/librsvg-$SYS-base
 }
 
-function remove_distro_image {
+#removes distro images
+function clean_distro_image {
        echo "removing base system images"
        sudo docker rmi --force debian
        sudo docker rmi --force opensuse/tumbleweed
        sudo docker rmi --force fedora
 }
 
+function clean_tmp_dir {
+       if [[ "$TMPDIR" == "/" ]] 
+       then
+               echo "Tried to delete root, exiting"
+               exit 1
+       fi
+
+       if [[ ! -d "$TMPDIR" ]] 
+       then
+               echo "$TMPDIR does not exist, exiting"
+               exit 0
+       fi
+       echo "This requires sudo because the build is done with the docker image, so build files cannot be 
removed without it"
+       echo " "
+       if [[ $INT == true ]]
+       then
+               read -p "Pausing, press any key to continue, you may be asked for admin password in the next 
step" -n1 -s
+               echo " "
+       fi
+       sudo rm -rf $TMPDIR
+}
+
 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
-               remove_librsvg_image
-               remove_system_image
-               rm $SYS/librsvg.tar.gz
-               rm $SYS/build-rsvg.sh
 
-               confirm_rm_distro
-               remove_distro_image
-
-               confirm_rm_dir
-               if [[ "$TMPDIR" == "/" ]] 
+               if [ $RMSYSTEMIMG == "true" ]
                then
-                       echo "Tried to delete root, exiting"
-                       exit 1
+                       SYS=opensuse
+                       clean_base_image
+
+                       SYS=fedora
+                       clean_base_image
+
+                       SYS=debian
+                       clean_base_image
+
                fi
 
-               if [[ ! -d "$TMPDIR" ]] 
+               confirm_rm_distro
+               if [ $RMDISTROIMG == "true" ]
                then
-                       echo "$TMPDIR does not exist, exiting"
-                       exit 0
+                       clean_distro_image
                fi
-               rm -rf $TMPDIR
+               
+               confirm_rm_dir
+               if [ $RMTMP == "true" ]
+               then
+                       clean_tmp_dir
+               fi
+
+
 
                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
-}
-
-function confirm_rm_dir {
-       echo "Would you like to also remove the librsvg files from the tmp directory: $TMPDIR"
-       select yn in "Yes" "No"; do
-       case $yn in
-           Yes ) break;;
-           No ) exit 1;;
-               esac
-       done
-}
-
-function confirm_rm_distro {
-       echo "Would you like to remove the base system images ie. opensuse (do this if you don't plan to 
build librsvg with this tool in the future, otherwise keep them, it takes a while to build)"
-       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
+#runs the built docker image, this runs cargo check automatically attached to the console
 function run_docker {
-       sudo docker run -it librsvg/librsvg-$SYS
+       sudo docker run --name librsvg-$SYS-test -v /tmp/librsvg/:/tmp/librsvg/ -w /tmp/librsvg/ -t --rm 
librsvg/librsvg-$SYS-base cargo test 
 }
 
 function check_dir {
        echo "Checking if $LIBDIR exists"
        if [[ ! -d "$LIBDIR" ]]
        then
-               echo "$LIBDIR does not exist, exiting"
-               exit 2
+               echo "Library directory: '$LIBDIR' does not exist or isn't set, defaulting to current working 
directory"
+               LIBDIR=$PWD
        fi
        
        if [[ $LIBDIR == */ ]]
@@ -275,6 +304,7 @@ while getopts "d:s:irpt:ch" flag; do
                t) TMPDIR=${OPTARG};;
                c) CLEANUP=true;;
                h) usage; exit 0;;
+               y) YES=true;;
                ?) usage; echo "Error: $flag"; exit 1;;
        esac
 done
@@ -284,10 +314,8 @@ function main {
        cleanup
        check_dir
        check_system
-       copy_build_script
-       prepare_librsvg
        build_base_image
-       build_docker
+       prepare_librsvg
        run_docker
 
        if [[ $INT == true ]]


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