fix(docker): modify db configuration for new tests

A user that can create databases is now required for tests,
we use the 'root' user in Docker.

Added docker services:
---------------------
- mariadb_test - host localhost:13307

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-17 00:44:35 -08:00
parent fa43f6bc3e
commit fa26c8078b
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
12 changed files with 53 additions and 79 deletions

View file

@ -5,7 +5,7 @@ socket = /var/run/mysqld/mysqld.sock
;port = 3306
name = AUR
user = aur
password = aur
;password = aur
[options]
username_min_len = 3

View file

@ -6,7 +6,8 @@
; development-specific options too.
[database]
; Options: mysql, sqlite.
; PHP options: mysql, sqlite.
; FastAPI options: mysql.
backend = mysql
; If using sqlite, set name to the database file path.
@ -14,8 +15,8 @@ name = aurweb
; MySQL database information. User defaults to root for containerized
; testing with mysqldb. This should be set to a non-root user.
user = aur
password = aur
user = root
;password = aur
host = localhost
;port = 3306
socket = /var/run/mysqld/mysqld.sock

View file

@ -77,6 +77,24 @@ services:
mariadb:
condition: service_healthy
mariadb_test:
# Test database.
image: aurweb:latest
init: true
environment:
- MARIADB_PRIVILEGED=1
entrypoint: /docker/mariadb-entrypoint.sh
command: /usr/bin/mysqld_safe --datadir=/var/lib/mysql
ports:
# This will expose mariadbd on 127.0.0.1:13307 in the host.
# Ex: `mysql -uaur -paur -h 127.0.0.1 -P 13306 aurweb`
- "13307:3306"
volumes:
- mariadb_test_run:/var/run/mysqld # Bind socket in this volume.
healthcheck:
test: "bash /docker/health/mariadb.sh"
interval: 3s
git:
image: aurweb:latest
init: true
@ -254,10 +272,9 @@ services:
stdin_open: true
tty: true
depends_on:
git:
mariadb_test:
condition: service_healthy
volumes:
- git_data:/aurweb/aur.git
- ./cache:/cache
- ./aurweb:/aurweb/aurweb
- ./migrations:/aurweb/migrations
@ -280,34 +297,12 @@ services:
stdin_open: true
tty: true
depends_on:
mariadb_init:
condition: service_started
mariadb_test:
condition: service_healthy
tmpfs:
- /tmp
volumes:
- mariadb_run:/var/run/mysqld
- git_data:/aurweb/aur.git
- ./cache:/cache
- ./aurweb:/aurweb/aurweb
- ./migrations:/aurweb/migrations
- ./test:/aurweb/test
- ./web/html:/aurweb/web/html
- ./web/template:/aurweb/web/template
- ./web/lib:/aurweb/web/lib
- ./templates:/aurweb/templates
pytest-sqlite:
image: aurweb:latest
profiles: ["dev"]
init: true
environment:
- AUR_CONFIG=conf/config.sqlite
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
entrypoint: /docker/test-sqlite-entrypoint.sh
command: setup-sqlite.sh run-pytests.sh clean
stdin_open: true
tty: true
volumes:
- git_data:/aurweb/aur.git
- mariadb_test_run:/var/run/mysqld
- ./cache:/cache
- ./aurweb:/aurweb/aurweb
- ./migrations:/aurweb/migrations
@ -325,16 +320,15 @@ services:
- AUR_CONFIG=conf/config
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
entrypoint: /docker/tests-entrypoint.sh
command: setup-sqlite.sh run-tests.sh
entrypoint: /docker/test-mysql-entrypoint.sh
command: /docker/scripts/run-tests.sh
stdin_open: true
tty: true
depends_on:
mariadb_init:
condition: service_started
mariadb_test:
condition: service_healthy
volumes:
- mariadb_run:/var/run/mysqld
- git_data:/aurweb/aur.git
- mariadb_test_run:/var/run/mysqld
- ./cache:/cache
- ./aurweb:/aurweb/aurweb
- ./migrations:/aurweb/migrations
@ -345,6 +339,7 @@ services:
- ./templates:/aurweb/templates
volumes:
mariadb_test_run: {}
mariadb_run: {} # Share /var/run/mysqld/mysqld.sock
mariadb_data: {} # Share /var/lib/mysql
git_data: {} # Share aurweb/aur.git

View file

@ -5,6 +5,10 @@ set -eou pipefail
cp -vf conf/config.dev conf/config
sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config
# Change database user/password.
sed -ri "s/^;?(user) = .*$/\1 = aur/" conf/config
sed -ri "s/^;?(password) = .*$/\1 = aur/" conf/config
sed -ri "s;^(aur_location) = .+;\1 = ${AURWEB_FASTAPI_PREFIX};" conf/config
# Setup Redis for FastAPI.

View file

@ -13,23 +13,18 @@ done
# Configure databases.
DATABASE="aurweb" # Persistent database for fastapi/php-fpm.
TEST_DB="aurweb_test" # Test database (ephemereal).
echo "Taking care of primary database '${DATABASE}'..."
mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'localhost' IDENTIFIED BY 'aur';"
mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'%' IDENTIFIED BY 'aur';"
mysql -u root -e "CREATE DATABASE IF NOT EXISTS $DATABASE;"
mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'localhost';"
mysql -u root -e "GRANT ALL ON ${DATABASE}.* TO 'aur'@'%';"
# Drop and create our test database.
echo "Dropping test database '$TEST_DB'..."
mysql -u root -e "DROP DATABASE IF EXISTS $TEST_DB;"
mysql -u root -e "CREATE DATABASE $TEST_DB;"
mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'localhost';"
mysql -u root -e "GRANT ALL ON ${TEST_DB}.* TO 'aur'@'%';"
mysql -u root -e "CREATE USER IF NOT EXISTS 'aur'@'%' IDENTIFIED BY 'aur';"
mysql -u root -e "GRANT ALL ON aurweb.* TO 'aur'@'localhost';"
mysql -u root -e "GRANT ALL ON aurweb.* TO 'aur'@'%';"
echo "Created new '$TEST_DB'!"
mysql -u root -e "CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY 'aur';"
mysql -u root -e "GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;"
mysqladmin -uroot shutdown

View file

@ -4,6 +4,8 @@ set -eou pipefail
# Setup a config for our mysql db.
cp -vf conf/config.dev conf/config
sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config
sed -ri "s/^;?(user) = .*$/\1 = aur/g" conf/config
sed -ri "s/^;?(password) = .*$/\1 = aur/g" conf/config
python -m aurweb.initdb 2>/dev/null || /bin/true

View file

@ -9,14 +9,19 @@ done
cp -vf conf/config.dev conf/config
sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config
sed -ri "s;^(aur_location) = .+;\1 = ${AURWEB_PHP_PREFIX};" conf/config
# Change database user/password.
sed -ri "s/^;?(user) = .*$/\1 = aur/" conf/config
sed -ri "s/^;?(password) = .*$/\1 = aur/" conf/config
# Enable memcached.
sed -ri 's/^(cache) = .+$/\1 = memcache/' conf/config
# Setup various location configurations.
sed -ri "s;^(aur_location) = .+;\1 = ${AURWEB_PHP_PREFIX};" conf/config
sed -ri "s|^(git_clone_uri_anon) = .+|\1 = ${AURWEB_PHP_PREFIX}/%s.git|" conf/config.defaults
sed -ri "s|^(git_clone_uri_priv) = .+|\1 = ${AURWEB_SSHD_PREFIX}/%s.git|" conf/config.defaults
# Listen on :9000.
sed -ri 's/^(listen).*/\1 = 0.0.0.0:9000/' /etc/php/php-fpm.d/www.conf
sed -ri 's/^;?(clear_env).*/\1 = no/' /etc/php/php-fpm.d/www.conf

View file

@ -1,7 +1,4 @@
#!/bin/bash
set -eou pipefail
# Initialize the new database; ignore errors.
python -m aurweb.initdb 2>/dev/null || /bin/true
exec php-fpm --fpm-config /etc/php/php-fpm.conf --nodaemonize

View file

@ -25,17 +25,8 @@ done
rm -rf $PROMETHEUS_MULTIPROC_DIR
mkdir -p $PROMETHEUS_MULTIPROC_DIR
# Initialize the new database; ignore errors.
python -m aurweb.initdb 2>/dev/null || \
(echo "Error: aurweb.initdb failed; already initialized?" && /bin/true)
# Run test_initdb ahead of time, which clears out the database,
# in case of previous failures which stopped the test suite before
# finishing the ends of some test fixtures.
eatmydata -- pytest test/test_initdb.py
# Run pytest with optional targets in front of it.
eatmydata -- make -C test "${PARAMS[@]}" pytest
pytest
# By default, report coverage and move it into cache.
if [ $COVERAGE -eq 1 ]; then

View file

@ -12,12 +12,6 @@ bash $dir/run-sharness.sh
# Pass --silence to avoid reporting coverage. We will do that below.
bash $dir/run-pytests.sh --no-coverage
# Export SQLite aurweb configuration.
export AUR_CONFIG=conf/config.sqlite
# Run Python tests.
bash $dir/run-pytests.sh --no-coverage
make -C test coverage
# /cache is mounted as a volume. Copy coverage into it.

View file

@ -1,17 +1,8 @@
#!/bin/bash
set -eou pipefail
DB_NAME="aurweb_test"
# Setup a config for our mysql db.
cp -vf conf/config.dev conf/config
sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config
sed -ri "s/^(name) = .+/\1 = ${DB_NAME}/" conf/config
# The port can be excluded from use if properly using
# volumes to share the mysql socket from the mariadb service.
# Example port sed:
# sed -i "s/^;?(port = .+)$/\1/" conf/config
# Continue onto the main command.
exec "$@"

View file

@ -3,6 +3,5 @@ set -eou pipefail
dir="$(dirname $0)"
bash $dir/test-mysql-entrypoint.sh
bash $dir/test-sqlite-entrypoint.sh
exec "$@"