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:
@@ -320,6 +320,17 @@ Steps:
|
|||||||
authenticated account (Federated's apps' `fcore` too) can send as any
|
authenticated account (Federated's apps' `fcore` too) can send as any
|
||||||
address. Tell Federated; with it on, an app could only send as its
|
address. Tell Federated; with it on, an app could only send as its
|
||||||
account's address
|
account's address
|
||||||
|
- MySQL (2026-12-03): `needs = ["mysql"]` (`coreapp new --mysql`): a
|
||||||
|
user and database `coreapp_<name>` (utf8mb4) on `pdnsmysql` (MariaDB
|
||||||
|
12.1, shared with PowerDNS), as Federated's apps do (e.g.
|
||||||
|
`lib/bookstack.sh`); same `DB_*` names as postgres, so an app has one
|
||||||
|
or the other. Root's password is read inside the container
|
||||||
|
(`$MYSQL_ROOT_PASSWORD`), not by the script, so it isn't in the
|
||||||
|
`set -x` log (Federated's `functions.sh` logs it anyway as
|
||||||
|
`MYSQL_ROOTPASSWORD=`, for every install: see "Logs"). Tested on
|
||||||
|
dev.fedcom.net: both needs refused, install, a table made and read from
|
||||||
|
the core network, no access to `powerdns`, wrong password refused,
|
||||||
|
remove drops the user and database, reinstall
|
||||||
- [ ] AI needs (findings below; needs Federated), then other services:
|
- [ ] AI needs (findings below; needs Federated), then other services:
|
||||||
PowerDNS records beyond the wildcard, if an app needs other hostnames
|
PowerDNS records beyond the wildcard, if an app needs other hostnames
|
||||||
5. The skill (moved ahead of 2-4, 2026-12-03): `skills/coreapp/SKILL.md`,
|
5. The skill (moved ahead of 2-4, 2026-12-03): `skills/coreapp/SKILL.md`,
|
||||||
@@ -355,7 +366,7 @@ Their points, and where coreapp-dev stands:
|
|||||||
done
|
done
|
||||||
- MySQL apps use the `pdnsmysql` container (MariaDB, 192.168.0.10, also
|
- MySQL apps use the `pdnsmysql` container (MariaDB, 192.168.0.10, also
|
||||||
PowerDNS's database), PostgreSQL apps `postgresql`: postgres is done;
|
PowerDNS's database), PostgreSQL apps `postgresql`: postgres is done;
|
||||||
[ ] a `mysql` need (its own user and database there)
|
done (`mysql` need, Coreapps step 4)
|
||||||
- Authelia through `installapp-sso` / `configsso_<app>`: needs a
|
- Authelia through `installapp-sso` / `configsso_<app>`: needs a
|
||||||
`lib/<app>.sh`, so not used; the sso need does the same, and keeps the
|
`lib/<app>.sh`, so not used; the sso need does the same, and keeps the
|
||||||
client copy Federated's apps keep
|
client copy Federated's apps keep
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ image = "localhost/coreapp/my-app" # where the Core gets the image
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
port = 8080 # the port it serves HTTP on
|
port = 8080 # the port it serves HTTP on
|
||||||
health = "/" # a path that answers when it's up
|
health = "/" # a path that answers when it's up
|
||||||
needs = ["postgres", "sso"] # its own database; sign-in with Core accounts; "email": sending mail
|
needs = ["postgres", "sso"] # its own database ("mysql" for MariaDB); sign-in with Core accounts; "email": sending mail
|
||||||
```
|
```
|
||||||
|
|
||||||
The app has no scripts or compose file: the Core side is made by
|
The app has no scripts or compose file: the Core side is made by
|
||||||
@@ -79,6 +79,7 @@ each new app explains the files and the settings it gets.
|
|||||||
| `coreapp new --postgres <name>` | The same, with its own database on the Core's PostgreSQL (a Python example app that uses it) |
|
| `coreapp new --postgres <name>` | The same, with its own database on the Core's PostgreSQL (a Python example app that uses it) |
|
||||||
| `coreapp new --sso <name>` | The same, with sign-in through the Core's Authelia (OpenID Connect; a Python example app) |
|
| `coreapp new --sso <name>` | The same, with sign-in through the Core's Authelia (OpenID Connect; a Python example app) |
|
||||||
| `coreapp new --postgres --sso <name>` | Both: a database and sign-in (the example counts each person's visits) |
|
| `coreapp new --postgres --sso <name>` | Both: a database and sign-in (the example counts each person's visits) |
|
||||||
|
| `coreapp new --mysql <name>` | (Instead of `--postgres`, with no example app.) Its own database on the Core's MariaDB |
|
||||||
| `coreapp new --email <name>` | (With any of the above.) Sending mail through the Core's mail server, with the app's own account |
|
| `coreapp new --email <name>` | (With any of the above.) Sending mail through the Core's mail server, with the app's own account |
|
||||||
| `coreapp deploy [--recreate]` | Build its image, copy it to the Core over SSH, install it, or update it keeping its settings and data (`--recreate`: a fresh container even if nothing changed) |
|
| `coreapp deploy [--recreate]` | Build its image, copy it to the Core over SSH, install it, or update it keeping its settings and data (`--recreate`: a fresh container even if nothing changed) |
|
||||||
| `coreapp check` | It answers at `https://<name>.<domain><health>` with a valid certificate |
|
| `coreapp check` | It answers at `https://<name>.<domain><health>` with a valid certificate |
|
||||||
|
|||||||
@@ -270,6 +270,23 @@ has the `DB_*` variables, `.coreapp` says `needs=postgres`.
|
|||||||
`/federated/bin/reconcile-authelia-sso` doesn't bring it back; Authelia
|
`/federated/bin/reconcile-authelia-sso` doesn't bring it back; Authelia
|
||||||
healthy, other clients (Nextcloud) still work. Deploy again: one block.
|
healthy, other clients (Nextcloud) still work. Deploy again: one block.
|
||||||
|
|
||||||
|
### With mysql
|
||||||
|
|
||||||
|
1. `needs = ["postgres", "mysql"]`: refused ("postgres or mysql, not
|
||||||
|
both"); `coreapp new --postgres --mysql x` too.
|
||||||
|
2. `coreapp new --mysql my-test`: `needs = ["mysql"]`, deploy. `.env` has
|
||||||
|
`DB_HOST=pdnsmysql.<domain>`, `DB_PORT=3306`, `DB_NAME` and `DB_USER`
|
||||||
|
`coreapp_my_test`, a random `DB_PASSWORD`; `service` has
|
||||||
|
`DEPENDS="pdnsmysql"`.
|
||||||
|
3. `docker run --rm --network core --env-file /federated/apps/my-test/.env
|
||||||
|
mariadb:12.1.2 sh -c 'mariadb -h$DB_HOST -u$DB_USER -p$DB_PASSWORD $DB_NAME ...'`:
|
||||||
|
create, insert, select work; `show databases` lists only its own;
|
||||||
|
`@@character_set_database` is `utf8mb4`; `powerdns` is denied (1044);
|
||||||
|
a wrong password is denied (1045).
|
||||||
|
4. The install log (`/federated/logs/coreapps/my-test-install.log`) has
|
||||||
|
root's password only on Federated's `MYSQL_ROOTPASSWORD=` lines.
|
||||||
|
5. `coreapp remove`: no `coreapp%` user or database left in MariaDB.
|
||||||
|
|
||||||
### With email
|
### With email
|
||||||
|
|
||||||
1. `coreapp new --email mail-test`: `needs = ["email"]`, deploy. On the
|
1. `coreapp new --email mail-test`: `needs = ["email"]`, deploy. On the
|
||||||
|
|||||||
+9
-6
@@ -3,7 +3,7 @@
|
|||||||
# Purpose : Make, deploy and test apps for Federated Core, against the Core
|
# Purpose : Make, deploy and test apps for Federated Core, against the Core
|
||||||
# in coreapp-dev's VM (coreapp-vm).
|
# in coreapp-dev's VM (coreapp-vm).
|
||||||
#
|
#
|
||||||
# coreapp new [--postgres] [--sso] [--email] <name>
|
# coreapp new [--postgres | --mysql] [--sso] [--email] <name>
|
||||||
# make a new app in ./<name> (with its own database,
|
# make a new app in ./<name> (with its own database,
|
||||||
# sign-in through the Core's Authelia, sending mail)
|
# sign-in through the Core's Authelia, sending mail)
|
||||||
# coreapp deploy [--recreate]
|
# coreapp deploy [--recreate]
|
||||||
@@ -154,20 +154,22 @@ apply_overlay() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_new() {
|
cmd_new() {
|
||||||
local name="" postgres="" sso="" email="" title dbname f needs="" what=""
|
local name="" postgres="" mysql="" sso="" email="" title dbname f needs="" what=""
|
||||||
local overlays=()
|
local overlays=()
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--postgres) postgres=1 ;;
|
--postgres) postgres=1 ;;
|
||||||
|
--mysql) mysql=1 ;;
|
||||||
--sso) sso=1 ;;
|
--sso) sso=1 ;;
|
||||||
--email) email=1 ;;
|
--email) email=1 ;;
|
||||||
-*) die "Unknown option $1. Usage: coreapp new [--postgres] [--sso] [--email] <name>" ;;
|
-*) die "Unknown option $1. Usage: coreapp new [--postgres | --mysql] [--sso] [--email] <name>" ;;
|
||||||
*) name="$1" ;;
|
*) name="$1" ;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
[[ -d "$TEMPLATE" ]] || die "The app template is missing: $TEMPLATE"
|
[[ -d "$TEMPLATE" ]] || die "The app template is missing: $TEMPLATE"
|
||||||
[[ -n "$name" ]] || die "Usage: coreapp new [--postgres] [--sso] [--email] <name> (lowercase letters, digits and -)"
|
[[ -n "$name" ]] || die "Usage: coreapp new [--postgres | --mysql] [--sso] [--email] <name> (lowercase letters, digits and -)"
|
||||||
|
[[ -z "$postgres" || -z "$mysql" ]] || die "--postgres or --mysql, not both."
|
||||||
[[ "$name" =~ ^[a-z]([a-z0-9-]{0,29}[a-z0-9])$ ]] \
|
[[ "$name" =~ ^[a-z]([a-z0-9-]{0,29}[a-z0-9])$ ]] \
|
||||||
|| die "'$name': use 2-31 lowercase letters, digits and -, starting with a letter and not ending with -. It becomes https://$name.<domain>."
|
|| die "'$name': use 2-31 lowercase letters, digits and -, starting with a letter and not ending with -. It becomes https://$name.<domain>."
|
||||||
[[ ! -e "$name" ]] || die "./$name already exists."
|
[[ ! -e "$name" ]] || die "./$name already exists."
|
||||||
@@ -190,7 +192,8 @@ cmd_new() {
|
|||||||
apply_overlay "$name" "$f"
|
apply_overlay "$name" "$f"
|
||||||
[[ -f "$f/.needs" ]] && needs="$needs, \"$(cat "$f/.needs")\""
|
[[ -f "$f/.needs" ]] && needs="$needs, \"$(cat "$f/.needs")\""
|
||||||
done
|
done
|
||||||
# No example app for email: the settings are in README.md
|
# No example apps for mysql and email: the settings are in README.md
|
||||||
|
[[ -n "$mysql" ]] && needs="\"mysql\"$needs"
|
||||||
[[ -n "$email" ]] && needs="$needs, \"email\""
|
[[ -n "$email" ]] && needs="$needs, \"email\""
|
||||||
sed -i "s/^needs = .*/needs = [${needs#, }]/" "$name/coreapp.toml"
|
sed -i "s/^needs = .*/needs = [${needs#, }]/" "$name/coreapp.toml"
|
||||||
# The example apps with a database or sign-in have a /health path
|
# The example apps with a database or sign-in have a /health path
|
||||||
@@ -200,7 +203,7 @@ cmd_new() {
|
|||||||
sed -i -e "s/{{NAME}}/$name/g" -e "s/{{TITLE}}/$title/g" -e "s/{{DBNAME}}/$dbname/g" "$f"
|
sed -i -e "s/{{NAME}}/$name/g" -e "s/{{TITLE}}/$title/g" -e "s/{{DBNAME}}/$dbname/g" "$f"
|
||||||
done < <(find "$name" -type f ! -name '*.png' -print0)
|
done < <(find "$name" -type f ! -name '*.png' -print0)
|
||||||
|
|
||||||
[[ -n "$postgres" ]] && what=", with a database"
|
[[ -n "$postgres$mysql" ]] && what=", with a database"
|
||||||
[[ -n "$sso" ]] && what="$what, with sign-in through Authelia"
|
[[ -n "$sso" ]] && what="$what, with sign-in through Authelia"
|
||||||
[[ -n "$email" ]] && what="$what, sending mail"
|
[[ -n "$email" ]] && what="$what, sending mail"
|
||||||
echo "Made $title in ./$name$what."
|
echo "Made $title in ./$name$what."
|
||||||
|
|||||||
+4
-1
@@ -67,7 +67,7 @@ FIRST, LAST = 2, 254
|
|||||||
RESERVED = {"www", "mail", "ns1", "ns2", "autodiscover", "autoconfig",
|
RESERVED = {"www", "mail", "ns1", "ns2", "autodiscover", "autoconfig",
|
||||||
"panel", "dashboard", "mcphub", "api", "admin"}
|
"panel", "dashboard", "mcphub", "api", "admin"}
|
||||||
# What an app can ask for, in the order they're set up
|
# 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
|
# 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.
|
# 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)} "
|
raise Refused(f"coreapp.toml: needs: unknown {', '.join(bad)} "
|
||||||
f"(it knows {', '.join(NEEDS)}).")
|
f"(it knows {', '.join(NEEDS)}).")
|
||||||
value = [n for n in NEEDS if n in value]
|
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:
|
else:
|
||||||
if not isinstance(value, str) or not re.fullmatch(FIELDS[key], value):
|
if not isinstance(value, str) or not re.fullmatch(FIELDS[key], value):
|
||||||
raise Refused(f"coreapp.toml: {key} = {value!r} isn't allowed. "
|
raise Refused(f"coreapp.toml: {key} = {value!r} isn't allowed. "
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
pdnsmysql
|
||||||
@@ -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@
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
+22
-3
@@ -67,7 +67,7 @@ image = "localhost/coreapp/my-app" # image name; the Core runs image:version
|
|||||||
version = "0.1.0" # the image tag; raise it for each release
|
version = "0.1.0" # the image tag; raise it for each release
|
||||||
port = 8080 # the port the app serves HTTP on (any; 8080 is usual)
|
port = 8080 # the port the app serves HTTP on (any; 8080 is usual)
|
||||||
health = "/health" # a path that answers once it's up
|
health = "/health" # a path that answers once it's up
|
||||||
needs = ["postgres", "sso"] # what it needs from the Core, or [] ("email" too)
|
needs = ["postgres", "sso"] # what it needs from the Core, or [] ("mysql", "email" too)
|
||||||
```
|
```
|
||||||
|
|
||||||
The installer is strict, because these values end up in files on the Core
|
The installer is strict, because these values end up in files on the Core
|
||||||
@@ -115,6 +115,25 @@ exiting. Many apps want a URL; build it from these variables in the
|
|||||||
entrypoint or the app's config (e.g.
|
entrypoint or the app's config (e.g.
|
||||||
`postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME`).
|
`postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME`).
|
||||||
|
|
||||||
|
### `mysql`: its own MySQL database (MariaDB)
|
||||||
|
|
||||||
|
For apps that need MySQL or MariaDB instead of PostgreSQL (use `postgres`
|
||||||
|
when the app supports both; an app can't have both). The Core makes a user
|
||||||
|
and database on its MariaDB 12 (the `pdnsmysql` container, shared with
|
||||||
|
PowerDNS and the Core's other apps), and adds the same variables:
|
||||||
|
|
||||||
|
| Variable | Value |
|
||||||
|
|---|---|
|
||||||
|
| `DB_HOST` | `pdnsmysql.<domain>` (resolves only on the Core's network) |
|
||||||
|
| `DB_PORT` | `3306` |
|
||||||
|
| `DB_NAME`, `DB_USER` | `coreapp_<name>` with `-` as `_` |
|
||||||
|
| `DB_PASSWORD` | random |
|
||||||
|
|
||||||
|
The database is `utf8mb4`; the app has all privileges on it and nothing
|
||||||
|
else. The rest is as for `postgres` (migrations, retrying at boot; a URL
|
||||||
|
is `mysql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME`).
|
||||||
|
`coreapp new --mysql` adds the need (there's no example app for it).
|
||||||
|
|
||||||
### `sso`: sign-in with Core accounts
|
### `sso`: sign-in with Core accounts
|
||||||
|
|
||||||
The Core registers the app as an OpenID Connect client with its Authelia,
|
The Core registers the app as an OpenID Connect client with its Authelia,
|
||||||
@@ -231,8 +250,8 @@ and make the Dockerfile fit the Core:
|
|||||||
- **Answer on `health`** once ready (a dedicated health endpoint, or `/` if
|
- **Answer on `health`** once ready (a dedicated health endpoint, or `/` if
|
||||||
it returns 2xx-4xx without signing in).
|
it returns 2xx-4xx without signing in).
|
||||||
- **One container.** If the upstream project ships a compose file with
|
- **One container.** If the upstream project ships a compose file with
|
||||||
several services, keep only the app, use `needs = ["postgres"]` for its
|
several services, keep only the app, use `needs = ["postgres"]` (or
|
||||||
database, and stop if it needs other services (see "Not available yet").
|
`["mysql"]` for MySQL/MariaDB) for its database, and stop if it needs other services (see "Not available yet").
|
||||||
|
|
||||||
Keep the app's other files as they are; add `.dockerignore` entries for
|
Keep the app's other files as they are; add `.dockerignore` entries for
|
||||||
`coreapp.toml`, `icon.png` and `.git` so they don't bust the build cache.
|
`coreapp.toml`, `icon.png` and `.git` so they don't bust the build cache.
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ keep its values and add new ones):
|
|||||||
| `IMAGE_VERSION` | The version that's installed |
|
| `IMAGE_VERSION` | The version that's installed |
|
||||||
|
|
||||||
`needs = ["postgres"]` adds `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and
|
`needs = ["postgres"]` adds `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and
|
||||||
`DB_PASSWORD`; `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and
|
`DB_PASSWORD` (`needs = ["mysql"]` the same, for MariaDB); `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and
|
||||||
`OIDC_CLIENT_SECRET`; `needs = ["email"]` adds `SMTP_HOST`, `SMTP_PORT`
|
`OIDC_CLIENT_SECRET`; `needs = ["email"]` adds `SMTP_HOST`, `SMTP_PORT`
|
||||||
(587), `SMTP_SECURITY` (`starttls`), `SMTP_USER`, `SMTP_PASSWORD` and
|
(587), `SMTP_SECURITY` (`starttls`), `SMTP_USER`, `SMTP_PASSWORD` and
|
||||||
`SMTP_FROM` (`{{NAME}}@<domain>`): the app's own account on the Core's mail
|
`SMTP_FROM` (`{{NAME}}@<domain>`): the app's own account on the Core's mail
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ version = "0.1.0"
|
|||||||
port = 8080
|
port = 8080
|
||||||
health = "/"
|
health = "/"
|
||||||
|
|
||||||
# What it needs from the Core: "postgres" (its own database), "sso"
|
# What it needs from the Core: "postgres" or "mysql" (its own database), "sso"
|
||||||
# (sign-in with Core accounts through Authelia), "email" (sending mail)
|
# (sign-in with Core accounts through Authelia), "email" (sending mail)
|
||||||
needs = []
|
needs = []
|
||||||
|
|||||||
Reference in New Issue
Block a user