| 1 | # Librsvg Docker Tests |
| 2 | |
| 3 | Run the librsvg test suite inside a docker container. The Librsvg CI runs on |
| 4 | opensuse, so this is a simpler way to run the test suite locally on the same |
| 5 | packages that are used by the Gitlab integration. |
| 6 | |
| 7 | Docker requires root for nearly all of its commands so the script will ask for |
| 8 | root. |
| 9 | |
| 10 | ## Usage |
| 11 | |
| 12 | ```text |
| 13 | 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 it) |
| 14 | |
| 15 | Use -d [DIRECTORY] pointing at your librsvg Directory |
| 16 | Use -s [SYSTEM] to determine what docker container to use (Fedora, OpenSUSE, Debian) |
| 17 | Use -h to return this Help |
| 18 | Use -i to have it Interactively pause periodically to check output (the cleanup scripts is always interactive unless -y is passed) |
| 19 | Use -p to recoPy the librsvg library folder to the tmp directory, removing everything that is there, useful for cleaning the cargo cache |
| 20 | Use -r to Rebuild the build dependencies docker image forcefully |
| 21 | Use -t to specify a Temporary directory (default: /tmp/librsvg) |
| 22 | Use -y to answer Yes to any prompts (This currently only includes the cleanup scripts) |
| 23 | Use -c to Cleanup ALL related docker images (this will not run the test suite) |
| 24 | ``` |
| 25 | |
| 26 | ### Example |
| 27 | |
| 28 | If the librsvg folder is in your home directory, run this from your home |
| 29 | directory: |
| 30 | |
| 31 | ```bash |
| 32 | ~/librsvg/tools/docker/docker-test.sh -d ~/librsvg -s opensuse -i |
| 33 | ``` |
| 34 | |
| 35 | This will run it pointing at `/home/Username/librsvg` (-d) with opensuse |
| 36 | tumbleweed docker image (-s), and interactive (-i), meaning it pauses and has |
| 37 | the user input a keystroke before continuing, useful for debugging or catching |
| 38 | typos. |
| 39 | |
| 40 | The first run will take some time as Docker downloads and installs the system, |
| 41 | updates the packages, and installs the build requirements, but it's set up so |
| 42 | that it won't re-download the system image each time, which takes more disk |
| 43 | space but saves on bandwidth. |
| 44 | |
| 45 | After the tests run, the links to rendered files in your terminal (in the case |
| 46 | that there are errors) will point to the `/tmp/librsvg` directory, so in some |
| 47 | terminals these links can be clicked on to view the files, otherwise the build |
| 48 | is found in that folder, and can be accessed from the host system. |
| 49 | |
| 50 | What I use, from the librsvg directory: |
| 51 | |
| 52 | ```sh |
| 53 | ./tools/docker/docker-test.sh -s opensuse |
| 54 | ``` |
| 55 | |
| 56 | This passes through the current directory (in this case the librsvg folder, as |
| 57 | cloned from git) and runs the test suite in OpenSUSE |
| 58 | |
| 59 | ### Cleanup |
| 60 | |
| 61 | To do a full cleanup of the docker images: |
| 62 | |
| 63 | ```sh |
| 64 | ./docker-test.sh -c |
| 65 | ``` |
| 66 | |
| 67 | This requires user input. |
| 68 | |
| 69 | This asks if it should also clear out the tmp directory passed to it, or the |
| 70 | default one. It checks if `/` is passed to it, so it shouldn't delete your |
| 71 | system. If you answer "no" to clearing out the tmp directory, those files will |
| 72 | not be deleted. |
| 73 | |
| 74 | Dangerous: pass -y if using this where user input cannot be provided, but it |
| 75 | will delete **all** docker images and the contents of `/tmp/librsvg` (if `-t` is |
| 76 | not passed, otherwise that directory) without warning. It will not touch the |
| 77 | actual librsvg library directory. |
| 78 | |
| 79 | ### Helpful Docker Commands |
| 80 | |
| 81 | ```sh |
| 82 | docker image prune |
| 83 | docker container prune |
| 84 | ``` |
| 85 | |
| 86 | This removes any dangling (not attached to an tagged image) docker images and |
| 87 | containers. I would recommend running it once in a while, or you may end up with |
| 88 | 100gb of docker containers like me, don't be like me. (disclaimer: I have also |
| 89 | been testing all of this so there's been a lot of mishaps and learning) |
| 90 | |
| 91 | This tool should use ~3gb of disk space for running the tests with the opensuse |
| 92 | image alone. If all 3 systems are tested, the disk usage goes up to ~9gb |
| 93 | |
| 94 | See your disk usage with: |
| 95 | |
| 96 | ```sh |
| 97 | docker system df |
| 98 | ``` |
| 99 | |
| 100 | ### I want to add more OS's to test, how do I do that? |
| 101 | |
| 102 | To add a new OS clone one of the `tools/docker/librsvg-base` folders, renaming |
| 103 | it to the OS you wish to add, eg. If I wanted to test Alpine, I would rename the |
| 104 | folder to "alpine" all lower case, one word, to make things easy. |
| 105 | |
| 106 | Then, go to |
| 107 | [Docker Hub](https://hub.docker.com/search?q=&type=image&category=os) and find |
| 108 | the OS you wish to add along with the version tag for it, for the alpine example |
| 109 | that's `alpine:latest` and put that in the `FROM` portion of the Dockerfile. |
| 110 | |
| 111 | LABEL can remain how it is. |
| 112 | |
| 113 | Finally `RUN` needs to be filled in with the package manager command to install |
| 114 | the dependencies to build Librsvg. See [COMPILING.md](../../COMPILING.md) for |
| 115 | build dependencies, the other Dockerfiles can help here. Essentially it's just |
| 116 | looking up what the packages are called on your OS of choice. |
| 117 | |
| 118 | Once you have that out of he way, [docker-test.sh](docker-test.sh) will need a |
| 119 | couple edits to be able to build. First, inside the `check_system` function copy |
| 120 | one of the `elif [[ $SYSTEM == "" ]]` and put it before the `else` at the bottom |
| 121 | of that function. Add your system name inside there, copying the style of inside |
| 122 | of the other `elif` statements. |
| 123 | |
| 124 | Then, in `cleanup` copy one of the `SYS= ... clean_base_image` lines and change |
| 125 | the `SYS` to your OS. |
| 126 | |
| 127 | Finally go to `clean_distro_image` and copy one of the `docker rmi --force` |
| 128 | lines, filling in your OS at the end. |
| 129 | |
| 130 | You're done! Now running the script with `./docker-test.sh -s youros` will use |
| 131 | your OS, setting the docker images, base image, and everything else correctly! |
| 132 | |
| 133 | ## How does this tool work? |
| 134 | |
| 135 | See the docker-test.sh file for the script itself, below is the architecture of |
| 136 | the script. The dockerfiles in the debian/fedora/opensuse folders have the build |
| 137 | dependency install commands that are used to build each of the base images. |
| 138 | |
| 139 | ```text |
| 140 | ┌─────────────────────────────────────────────────────┐ |
| 141 | |main │ |
| 142 | | This function runs the following functions one at a | |
| 143 | | time: | |
| 144 | │ check_docker: This makes sure docker is installed | |
| 145 | | cleanup │ |
| 146 | │ check_dir │ |
| 147 | │ check_system │ |
| 148 | │ build_base_system │ |
| 149 | │ prepare_librsvg │ |
| 150 | │ run_docker │ |
| 151 | | It's found at the bottom of the script, and pauses | |
| 152 | | after everything finishes if -i is passed | |
| 153 | └─────────────────────────────────────────────────────┘ |
| 154 | Cleanup │ |
| 155 | ▼ |
| 156 | ┌───────────────────────┐ ┌──────────────────────────────────────┐ |
| 157 | │cleanup │ ┌─˃│clean_base_image │ |
| 158 | │ If -c was passed │ │ │ Delete librsvg-$SYS-base docker image│ |
| 159 | │ Confirm with user │ │ └──────────────────────────────────────┘ |
| 160 | │ Set SYS to each system├──┘ ┌────────────────────────────────┐ ˄ |
| 161 | │ Confirm with user ────┼────˃|clean_distro_image │ | |
| 162 | │ Confirm with user ────┼──┐ | Delete all distro docker images│ | |
| 163 | └───────────────────────┘ │ │ Ie. debian, opensuse/tumbleweed│ | |
| 164 | Check path | │ └────────────────────────────────┘ | |
| 165 | ˅ │ ┌─────────────────────────────┐ | |
| 166 | ┌───────────────────────┐ └─˃│clean_tmp_dir │ | |
| 167 | │check_dir │ │ Check if $TMPDIR is "/" │ | |
| 168 | │ checks if $LIBDIR is | │ Delete tmp directory on host│ | |
| 169 | | passed with -d, if not| │ default: /tmp/librsvg │ | |
| 170 | | defaults to current | │ specity with -t │ | |
| 171 | | directory, then it | └─────────────────────────────┘ | |
| 172 | | checks for trailing / | ˄ | |
| 173 | │ in library directory, │ | | |
| 174 | │ if it doesn't exist │ | | |
| 175 | │ then it appends one. │ | | |
| 176 | │ This makes sure the │ | | |
| 177 | │ later commands don't | | | |
| 178 | | target the wrong │ | | |
| 179 | | directory. | | | |
| 180 | └───────────────────────┘ | | |
| 181 | Now the system │ | | |
| 182 | ˅ | | |
| 183 | ┌────────────────────────────────────────┐ | | |
| 184 | │check_system │ | | |
| 185 | │ this parses a few common spellings of │ | | |
| 186 | │ OpenSUSE, Fedora, and Debian │ | | |
| 187 | │ to set the $SYS variable to the correct│ | | |
| 188 | │ OS image. It's convenient to not care │ | | |
| 189 | │ about the difference between "OpenSUSE"│ | | |
| 190 | │ and "opensuse", there's probably a │ | | |
| 191 | | better way to do this | | | |
| 192 | └────────────────────────────────────────┘ | | |
| 193 | Build time! │ | | |
| 194 | ˅ | | |
| 195 | ┌────────────────────────────────────────┐ | | |
| 196 | │build_base_system | \ | |
| 197 | │ Builds the base docker image: if -r ───┼───────────────┼───────┘ |
| 198 | │ then image is rebuilt. If -r is not │ / |
| 199 | │ passed, then Docker reruns the │ | |
| 200 | │ Dockerfile command which updates the │ | |
| 201 | │ existing image using dnf/zypper/apt │ | |
| 202 | └────────────────────────────────────────┘ | |
| 203 | Preparations │ | |
| 204 | ˅ | |
| 205 | ┌──────────────────────────────────────────────────────┐| |
| 206 | │prepare_librsvg || |
| 207 | | If -p ───────────────────────────────────────────────┼┘ |
| 208 | │ Then creates $TMPDIR if it doesn't exist. | |
| 209 | | Prepares librsvg, copying it to $TMPDIR, using Rsync │ |
| 210 | │ to exclude the git and target folders. │ |
| 211 | │ It then runs autogen in $TMPDIR to prepare for │ |
| 212 | │ building │ |
| 213 | └──────────────────────────────────────────────────────┘ |
| 214 | Run Docker | |
| 215 | ˅ |
| 216 | ┌──────────────────────────────────────────────────────┐ |
| 217 | │run_docker | |
| 218 | │ Runs the docker container with this command: | |
| 219 | │ sudo docker run --name librsvg-$SYS-test \ | |
| 220 | | -v $TMPDIR:$TMPDIR -w $TMPDIR -t --rm \ | |
| 221 | | librsvg/librsvg-$SYS-base cargo test | |
| 222 | | | |
| 223 | | --name runs the docker container with name │ |
| 224 | │ librsvg-$SYS-test ex: librsvg-opensuse-test │ |
| 225 | | | |
| 226 | │ -v $TMPDIR:$TMPDIR passes through $TMPDIR on the host│ |
| 227 | │ to $TMPDIR inside the container ex: /tmp/librsvg │ |
| 228 | | | |
| 229 | │ -w $TMPDIR sets the working directory to $TMPDIR │ |
| 230 | | inside the container | |
| 231 | | | |
| 232 | | -t binds the container's console to the current one | |
| 233 | | | |
| 234 | | -rm sets the generated image to self-destruct after | |
| 235 | | all processes exit | |
| 236 | | | |
| 237 | | cargo test runs cargo test inside the container | |
| 238 | └──────────────────────────────────────────────────────┘ |
| 239 | |
| 240 | ``` |