1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-10-23 06:49:01 +03:00

Testing: Updated db-testing container setup to work with Podman

Also added a way to skip building the image
This commit is contained in:
Dan Brown
2026-10-12 15:22:33 +01:00
parent 0cc24d2f22
commit f6b3dc6352
3 changed files with 53 additions and 23 deletions

View File

@@ -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
```

View File

@@ -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