--- 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 (PNG, up to 1 MB; optional) | 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 | 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 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 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. ## 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 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). 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 is fixed, so the app has to fit it: - Redirect URI: exactly `https://./auth/callback` (`$APP_URL/auth/callback`). If the app's library uses another callback path, configure the library, or route `/auth/callback` to it. - Authorization code flow, PKCE with S256 required, client authentication `client_secret_basic` (secret in the Authorization header). - Scopes: `openid profile email groups`. Userinfo gives `sub`, `preferred_username`, `name`, `email`, `groups` (the person's Core groups: use them for roles, e.g. admins). - 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. 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). ### Not available yet 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. 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-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. - **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=...`). - **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. - **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). Signing in needs a real Core account and a browser: ask the user to do that step and tell you what happened. ### 4. When something fails | Command | Shows | |---|---| | `coreapp status` | Its container, address, port, needs, URL | | `coreapp logs` / `coreapp logs -f` | The app's own log | | `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, and undid needs the update added. The failed version's log is printed above that line (`coreapp logs` now shows the old version's). Its data and database aren't rolled back. 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 with "redirect_uri" errors: the app isn't using `$APP_URL/auth/callback`. "invalid_client": it isn't sending the secret with `client_secret_basic`, or isn't using PKCE. - 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). ## 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), and what they still need to test themselves (signing in in a browser), - 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.