coreapp.toml's [postgres] or [mysql] min_version: the installer compares it with the Core's PostgreSQL or MariaDB on install and update, and refuses an older Core with both versions, instead of the app failing later. coreapp core reads the versions the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 KiB
name, description
| name | description |
|---|---|
| coreapp | Build, port and test apps ("Coreapps") for Federated Core with coreapp-dev. Use this whenever someone wants to make an app run on a Federated Core, package an existing web app or repository for a Core, write or fix a coreapp.toml, give an app sign-in with Core accounts (Authelia) or a database on the Core's PostgreSQL, or deploy and test an app on the Core in the local coreapp-dev VM (coreapp deploy, coreapp check), even if they just say "make this work on our Core" or "Coreapp". |
Making apps for Federated Core
A Federated Core is a self-hosted server that runs many apps as Docker
containers behind one domain. A Coreapp is an app anyone can publish
and a Core's owner can install. coreapp-dev is the kit for making them: it
runs a real Core in a VM on this computer, and the coreapp command deploys
the app you're working on to it.
How a Coreapp works
An app is a repository with:
| File | What it is |
|---|---|
coreapp.toml |
What the Core needs to know (below) |
Dockerfile |
Builds the app's image |
| the app's code | Whatever the Dockerfile uses |
icon.png |
Its icon in the Core's dashboard: a square PNG, 256x256 is good, up to 1 MB (shown at 40x40). Without one, or if it isn't a PNG, the Core shows a default icon |
That's all. The app has no scripts and no compose file: a trusted
installer on the Core (coreapps) reads coreapp.toml and makes the rest:
the container on the Core's network, the HTTPS route and certificate for
https://<name>.<domain>, the app's settings and secrets, and whatever it
needs (its database, its sign-in client). This is deliberate: a Core
installs apps from other people's repositories, so an app gets to declare
what it needs, never to run commands on the Core. Don't try to get around
it (SSHing into the Core to edit files, adding scripts the Core should run):
whatever you change by hand there is lost on the next deploy and won't exist
on anyone else's Core.
What the Core gives every app:
-
One container, from the app's image, serving plain HTTP on one port. Traefik on the Core terminates HTTPS at
https://<name>.<domain>and forwards to that port. -
/datainside the container: kept on the Core across updates, restarts and reboots. The Core makes it belong to the user the image runs as (USERin the Dockerfile) before starting the container, so the image doesn't need to create or chown/dataitself (what the image has at/datais hidden by the mount anyway). Everything else in the container is thrown away on each update, so anything the app must keep (uploads, SQLite files, generated keys) goes under/data. -
Environment variables (from a
.envfile made once at install; updates keep the values and add new ones):Variable Value APP_URLhttps://<name>.<domain>, the app's public addressAPP_SECRET32 random letters and digits, for signing cookies, sessions IMAGE_VERSIONThe installed version ( coreapp deploybuilds with plaindocker build ., no build args, so read the version from here, not a build-timeVERSION)CORE_DOMAINThe Core's domain ( <domain>). Set only on a Core: an app that also runs elsewhere can use it to tellCORE_ADMIN_EMAILadmin@<domain>, the Core's admin account: always an admin of the app (seesso)CORE_PROXYtraefik's address, the only proxy in front of the app: the one to trust for X-Forwarded-ForandX-Forwarded-ProtoAPP_SECRETisn't hex or base64: an app that wants key bytes (e.g. 32 bytes for encryption) derives them, e.g. SHA-256 ofAPP_SECRET. It never changes, and it lives only in the app's.envon the Core (/federated/apps/<name>/.env, beside/data): anything encrypted with it is unreadable without that file.plus the ones each need adds (below).
coreapp.toml
name = "my-app" # id and hostname: https://my-app.<domain>
title = "My App" # shown in the Core's dashboard
description = "What it does, in a sentence"
docs = "https://example.com/docs" # optional; installed from a repository, defaults to it
image = "localhost/coreapp/my-app" # image name; the Core runs image:version
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)
health = "/health" # a path that answers once it's up
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 that are read by shell and YAML:
name: 2-31 lowercase letters, digits and-, starting with a letter, not ending with-. Names of Federated's own apps (nextcloud, gitea, ...) and the Core's hostnames (www, mail, ...) are refused.title: up to 40 letters, digits, spaces and. , ! ? ( ) & + _ -.description: up to 200 characters, no",$, backtick,\,@or line breaks.image: must start with its registry. While developing, uselocalhost/coreapp/<name>:coreapp deploybuilds it here and copies it to the Core, and it can't be pulled from anywhere by mistake. (A name without a registry, likeme/app, would mean Docker Hub, so it's refused.)version: letters, digits,.,_,-.port: a number, not a string. Use whatever port the app already listens on; for a new app, 8080. It's only reachable inside the Core.health: a path starting with/. Deploy asks for it on the app's address with the app's host name (Host: <name>.<domain>,X-Forwarded-Proto: https, as traefik sends), and waits until it answers with any status below 500 (so/is fine for an app without a health endpoint, even if it redirects to a sign-in page);coreapp checkwants a 2xx there, so prefer a path that returns 200 without signing in.- Unknown settings are refused, so a typo doesn't go unnoticed.
coreapp deploy checks the file first and says exactly what's wrong.
What the Core offers
The Core runs these for its apps. Versions are today's; coreapp core
prints the ones the Core in the VM actually runs, and Federated updates
them with the Core. Check the app's requirements against them before
choosing a need (its docs, the images in its own compose file, its
migrations): a feature the Core's version lacks fails only when the code
using it runs, so deploy, coreapp check and a sign-in can all pass.
If the app needs a newer database server than some Cores have, put its
oldest working version in coreapp.toml, so an older Core refuses to
install it (with both versions in the message) instead of breaking later:
[postgres]
min_version = "16" # or [mysql] min_version = "11.4" (MariaDB's numbering)
Use what the app's docs or code require, not just today's version.
| What | Today | For the app |
|---|---|---|
| PostgreSQL | 17.6 | needs = ["postgres"] |
PostgreSQL extensions the app can enable (CREATE EXTENSION in its migrations) |
btree_gin, btree_gist, citext, cube, fuzzystrmatch, hstore, intarray, isn, lo, ltree, pg_trgm, pgcrypto, seg, tablefunc, unaccent, uuid-ossp, ... | |
| Extensions only the Core can enable | vector (pgvector 0.8.1), pg_stat_statements, dblink, postgres_fdw, ... | [postgres] extensions = ["vector"] in coreapp.toml |
| MariaDB | 12.1.2 | needs = ["mysql"] |
| Authelia | 4.39 | needs = ["sso"]: OpenID Connect sign-in with Core accounts |
| Mail server | docker-mailserver 16 | needs = ["email"]: sending, SMTP with STARTTLS |
| Traefik | 3.7 | HTTPS and the certificate in front of every app |
| Docker, Compose | 29, 5.1 | one container per app |
| Machine | x86_64, 4 CPUs, 7.7 GB memory (the dev VM) | build images for linux/amd64; /data is on btrfs |
What's inside the image is the app's own: its language runtime, SQLite and
other libraries are whatever the Dockerfile installs, not the Core's.
SQLite in /data is a fine database for an app that supports it. An
app's SQLite mode is often its single-user mode, though: if its multi-user
edition insists on PostgreSQL or MySQL, allow SQLite there when it runs on
a Core (CORE_DOMAIN set), rather than using the single-user edition.
Needs
Needs can be added to an installed app (deploy sets them up) and dropped
(deploy removes them once the new version answers; if it doesn't, the
update rolls back with them intact). Dropping sso or email removes the
sign-in client or mail account and their settings. Dropping postgres or
mysql deletes the app's database, so deploy refuses it unless the user
asks for that: coreapp deploy --drop-database, which asks them to type
the app's name. That's the user's decision; don't run it on your own.
Switching between postgres and mysql is dropping one and adding the
other: the data doesn't move.
postgres: its own database
The Core makes a PostgreSQL user and database just for this app, and adds:
| Variable | Value |
|---|---|
DB_HOST |
postgresql.<domain> (resolves only on the Core's network, which the app is on) |
DB_PORT |
5432 |
DB_NAME, DB_USER |
coreapp_<name> with - as _ (e.g. coreapp_my_app) |
DB_PASSWORD |
random |
The server is the Core's PostgreSQL (its version and extensions: "What the
Core offers"; check the app's needs against them first), shared with the
Core's other apps; the app owns its database and nothing else. There's no
superuser access, so the app creates its own tables (migrations at startup
are the usual way). Extensions the app's user can't make (vector and the
others "only the Core can enable") go in coreapp.toml; the installer
makes them, as the superuser, before the app starts:
[postgres]
extensions = ["vector"] # pgvector, for the app's embeddings
List only those the app's migrations need (trusted ones may be listed
too, which is harmless; dependencies, like cube for earthdistance, come
with them). A migration's own CREATE EXTENSION IF NOT EXISTS vector then
passes; one without IF NOT EXISTS fails, so change it. An extension the
Core doesn't have (postgis today) is refused at deploy: report it. Taking
one off the list keeps it in the database, since the data may use it. At
boot the
database may come up after the app: retry the connection instead of
exiting. Many apps want a URL; build it from these variables in the
entrypoint or the app's config (e.g.
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).
[mysql] min_version works as for postgres; there are no extensions.
sso: sign-in with Core accounts
The Core registers the app as an OpenID Connect client with its Authelia, and adds:
| Variable | Value |
|---|---|
OIDC_ISSUER |
https://authelia.<domain> |
OIDC_CLIENT_ID |
coreapp-<name> |
OIDC_CLIENT_SECRET |
random |
By default the client's redirect URI is $APP_URL/auth/callback, PKCE
(S256) is required and the secret goes in the Authorization header
(client_secret_basic). Many apps have a fixed callback path or no PKCE:
then fit the client to the app with [sso] in coreapp.toml (callback,
pkce, token_auth), never with a workaround in the app. Use the app's
own OpenID Connect support ("generic OIDC" settings) with OIDC_*.
Two rules for who may do what, on every Core:
- The Core's admin is the app's admin.
CORE_ADMIN_EMAIL(admin@<domain>, the Core's own admin) is always an admin of the app: made one (again) on each Core sign-in, trusted only from the email Authelia gives, never from an address typed into the app. No setup link, no first-come owner; it signs in only with the Core. - Everyone else gets the lowest role that can look around. Any other Core account may sign in, without an invitation, as a read-only member (a viewer). The app's admins raise people from there. In an app where each person has only their own private things (a feed reader, notes), a regular user is the lowest role.
Before writing sign-in code, read
references/sign-in.md: how to find what the app
needs for [sso], how to build the two rules into the app (first-run
setup, password reset), what Authelia tells the app (its groups are
empty today), and how to test sign-in with coreapp signin.
email: sending mail
The Core makes a mail account just for this app, for sending (no inbox), and adds:
| Variable | Value |
|---|---|
SMTP_HOST |
mail.<domain> (the Core's mail server; valid certificate) |
SMTP_PORT |
587 |
SMTP_SECURITY |
starttls (connect, then STARTTLS; not implicit TLS) |
SMTP_USER |
coreapp-<name> |
SMTP_PASSWORD |
random |
SMTP_FROM |
<name>@<domain>, the address to send from |
Most apps have SMTP settings; map these onto them. Mail to SMTP_FROM
isn't delivered anywhere (the account has no mailbox), so set a reply-to
if people should be able to answer. The account can't sign in to anything
else on the Core. coreapp new --email adds the need (there's no example
app for it). There's no inbox to check that a test message arrived: send
one the app's usual way (e.g. a password reset for coreapp.test@<domain>),
then coreapp mail: what the Core's mail server did with each message from
the app's account in the last day (accepted, then delivered, deferred or
bounced, with the reason). Mail to coreapp.test@<domain> is accepted and
then deferred ("451 ... Temporary internal error"), because the test
account has no mailbox; that's expected and shows the app's sending
works. Ask the user to confirm delivery to a real address.
Not available yet
A newer database server than the Core's (an app that needs PostgreSQL 18:
if the app also supports SQLite, that in /data is a fine choice, and say
so in your report; otherwise set min_version, which refuses on this
Core, and report it), the Core's AI features (offering
tools to its AI agent, or using its model), extra services such as Redis or
a second container, extra hostnames, and public ports other than HTTPS.
If the app can't work without one of these, say so plainly in your report
rather than working around it; the gap is useful to know. The same goes for
a need that doesn't fit the app (e.g. a sign-in [sso] can't describe):
report it rather than writing a proxy, bridge or second service into the
app's container. If it's optional
(e.g. email notifications), leave it off and note it.
Workflow
1. Check the tools
command -v coreapp && coreapp-vm list
coreapp core # what this Core offers apps, with versions
coreapp-vm list should show the VM coreserver running. If coreapp is
missing or the VM isn't running, stop and tell the user: setting those up
(installing coreapp-dev, creating and provisioning the Core) is theirs to do
(coreapp-vm start only starts an existing VM).
2a. A new app
coreapp new my-app # plain (a static page on busybox)
coreapp new --postgres my-app # with a database (Python example)
coreapp new --sso my-app # with sign-in (Python example)
coreapp new --postgres --sso my-app # both
It makes ./my-app with a working example, coreapp.toml and a README.
Replace the example with the real app.
2b. An existing app (porting)
Work in the app's repository. Add coreapp.toml (copy the example above),
and make the Dockerfile fit the Core:
-
Listen on
0.0.0.0and onport, plain HTTP. No TLS in the app. -
Know its public address:
APP_URL(many apps need a "base URL" or "trusted host" setting). It's behind traefik, which sendsX-Forwarded-Proto: httpsandX-Forwarded-For: set the app's "trusted proxies" toCORE_PROXY(so it logs and rate-limits by the real client address), and turn on its "behind HTTPS" or secure-cookie setting if it has one, since it sees plain HTTP itself. -
Keep state in
/data: point upload folders, SQLite files and generated keys there. If the app needs a directory structure under/data, create it at startup (it starts empty). -
Send mail with
needs = ["email"], if the app sends any (password resets, notifications): mapSMTP_*onto its mail settings. -
If the app also runs elsewhere (a desktop or another server edition sharing the Dockerfile), keep those working: choose the Core's behaviour in the app when
CORE_DOMAINis set (the Core's variables become defaults; the app's own explicit settings still win), not by changing the Dockerfile'sENVorENTRYPOINTfor everyone. The Core builds theDockerfileat the repository's root. Where the app's settings have another shape (a mail URL instead ofSMTP_*, a database URL, a hex key), build them from the Core's variables where the app loads its settings, so its command-line tools (coreapp shell '<app> ...') get them too, not only the server started by the entrypoint. -
Read settings from the environment, mapping the Core's names to the app's in an entrypoint script or config file if they differ (
SECRET_KEY="$APP_SECRET",DATABASE_URL=...). In an entrypoint for an upstream image, set the app's variables outright rather than "only if unset": the image's ownENVdefaults (a SQLite path, a port) would win otherwise, and on a Core nobody else sets them. (In the app's own code, as above, the Core's values are defaults that the app's explicit settings override: that's for its other editions, not upstreamENV.) Before writing the entrypoint, look at how the upstream image starts (docker inspect -f '{{json .Config.Entrypoint}} {{json .Config.Cmd}}' <image>): end yours by running what it ran (execits entrypoint with"$@", orexec "$@"when it only has aCMD). -
Wait for what it needs at startup if it only checks once: the database may come up after the app on a reboot, and Authelia restarts when the app's sign-in client is registered (on the first deploy, and when
[sso]changes). An app that fetches Authelia's discovery only at startup then has no sign-in until restarted, so wait in the entrypoint, with a time limit, e.g.until wget -qO /dev/null "$OIDC_ISSUER/.well-known/openid-configuration"; do sleep 2; done(andnc -z "$DB_HOST" "$DB_PORT"for the database). -
Images without a shell (built
FROM scratchor distroless) can't run an entrypoint script, andcoreapp shellcan't open one. Copy a static busybox in and run the script with it:FROM busybox:1.37-musl AS busybox FROM upstream/image:1.2.3 COPY --from=busybox /bin/busybox /bin/busybox COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/bin/busybox", "sh", "/entrypoint.sh"](end it with
execand the upstream entrypoint; call tools as/bin/busybox mkdir ...). Prefer this to a program of your own. -
Run as a non-root user if the image allows.
/datais given to whatever user the image runs as, so this is enough:RUN useradd --system --uid 1000 --home-dir /data app # Debian-based images USER app(
adduser -S -u 1000 -h /data appon Alpine.) Many upstream images already have a user; use it. -
Give it its own
icon.png: the project's logo, square, as a PNG (convert an SVG or ICO; 256x256 is good). The template's is a placeholder.coreapp deployandpublishsay if it's unusable, not square or under 80 pixels;publishrefuses one the Core can't use. -
Answer on
healthonce ready (a dedicated health endpoint, or/if it returns 2xx-4xx without signing in). -
One container. If the upstream project ships a compose file with several services, keep only the app, use
needs = ["postgres"](or["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
coreapp.toml, icon.png and .git so they don't bust the build cache.
3. Deploy and test
coreapp deploy # check coreapp.toml, build, copy the image, install or update
coreapp check # https://<name>.<domain><health> answers with a valid certificate
Deploying again updates the app in place: same address, same secrets, same data and database. Change something, deploy, look. A new version isn't needed for each try; raise it when you release.
A deploy only replaces the container when something changed (the image or
the settings). To test that data really survives a new container, use
coreapp deploy --recreate, which always starts a fresh one.
coreapp deploy may ask before installing on a Core whose plan bills apps
as add-ons. That question is for the user; don't answer it yourself.
Then test it like a person would: open https://<name>.<domain>/ (curl it,
or ask the user to use a browser), sign in if it has sso, and check that
what it stores survives coreapp deploy --recreate (data in /data and
the database).
For an app with sso, coreapp signin [path] signs in as a browser would,
with the Core's test account (coreapp.test@<domain>), and says whether it
got back to the app signed in; see
references/sign-in.md for its options
(--cookies, --form, --code for single-page apps). The test account
isn't the admin: ask the user to sign in once in a browser as
admin@<domain> before a release.
4. When something fails
| Command | Shows |
|---|---|
coreapp status |
Its container, address, port, needs, URL, and the Core's PostgreSQL or MariaDB version if it needs one |
coreapp mail |
What the Core's mail server did with the mail it sent (apps with email) |
coreapp logs / coreapp logs -f |
The app's own log |
coreapp signin [path] |
Signs in with the Core's test account and shows each step |
coreapp shell '<command>' |
Run one command in its container, e.g. coreapp shell 'id; env; ls -l /data' (without a command it opens an interactive shell, which needs a terminal) |
coreapp list |
All apps on the Core installed this way |
coreapp remove |
Uninstall it (asks first; deletes its data and database) |
Common causes:
- "doesn't answer at http://192.168.5.x:PORT/...": the app crashed (see
coreapp logs), listens on another port or on 127.0.0.1, orhealthpoints at a path that fails or redirects to an error. - "Rolled back": an update failed, so the Core put back the version that
ran before, with its settings, its database and
/dataas they were before the update (/dataonly where the Core's filesystem can copy it instantly; the message says), and undid needs the update added. Whatever the failed version wrote is gone. Its log is printed above that line (coreapp logsnow shows the old version's). When the version wasn't raised, the image that failed is the one running again. - "keeps a copy of its database ... Nothing was changed. Free some space first.": before an update the Core copies the app's database, to roll back to, and the apps' disk hasn't room for it (it keeps 1 GB free for the Core). That's the user's to sort out; tell them. With a big database, updates say they take a while for the same reason.
coreapp checkfails but deploy worked: a new certificate can take a minute; it retries for two. It also tries the VM directly, which tells the app apart from the way in.- Sign-in fails:
coreapp signinshows Authelia's error and hint; what each means is at the end of references/sign-in.md. - Permission denied under
/data: the app switches to another user after starting (the Core gives/datato the image'sUSER), or it writes somewhere else in the container (coreapp shell 'id; ls -ld /data').
The installer's own log (the Core's install scripts) is on the Core in
/federated/logs/coreapps/. It contains secrets, so don't print it in full;
look at the end of it with coreapp-vm ssh tail -n 40 /federated/logs/coreapps/<name>-install.log
only when a deploy fails in the installer itself.
5. Publishing (only when the user asks for a release)
Publishing pushes the image to the user's registry and tags their repository; installing a release from its repository is how a Core's owner gets it. For both, read references/publishing.md.
Reporting back
When you're done, tell the user:
- what you changed in the repository (
coreapp.toml, Dockerfile, config), - what you tested and how (deploy, check, which pages, a redeploy keeping
data,
coreapp signin), and what they still need to test themselves (signing in in a browser asadmin@<domain>), - anything the app needs that the Core doesn't offer yet, and how you handled it,
- anything in coreapp-dev that got in the way or was unclear. coreapp-dev is new, and this is how it gets better.