Add the mysql need: its own database on the Core's MariaDB

needs = ["mysql"] (coreapp new --mysql) makes a user and database
coreapp_<name> on pdnsmysql, with the same DB_* settings as postgres
(so an app has one or the other). Root's password is read inside the
container, so it stays out of installapp's set -x log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 15:15:23 -07:00
co-authored by Claude Opus 5.5
parent 6ab1db839b
commit 8ef2112e3c
12 changed files with 93 additions and 14 deletions
+4 -1
View File
@@ -67,7 +67,7 @@ FIRST, LAST = 2, 254
RESERVED = {"www", "mail", "ns1", "ns2", "autodiscover", "autoconfig",
"panel", "dashboard", "mcphub", "api", "admin"}
# What an app can ask for, in the order they're set up
NEEDS = ["postgres", "sso", "email"]
NEEDS = ["postgres", "mysql", "sso", "email"]
# What coreapp.toml may contain. Values end up in shell-sourced and YAML
# files on the Core, so each is limited to characters that are safe there.
@@ -150,6 +150,9 @@ def read_manifest(folder):
raise Refused(f"coreapp.toml: needs: unknown {', '.join(bad)} "
f"(it knows {', '.join(NEEDS)}).")
value = [n for n in NEEDS if n in value]
if "postgres" in value and "mysql" in value:
raise Refused("coreapp.toml: needs: postgres or mysql, not both "
"(both give the app DB_* settings).")
else:
if not isinstance(value, str) or not re.fullmatch(FIELDS[key], value):
raise Refused(f"coreapp.toml: {key} = {value!r} isn't allowed. "
+1
View File
@@ -0,0 +1 @@
pdnsmysql
+6
View File
@@ -0,0 +1,6 @@
# Its database on the Core's MariaDB (pdnsmysql), made by needs/mysql/setup
DB_HOST=pdnsmysql.@DOMAIN@
DB_PORT=3306
DB_NAME={{DBNAME}}
DB_USER={{DBNAME}}
DB_PASSWORD=@DB_PASSWORD:RANDOM:LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL@
+13
View File
@@ -0,0 +1,13 @@
# Its own database and user on the Core's MariaDB (pdnsmysql, shared with
# PowerDNS and Federated's apps), with the password from .env. Safe to run
# again: an existing user gets the password, an existing database is kept.
# Root's password is read inside the container (its MYSQL_ROOT_PASSWORD), so
# it's not on a command line or in installapp's set -x log.
DB_PASSWORD="$(sed -n 's/^DB_PASSWORD=//p' /federated/apps/{{NAME}}/.env)"
docker exec -i pdnsmysql sh -c 'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" exec mariadb -uroot' <<SQL
CREATE USER IF NOT EXISTS '{{DBNAME}}'@'%' IDENTIFIED BY '$DB_PASSWORD';
ALTER USER '{{DBNAME}}'@'%' IDENTIFIED BY '$DB_PASSWORD';
CREATE DATABASE IF NOT EXISTS {{DBNAME}} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON {{DBNAME}}.* TO '{{DBNAME}}'@'%';
SQL
unset DB_PASSWORD
+5
View File
@@ -0,0 +1,5 @@
# Drop its database and user from the Core's MariaDB (pdnsmysql)
docker exec -i pdnsmysql sh -c 'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" exec mariadb -uroot' <<SQL
DROP DATABASE IF EXISTS {{DBNAME}};
DROP USER IF EXISTS '{{DBNAME}}'@'%';
SQL