mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: Switch to postgres
Migrate from MariaDB to PostgreSQL. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
3220cf886e
commit
db8e2458f9
64 changed files with 572 additions and 629 deletions
|
@ -47,7 +47,7 @@ Luckily such data can be generated.
|
|||
docker compose exec fastapi /bin/bash
|
||||
pacman -S words fortune-mod
|
||||
./schema/gendummydata.py dummy.sql
|
||||
mysql aurweb < dummy.sql
|
||||
su postgres -q -c 'psql aurweb < dummy.sql'
|
||||
```
|
||||
|
||||
The generation script may prompt you to install other Arch packages before it
|
||||
|
|
|
@ -71,7 +71,7 @@ start_step_ca() {
|
|||
|
||||
kill_step_ca() {
|
||||
# Stop the step-ca web server.
|
||||
killall step-ca >/dev/null 2>&1 || /bin/true
|
||||
killall -w step-ca >/dev/null 2>&1 || /bin/true
|
||||
}
|
||||
|
||||
install_step_ca() {
|
||||
|
@ -105,8 +105,6 @@ if [ ! -d /root/.step/config ]; then
|
|||
echo -n "WARN: Your certificates are being regenerated to resolve "
|
||||
echo -n "an inconsistent step-ca state. You will need to re-import "
|
||||
echo "the root CA certificate into your browser."
|
||||
else
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Set permissions to /data to rwx for everybody.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
set -eou pipefail
|
||||
|
||||
# Setup the DB.
|
||||
NO_INITDB=1 /docker/mariadb-init-entrypoint.sh
|
||||
/docker/postgres-init-entrypoint.sh
|
||||
|
||||
# Create aurblup's directory.
|
||||
AURBLUP_DIR="/aurweb/aurblup/"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
set -eou pipefail
|
||||
|
||||
# Setup database.
|
||||
NO_INITDB=1 /docker/mariadb-init-entrypoint.sh
|
||||
/docker/postgres-init-entrypoint.sh
|
||||
|
||||
# Setup some other options.
|
||||
aurweb-config set options cache 'redis'
|
||||
|
|
|
@ -39,7 +39,7 @@ Match User aur
|
|||
EOF
|
||||
|
||||
# Setup database.
|
||||
NO_INITDB=1 /docker/mariadb-init-entrypoint.sh
|
||||
/docker/postgres-init-entrypoint.sh
|
||||
|
||||
# Setup some other options.
|
||||
aurweb-config set serve repo-path '/aurweb/aur.git/'
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/bash
|
||||
exec mysqladmin ping --silent
|
2
docker/health/postgres.sh
Executable file
2
docker/health/postgres.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
exec su postgres -c 'pg_isready'
|
|
@ -1,31 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
MYSQL_DATA=/var/lib/mysql
|
||||
|
||||
mariadb-install-db --user=mysql --basedir=/usr --datadir=$MYSQL_DATA
|
||||
|
||||
# Start it up.
|
||||
mysqld_safe --datadir=$MYSQL_DATA --skip-networking &
|
||||
while ! mysqladmin ping 2>/dev/null; do
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
# Configure databases.
|
||||
DATABASE="aurweb" # Persistent database for fastapi.
|
||||
|
||||
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 "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'@'%';"
|
||||
|
||||
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
|
||||
|
||||
exec "$@"
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
# Setup a config for our mysql db.
|
||||
aurweb-config set database name 'aurweb'
|
||||
aurweb-config set database user 'aur'
|
||||
aurweb-config set database password 'aur'
|
||||
aurweb-config set database host 'localhost'
|
||||
aurweb-config set database socket '/var/run/mysqld/mysqld.sock'
|
||||
aurweb-config unset database port
|
||||
|
||||
if [ ! -z ${NO_INITDB+x} ]; then
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
python -m aurweb.initdb 2>/dev/null || /bin/true
|
||||
exec "$@"
|
34
docker/postgres-entrypoint.sh
Executable file
34
docker/postgres-entrypoint.sh
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
PGDATA=/var/lib/postgres/data
|
||||
DATABASE="aurweb"
|
||||
|
||||
# Initialize and setup postgres
|
||||
if [ ! -f "$PGDATA/../init" ]; then
|
||||
echo "Preparing postgres instance..."
|
||||
touch $PGDATA/../init
|
||||
|
||||
# Init db directory
|
||||
su postgres -c "pg_ctl initdb -D $PGDATA"
|
||||
su postgres -c "echo \"listen_addresses='*'\" >> $PGDATA/postgresql.conf"
|
||||
su postgres -c "echo \"host all all 0.0.0.0/0 scram-sha-256\" >> $PGDATA/pg_hba.conf"
|
||||
install -d -o postgres -g postgres /run/postgresql
|
||||
|
||||
# Start postgres
|
||||
su postgres -c "pg_ctl start -D $PGDATA"
|
||||
|
||||
# Configure database & user
|
||||
echo "Taking care of primary database '$DATABASE'..."
|
||||
su postgres -c "psql -c \"create database $DATABASE;\""
|
||||
su postgres -c "psql -c \"create role aur superuser login password 'aur';\"";
|
||||
|
||||
# Provision database
|
||||
python -m aurweb.initdb 2>/dev/null || /bin/true
|
||||
|
||||
# Stop postgres
|
||||
su postgres -c "pg_ctl stop -D $PGDATA"
|
||||
|
||||
fi
|
||||
|
||||
exec "$@"
|
12
docker/postgres-init-entrypoint.sh
Executable file
12
docker/postgres-init-entrypoint.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
# Setup a config for our postgres db via socket connection.
|
||||
aurweb-config set database name 'aurweb'
|
||||
aurweb-config set database user 'aur'
|
||||
aurweb-config set database socket '/run/postgresql'
|
||||
aurweb-config unset database host
|
||||
aurweb-config unset database port
|
||||
aurweb-config unset database password
|
||||
|
||||
exec "$@"
|
|
@ -14,7 +14,7 @@ pacman -Sy --noconfirm --noprogressbar archlinux-keyring
|
|||
# Install other OS dependencies.
|
||||
pacman -Syu --noconfirm --noprogressbar \
|
||||
--cachedir .pkg-cache git gpgme nginx redis openssh \
|
||||
mariadb mariadb-libs cgit-aurweb uwsgi uwsgi-plugin-cgi \
|
||||
postgresql cgit-aurweb uwsgi uwsgi-plugin-cgi \
|
||||
python-pip pyalpm python-srcinfo curl libeatmydata cronie \
|
||||
python-poetry python-poetry-core step-cli step-ca asciidoc \
|
||||
python-virtualenv python-pre-commit
|
||||
|
|
|
@ -8,7 +8,7 @@ make -C test clean
|
|||
# Run sharness tests.
|
||||
bash $dir/run-sharness.sh
|
||||
|
||||
# Run Python tests with MariaDB database.
|
||||
# Run Python tests with PostgreSQL database.
|
||||
# Pass --silence to avoid reporting coverage. We will do that below.
|
||||
bash $dir/run-pytests.sh --no-coverage
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
# We use the root user for testing in Docker.
|
||||
# The test user must be able to create databases and drop them.
|
||||
aurweb-config set database user 'root'
|
||||
aurweb-config set database host 'localhost'
|
||||
aurweb-config set database socket '/var/run/mysqld/mysqld.sock'
|
||||
|
||||
# Remove possibly problematic configuration options.
|
||||
# We depend on the database socket within Docker and
|
||||
# being run as the root user.
|
||||
aurweb-config unset database password
|
||||
aurweb-config unset database port
|
||||
|
||||
# Setup notifications for testing.
|
||||
aurweb-config set notifications sendmail "$(pwd)/util/sendmail"
|
||||
|
||||
exec "$@"
|
15
docker/test-postgres-entrypoint.sh
Executable file
15
docker/test-postgres-entrypoint.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
# Setup a config for our postgres db via socket connection.
|
||||
aurweb-config set database name 'aurweb'
|
||||
aurweb-config set database user 'aur'
|
||||
aurweb-config set database socket '/run/postgresql'
|
||||
aurweb-config unset database host
|
||||
aurweb-config unset database port
|
||||
aurweb-config unset database password
|
||||
|
||||
# Setup notifications for testing.
|
||||
aurweb-config set notifications sendmail "$(pwd)/util/sendmail"
|
||||
|
||||
exec "$@"
|
|
@ -2,6 +2,6 @@
|
|||
set -eou pipefail
|
||||
dir="$(dirname $0)"
|
||||
|
||||
bash $dir/test-mysql-entrypoint.sh
|
||||
bash $dir/test-postgres-entrypoint.sh
|
||||
|
||||
exec "$@"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue