diff --git a/conf/config.defaults b/conf/config.defaults index c29d7045..68e235be 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -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 diff --git a/conf/config.dev b/conf/config.dev index 9467615e..e97f6f12 100644 --- a/conf/config.dev +++ b/conf/config.dev @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index bda4ddfb..c39d38bf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/docker/fastapi-entrypoint.sh b/docker/fastapi-entrypoint.sh index f4ceaafa..9df6382d 100755 --- a/docker/fastapi-entrypoint.sh +++ b/docker/fastapi-entrypoint.sh @@ -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. diff --git a/docker/mariadb-entrypoint.sh b/docker/mariadb-entrypoint.sh index e1ebfa6a..a00f6106 100755 --- a/docker/mariadb-entrypoint.sh +++ b/docker/mariadb-entrypoint.sh @@ -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 diff --git a/docker/mariadb-init-entrypoint.sh b/docker/mariadb-init-entrypoint.sh index 413227b9..6df98e4f 100755 --- a/docker/mariadb-init-entrypoint.sh +++ b/docker/mariadb-init-entrypoint.sh @@ -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 diff --git a/docker/php-entrypoint.sh b/docker/php-entrypoint.sh index 274f8e17..05b76408 100755 --- a/docker/php-entrypoint.sh +++ b/docker/php-entrypoint.sh @@ -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 diff --git a/docker/scripts/run-php.sh b/docker/scripts/run-php.sh index 22346b47..b86f8ce5 100755 --- a/docker/scripts/run-php.sh +++ b/docker/scripts/run-php.sh @@ -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 diff --git a/docker/scripts/run-pytests.sh b/docker/scripts/run-pytests.sh index ee546fb7..b8f695df 100755 --- a/docker/scripts/run-pytests.sh +++ b/docker/scripts/run-pytests.sh @@ -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 diff --git a/docker/scripts/run-tests.sh b/docker/scripts/run-tests.sh index 3181a623..45c7835f 100755 --- a/docker/scripts/run-tests.sh +++ b/docker/scripts/run-tests.sh @@ -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. diff --git a/docker/test-mysql-entrypoint.sh b/docker/test-mysql-entrypoint.sh index 7be3626b..a46b2572 100755 --- a/docker/test-mysql-entrypoint.sh +++ b/docker/test-mysql-entrypoint.sh @@ -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 "$@" diff --git a/docker/tests-entrypoint.sh b/docker/tests-entrypoint.sh index ca3d3d9a..145bee6e 100755 --- a/docker/tests-entrypoint.sh +++ b/docker/tests-entrypoint.sh @@ -3,6 +3,5 @@ set -eou pipefail dir="$(dirname $0)" bash $dir/test-mysql-entrypoint.sh -bash $dir/test-sqlite-entrypoint.sh exec "$@"