diff --git a/dev/docker/db-testing/Dockerfile b/dev/docker/db-testing/Containerfile similarity index 100% rename from dev/docker/db-testing/Dockerfile rename to dev/docker/db-testing/Containerfile diff --git a/dev/docker/db-testing/readme.md b/dev/docker/db-testing/readme.md index 89892408e..3e3261eb3 100644 --- a/dev/docker/db-testing/readme.md +++ b/dev/docker/db-testing/readme.md @@ -1,6 +1,6 @@ # Database Testing Suite -This docker setup is designed to run BookStack's test suite against each major database version we support +This container setup is designed to run BookStack's test suite against each major database version we support across MySQL and MariaDB to ensure compatibility and highlight any potential issues before a release. This is a fairly slow and heavy process, so is designed to just be run manually before a release which makes changes to the database schema, or a release which makes significant changes to database queries. @@ -10,7 +10,8 @@ makes changes to the database schema, or a release which makes significant chang Everything is ran via the `run.sh` script. This will: - Optionally, accept a branch of BookStack to use for testing. -- Build the docker image from the `Dockerfile`. +- Use podman if available, otherwise fall back to docker. +- Build the container image from the `Containerfile`. - This will include a built-in copy of the chosen BookStack branch. - Cycle through each major supported database version: - Migrate and seed the database. @@ -29,4 +30,7 @@ cd dev/docker/db-testing # Run for a specific branch ./run.sh v25-11 + +# Run, but skip the build step +./run.sh --skip-build ``` diff --git a/dev/docker/db-testing/run.sh b/dev/docker/db-testing/run.sh index fe6ee4508..a0c2a3bc5 100755 --- a/dev/docker/db-testing/run.sh +++ b/dev/docker/db-testing/run.sh @@ -1,35 +1,62 @@ #!/bin/bash -BRANCH=${1:-development} +BRANCH=development +SKIP_BUILD=0 + +# Parse arguments: --skip-build, plus an optional branch name +for arg in "$@"; do + case "$arg" in + --skip-build) + SKIP_BUILD=1 + ;; + *) + BRANCH="$arg" + ;; + esac +done + +# Use podman if available, otherwise fall back to docker +if command -v podman >/dev/null 2>&1; then + ENGINE=podman +elif command -v docker >/dev/null 2>&1; then + ENGINE=docker +else + echo "Failed to find podman or docker in PATH" + exit 1 +fi # Build the container with a known name -docker build --no-cache --build-arg BRANCH="$BRANCH" -t bookstack:db-testing . -if [ $? -eq 1 ]; then - echo "Failed to build app container for testing" - exit 1 +if [ "$SKIP_BUILD" -eq 1 ]; then + echo "Skipping app container build" +else + $ENGINE build --no-cache --build-arg BRANCH="$BRANCH" -t bookstack:db-testing . + if [ $? -ne 0 ]; then + echo "Failed to build app container for testing" + exit 1 + fi fi # List of database containers to test against containers=( - "mysql:8.0" - "mysql:8.4" - "mysql:9.5" - "mariadb:10.6" - "mariadb:10.11" - "mariadb:11.4" - "mariadb:11.8" - "mariadb:12.0" + "docker.io/library/mysql:8.0" + "docker.io/library/mysql:8.4" + "docker.io/library/mysql:9.5" + "docker.io/library/mariadb:10.6" + "docker.io/library/mariadb:10.11" + "docker.io/library/mariadb:11.4" + "docker.io/library/mariadb:11.8" + "docker.io/library/mariadb:12.0" ) # Pre-clean-up from prior runs -docker stop bs-dbtest-db -docker network rm bs-dbtest-net +$ENGINE stop bs-dbtest-db +$ENGINE network rm bs-dbtest-net # Cycle over each database image for img in "${containers[@]}"; do echo "Starting tests with $img..." - docker network create bs-dbtest-net - docker run -d --rm --name "bs-dbtest-db" \ + $ENGINE network create bs-dbtest-net + $ENGINE run -d --rm --name "bs-dbtest-db" \ -e MYSQL_DATABASE=bookstack-test \ -e MYSQL_USER=bookstack \ -e MYSQL_PASSWORD=bookstack \ @@ -37,7 +64,7 @@ for img in "${containers[@]}"; do --network=bs-dbtest-net \ "$img" sleep 20 - APP_RUN='docker run -it --rm --network=bs-dbtest-net -e TEST_DATABASE_URL="mysql://bookstack:bookstack@bs-dbtest-db:3306" bookstack:db-testing' + APP_RUN="$ENGINE run -it --rm --network=bs-dbtest-net -e TEST_DATABASE_URL=\"mysql://bookstack:bookstack@bs-dbtest-db:3306\" bookstack:db-testing" $APP_RUN artisan migrate --force --database=mysql_testing $APP_RUN artisan db:seed --force --class=DummyContentSeeder --database=mysql_testing $APP_RUN vendor/bin/phpunit @@ -49,7 +76,6 @@ for img in "${containers[@]}"; do [[ $ans == [yY] ]] && exit 0 fi - docker stop "bs-dbtest-db" - docker network rm bs-dbtest-net + $ENGINE stop "bs-dbtest-db" + $ENGINE network rm bs-dbtest-net done -