From befc6457051c914d3b0328d60d2e9e50ee2594ca Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Tue, 11 Nov 2025 10:24:56 +0000 Subject: [PATCH] DB: Added initial DB testing docker-based script --- dev/docker/db-testing/Dockerfile | 30 +++++++++++++++++++ dev/docker/db-testing/run.sh | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 dev/docker/db-testing/Dockerfile create mode 100755 dev/docker/db-testing/run.sh diff --git a/dev/docker/db-testing/Dockerfile b/dev/docker/db-testing/Dockerfile new file mode 100644 index 000000000..69b07a2b5 --- /dev/null +++ b/dev/docker/db-testing/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:24.04 + +# Install additional dependencies +RUN apt-get update && \ + apt-get install -y \ + git \ + wget \ + zip \ + unzip \ + php \ + php-bcmath php-curl php-mbstring php-gd php-xml php-zip php-mysql php-ldap \ + && \ + rm -rf /var/lib/apt/lists/* + +# Take branch as an argument so we can choose which BookStack +# branch to test against +ARG BRANCH=development + +# Download BookStack & install PHP deps +RUN mkdir -p /var/www && \ + git clone https://github.com/bookstackapp/bookstack.git --branch "$BRANCH" --single-branch /var/www/bookstack && \ + cd /var/www/bookstack && \ + wget https://raw.githubusercontent.com/composer/getcomposer.org/f3108f64b4e1c1ce6eb462b159956461592b3e3e/web/installer -O - -q | php -- --quiet --filename=composer && \ + php composer install + +# Set the BookStack dir as the default working dir +WORKDIR /var/www/bookstack + +# Set the default action as running php +ENTRYPOINT ["/bin/php"] diff --git a/dev/docker/db-testing/run.sh b/dev/docker/db-testing/run.sh new file mode 100755 index 000000000..f9944f8e4 --- /dev/null +++ b/dev/docker/db-testing/run.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +BRANCH=${1:-development} + +# Build the container with a known name +docker build --build-arg BRANCH="$BRANCH" -t bookstack:db-testing . + +# List of database containers to test against +containers=( + mysql:5.7 + mysql:8.0 + mysql:8.4 + mysql:9.5 + mariadb:10.2 + mariadb:10.6 + mariadb:10.11 + mariadb:11.4 + mariadb:11.8 + mariadb:12.0 +) + +# Pre-clean-up from prior runs +docker stop bs-dbtest-db +docker 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" \ + -e MYSQL_DATABASE=bookstack-test -e MYSQL_USER=bookstack -e MYSQL_PASSWORD=bookstack -e MYSQL_ROOT_PASSWORD=password \ + --network=bs-dbtest-net \ + "$img" + sleep 10 + 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 artisan migrate --force --database=mysql_testing + $APP_RUN artisan db:seed --force --class=DummyContentSeeder --database=mysql_testing + $APP_RUN vendor/bin/phpunit + if [ $? -eq 0 ]; then + echo "$img - Success" + else + echo "$img - Error" + read -p "Stop script? [y/N] " ans + [[ $ans == [yY] ]] && exit 0 + fi + + docker stop "bs-dbtest-db" + docker network rm bs-dbtest-net +done +