--- name: coreapp description: 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://.`, 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://.` and forwards to that port. - `/data` inside the container: kept on the Core across updates, restarts and reboots. The Core makes it belong to the user the image runs as (`USER` in the Dockerfile) before starting the container, so the image doesn't need to create or chown `/data` itself (what the image has at `/data` is 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 `.env` file made once at install; updates keep the values and add new ones): | Variable | Value | |---|---| | `APP_URL` | `https://.`, the app's public address | | `APP_SECRET` | 32 random letters and digits, for signing cookies, sessions | | `IMAGE_VERSION` | The installed version (`coreapp deploy` builds with plain `docker build .`, no build args, so read the version from here, not a build-time `VERSION`) | | `CORE_DOMAIN` | The Core's domain (``). Set only on a Core: an app that also runs elsewhere can use it to tell | | `CORE_ADMIN_EMAIL` | `admin@`, the Core's admin account: always an admin of the app (see `sso`) | `APP_SECRET` isn't hex or base64: an app that wants key bytes (e.g. 32 bytes for encryption) derives them, e.g. SHA-256 of `APP_SECRET`. It never changes, and it lives only in the app's `.env` on the Core (`/federated/apps//.env`, beside `/data`): anything encrypted with it is unreadable without that file. plus the ones each need adds (below). ## coreapp.toml ```toml name = "my-app" # id and hostname: https://my-app. 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, use `localhost/coreapp/`: `coreapp deploy` builds it here and copies it to the Core, and it can't be pulled from anywhere by mistake. (A name without a registry, like `me/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: .`, `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 check` wants 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. | 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, ... | not available to apps yet: report it | | 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. ## Needs ### `postgres`: its own database The Core makes a PostgreSQL user and database just for this app, and adds: | Variable | Value | |---|---| | `DB_HOST` | `postgresql.` (resolves only on the Core's network, which the app is on) | | `DB_PORT` | `5432` | | `DB_NAME`, `DB_USER` | `coreapp_` with `-` as `_` (e.g. `coreapp_my_app`) | | `DB_PASSWORD` | random | The server is PostgreSQL 17 (17.6 today; `coreapp status` shows the Core's version), shared with the Core's other apps; the app owns its database and nothing else. Check what version the app needs before choosing this (its docs, its own compose file's `postgres:` image, its migrations): features of a newer PostgreSQL fail only when the code that uses them runs, so a deploy, `coreapp check` and a sign-in can all pass on the wrong version. If it needs a newer one, see "Not available yet". There's no superuser access, so the app creates its own tables (migrations at startup are the usual way). 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.` (resolves only on the Core's network) | | `DB_PORT` | `3306` | | `DB_NAME`, `DB_USER` | `coreapp_` 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 The Core registers the app as an OpenID Connect client with its Authelia, and adds: | Variable | Value | |---|---| | `OIDC_ISSUER` | `https://authelia.` | | `OIDC_CLIENT_ID` | `coreapp-` | | `OIDC_CLIENT_SECRET` | random | The client, by default: - Redirect URI: exactly `https://./auth/callback` (`$APP_URL/auth/callback`). - Authorization code flow, PKCE with S256 required, client authentication `client_secret_basic` (secret in the Authorization header). If the app's sign-in can't be configured to match (many have a fixed callback path, and many don't send PKCE), change the client in `coreapp.toml` instead of working around it in the app: ```toml [sso] callback = "/auth/openid/core" # the app's callback path (default "/auth/callback") pkce = false # the app doesn't send PKCE (default true) token_auth = "client_secret_post" # it sends the secret in the form (default client_secret_basic) ``` Set only what the app needs, and say in a comment why. Find out from the app's documentation or source: the callback path it puts in `redirect_uri` (sometimes built in the browser, e.g. `/auth/openid/`; then pick the key so the path is known), whether it sends `code_challenge`, and how it sends the secret. Authelia checks the redirect URI when the sign-in starts (an error page instead of its login page if it's wrong), but PKCE and the secret only after the person has signed in, so a curl of the authorize URL can't show those are right: `coreapp signin` can (see "Deploy and test"). Changing `[sso]` and deploying registers the client again; Authelia restarts for it (a few seconds of 404s from it, which an app checking discovery at startup may log; it should retry). - Scopes: `openid profile email groups`. Userinfo gives `sub`, `preferred_username`, `name`, `email`, and `groups`, which is empty on today's Cores: they have two groups, `admins` and `everybody`, but Authelia's settings don't find them yet (for Federated to fix). Read `groups` if the app can use it, but don't depend on it for roles. - **The app's admin is the Core's admin.** On a Core, the account `CORE_ADMIN_EMAIL` (`admin@`, the Core's own admin, as in Federated's apps) is always an admin of the app, from its first sign-in: no setup link, no first-come owner. It can then make other people admins in the app. Two rules: - Trust it only from the Core's sign-in: the `email` in Authelia's userinfo or ID token, compared case-insensitively. Never make a local account, a sign-up or an invitation with that address an admin; anyone could type it. - Every time, not only the first: if its admin role was taken away in the app, its next Core sign-in gives it back. If the app has its own first-run setup (an owner to create, a setup link), skip it on a Core: the Core's admin is the owner. If the app can't run without an owner (its pages say "not set up" until there is one), make `CORE_ADMIN_EMAIL` the owner at startup, without a password; it signs in with the Core. The example app (`coreapp new --sso`) shows the check in `oidc.py`. `coreapp signin` signs in as the test account, not the admin, so ask the user to sign in once as `admin@` in a browser and check it gets the admin pages. - **Everyone else gets the lowest role.** Any other Core account (a person at the company) may sign in, with no invitation, and gets the app's lowest role (viewer, or whatever can do least). The app's admins raise people from there in the app. Don't hand out more by default, and don't require invitations for Core accounts. `coreapp signin` checks this: the test account should land with that role. - Discovery: `$OIDC_ISSUER/.well-known/openid-configuration`. The Core routes `authelia.` from inside the app's container to the real HTTPS endpoint, with a valid certificate, so normal TLS verification works. - Sign-out in the app ends the app's session; the person stays signed in to the Core. Use the app's own OpenID Connect support or its framework's library where it has one: most self-hosted apps have "generic OIDC" settings that map onto these variables. If the app has its own step for setting up its client (an admin makes a secret in its settings, or pastes a client block into the identity provider), skip it on the Core: fill its settings from `OIDC_*`, so sign-in works with no admin step, and don't show those instructions when the Core gave the client. For a standard-library Python example of the whole flow, `coreapp new --sso example` makes one (`oidc.py`). ### `email`: sending mail The Core makes a mail account just for this app, for sending (no inbox), and adds: | Variable | Value | |---|---| | `SMTP_HOST` | `mail.` (the Core's mail server; valid certificate) | | `SMTP_PORT` | `587` | | `SMTP_SECURITY` | `starttls` (connect, then STARTTLS; not implicit TLS) | | `SMTP_USER` | `coreapp-` | | `SMTP_PASSWORD` | random | | `SMTP_FROM` | `@`, 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@`) and check `coreapp logs` for mail errors; 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), 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 ```bash 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 ```bash 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.0` and on `port`**, 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 a proxy that sends `X-Forwarded-Proto: https` and `X-Forwarded-For`). - **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): map `SMTP_*` 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_DOMAIN` is set (the Core's variables become defaults; the app's own explicit settings still win), not by changing the Dockerfile's `ENV` or `ENTRYPOINT` for everyone. The Core builds the `Dockerfile` at the repository's root. Where the app's settings have another shape (a mail URL instead of `SMTP_*`, 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 ' ...'`) 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=...`). Set the app's own variables outright rather than "only if unset": upstream images often set defaults in `ENV` (a SQLite path, a port) that would win otherwise. - **Images without a shell** (built `FROM scratch` or distroless) can't run an entrypoint script, and `coreapp shell` can't open one. Copy a static busybox in and run the script with it: ```dockerfile 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 `exec` and 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. `/data` is given to whatever user the image runs as, so this is enough: ```dockerfile RUN useradd --system --uid 1000 --home-dir /data app # Debian-based images USER app ``` (`adduser -S -u 1000 -h /data app` on 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 deploy` and `publish` say if it's unusable, not square or under 80 pixels; `publish` refuses one the Core can't use. - **Answer on `health`** once 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 ```bash coreapp deploy # check coreapp.toml, build, copy the image, install or update coreapp check # https://. 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://./` (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). Sign in with `coreapp signin`: it signs in to the app as a browser would, on the real Authelia with the app's real client, as the Core's test account (`coreapp.test@`, display name `coreapp.test`, in no groups; made on the Core in the VM when first needed, with a new password each time). It prints each step, with Authelia's error if the client doesn't fit, and says whether it got back to the app signed in: ```bash coreapp signin # starts at /login coreapp signin /auth/login # the app's own page that starts sign-in coreapp signin /signin # a page whose button starts sign-in: pressed coreapp signin --cookies jar /login && curl -b jar https://./api/me ``` A page with a sign-in button (a form with only hidden fields, such as a CSRF token) is submitted as a person pressing it would; with several such forms, pick one with `--form `. Don't add routes to the app just for the test. For apps whose sign-in starts in the browser's JavaScript (single-page apps: the page builds the authorize URL itself), `coreapp signin --code` starts at Authelia with the app's client and stops at the app's callback, printing it with the code; give that to the app as its page would (e.g. Vikunja's: `POST /api/v1/auth/openid//callback` with `code` and `redirect_url`). Its `state` is not the app's, so a callback that checks state (a server-side callback page) refuses it: use the path form for those. Authelia bans an account for a few minutes after repeated failed sign-ins, so don't loop on it. Still ask the user to sign in once in a browser before a release, as the Core's admin (`admin@`): it checks what a script can't (the app's pages, and that the admin gets the admin role). ### 4. When something fails | Command | Shows | |---|---| | `coreapp status` | Its container, address, port, needs, the Core's database version, URL | | `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 ''` | 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, or `health` points 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 `/data` as they were before the update (`/data` only 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 logs` now shows the old version's). When the version wasn't raised, the image that failed is the one running again. - `coreapp check` fails 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 signin` shows Authelia's error and hint): "The 'redirect_uri' parameter does not match" means the app's callback isn't the client's (`[sso] callback`); "invalid_client" means it sends the secret another way (`[sso] token_auth`); a PKCE error means `[sso] pkce` doesn't match what the app does. - Permission denied under `/data`: the app switches to another user after starting (the Core gives `/data` to the image's `USER`), 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/-install.log` only when a deploy fails in the installer itself. ### 5. Publishing (when the user asks for a release) A published app is a tagged commit in its repository plus its image in a registry, from which any Core can install it. Only publish when the user asks: it pushes to their registry and tags their repository. 1. Set `image` in `coreapp.toml` to the registry: for an app on a Gitea server, `//` in lowercase (Gitea's container registry is on the same host). `coreapp publish` suggests one from the git remote. `coreapp deploy` keeps working with that name. 2. Raise `version` if this version was published before (published versions are never replaced). 3. Commit everything; `coreapp publish` refuses uncommitted changes. 4. `coreapp publish` builds the image for linux/amd64 (add `--platform linux/amd64,linux/arm64` for ARM Cores too), pushes `image:version`, and tags the commit `v`. It needs `docker login ` first; that's the user's to do (for Gitea, with a token that has the `write:package` scope). 5. The user pushes the commit and tag: `git push && git push origin v`. New apps also have `.gitea/workflows/publish.yml`, which does the same on the Gitea server when a `v*` tag is pushed, if the repository has an Actions runner that can use Docker and the secrets `REGISTRY_USER` and `REGISTRY_TOKEN`. When porting an existing app, copy it from a new app (`coreapp new x`) if the user wants it. To check a release the way a Core's owner will get it: `coreapp install https:////` installs it on the Core in the VM from the repository (the newest `v*` tag; `@v1.2.0` for another), pulling the published image, and `coreapp update ` moves it to a newer release. Coreapps are often private: for a private repository and image, the Core needs a token for the host first, `coreapp login `, which asks for a user name and a read-only token (repositories and packages). That's the user's to enter, not yours. The Core only reads `coreapp.toml` and `icon.png` from the repository; `version` has to match the tag. On the same Core, `coreapp deploy` from the folder and `coreapp install` from the repository update the same app (same name, data and database). A Core keeps running the image it installed, by digest: a release can't be fixed by pushing its tag again (installing it again is refused), so publish a new version. Going back to an older release needs `coreapp install --downgrade @v`; the user decides that, since the older version may not understand the newer one's data. ## 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 with their own account), - 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.