From dbeebd3b01044d508531476dc99571890e150065 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sat, 27 Nov 2021 23:15:19 -0800 Subject: [PATCH] change(fastapi): setup live database in mariadb-init-entrypoint.sh Centralize database setup there and remove all copying of config.dev from the entrypoint scripts (the Dockerfile now does it). Signed-off-by: Kevin Morris --- docker/cron-entrypoint.sh | 28 +++++++++++++++++++++++----- docker/fastapi-entrypoint.sh | 10 +--------- docker/git-entrypoint.sh | 10 +--------- docker/mariadb-init-entrypoint.sh | 12 ++++++++---- docker/php-entrypoint.sh | 10 +--------- docker/test-mysql-entrypoint.sh | 4 ---- 6 files changed, 34 insertions(+), 40 deletions(-) diff --git a/docker/cron-entrypoint.sh b/docker/cron-entrypoint.sh index d4173eaf..5b69ab19 100755 --- a/docker/cron-entrypoint.sh +++ b/docker/cron-entrypoint.sh @@ -1,12 +1,30 @@ #!/bin/bash set -eou pipefail -# Prepare AUR_CONFIG. -cp -vf conf/config.dev conf/config -sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config +# Setup the DB. +NO_INITDB=1 /docker/mariadb-init-entrypoint.sh -# Create directories we need. -mkdir -p /aurweb/aurblup +# Create aurblup's directory. +AURBLUP_DIR="/aurweb/aurblup/" +mkdir -p $AURBLUP_DIR + +# Setup aurblup config for Docker. +AURBLUP_DBS='core extra community multilib testing community-testing' +AURBLUP_SERVER='https://mirrors.kernel.org/archlinux/%s/os/x86_64' +aurweb-config set aurblup db-path "$AURBLUP_DIR" +aurweb-config set aurblup sync-dbs "$AURBLUP_DBS" +aurweb-config set aurblup server "$AURBLUP_SERVER" + +# Setup mkpkglists config for Docker. +ARCHIVE_DIR='/var/lib/aurweb/archives' +aurweb-config set mkpkglists archivedir "$ARCHIVE_DIR" +aurweb-config set mkpkglists packagesfile "$ARCHIVE_DIR/packages.gz" +aurweb-config set mkpkglists packagesmetafile \ + "$ARCHIVE_DIR/packages-meta-v1.json.gz" +aurweb-config set mkpkglists packagesmetaextfile \ + "$ARCHIVE_DIR/packages-meta-ext-v1.json.gz" +aurweb-config set mkpkglists pkgbasefile "$ARCHIVE_DIR/pkgbase.gz" +aurweb-config set mkpkglists userfile "$ARCHIVE_DIR/users.gz" # Install the cron configuration. cp /docker/config/aurweb-cron /etc/cron.d/aurweb-cron diff --git a/docker/fastapi-entrypoint.sh b/docker/fastapi-entrypoint.sh index d1519bf8..c6597313 100755 --- a/docker/fastapi-entrypoint.sh +++ b/docker/fastapi-entrypoint.sh @@ -1,16 +1,8 @@ #!/bin/bash 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 - # Setup database. -aurweb-config set database user 'aur' -aurweb-config set database password 'aur' -aurweb-config set database host 'localhost' -aurweb-config set database socket '/var/lib/mysqld/mysqld.sock' -aurweb-config unset database port +NO_INITDB=1 /docker/mariadb-init-entrypoint.sh # Setup some other options. aurweb-config set options cache 'redis' diff --git a/docker/git-entrypoint.sh b/docker/git-entrypoint.sh index 96f4d112..c9f1ec30 100755 --- a/docker/git-entrypoint.sh +++ b/docker/git-entrypoint.sh @@ -38,16 +38,8 @@ Match User aur AcceptEnv AUR_OVERWRITE EOF -# Setup a config for our mysql db. -cp -vf conf/config.dev $AUR_CONFIG -sed -i "s;YOUR_AUR_ROOT;$(pwd);g" $AUR_CONFIG - # Setup database. -aurweb-config set database user 'aur' -aurweb-config set database password 'aur' -aurweb-config set database host 'localhost' -aurweb-config set database socket '/var/lib/mysqld/mysqld.sock' -aurweb-config unset database port +NO_INITDB=1 /docker/mariadb-init-entrypoint.sh # Setup some other options. aurweb-config set serve repo-path '/aurweb/aur.git/' diff --git a/docker/mariadb-init-entrypoint.sh b/docker/mariadb-init-entrypoint.sh index 64e66a0f..74980031 100755 --- a/docker/mariadb-init-entrypoint.sh +++ b/docker/mariadb-init-entrypoint.sh @@ -2,12 +2,16 @@ 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 - +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 "$@" diff --git a/docker/php-entrypoint.sh b/docker/php-entrypoint.sh index 1756718d..dc1a91de 100755 --- a/docker/php-entrypoint.sh +++ b/docker/php-entrypoint.sh @@ -5,16 +5,8 @@ for archive in packages pkgbase users packages-meta-v1.json packages-meta-ext-v1 ln -vsf /var/lib/aurweb/archives/${archive}.gz /aurweb/web/html/${archive}.gz done -# Setup a config for our mysql db. -cp -vf conf/config.dev conf/config -sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config - # Setup database. -aurweb-config set database user 'aur' -aurweb-config set database password 'aur' -aurweb-config set database host 'localhost' -aurweb-config set database socket '/var/lib/mysqld/mysqld.sock' -aurweb-config unset database port +NO_INITDB=1 /docker/mariadb-init-entrypoint.sh # Setup some other options. aurweb-config set options cache 'memcache' diff --git a/docker/test-mysql-entrypoint.sh b/docker/test-mysql-entrypoint.sh index 262577a6..1bf85b54 100755 --- a/docker/test-mysql-entrypoint.sh +++ b/docker/test-mysql-entrypoint.sh @@ -1,10 +1,6 @@ #!/bin/bash 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 - # 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'