coreapp: make, deploy and test apps on the Core in the VM
Apps are folders in Federated Core's generic services format (service, docker-compose.yml.in, env.in, install, uninstall, icon.png) plus their own Dockerfile. coreapp new scaffolds one from templates/app with an address in 192.168.200.x; deploy builds the image, copies it to the Core over SSH, installs it with installapp (and starts it, since the Core's start only knows its own apps) or updates it keeping .env; check, status, logs, shell and remove work on the Core. Apps in development aren't registered with Federated's monitoring: deploy drops MONITOR from the Core's copy of service. installapp/uninstallapp traces go to private logs, not the terminal. update.sh installs docker and docker-buildx and links coreapp into ~/.local/bin. PLAN.md: how the Core runs apps, and corrected evidence for the Core's timers running their jobs at every boot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -48,12 +48,115 @@ What we learned provisioning (2026-12-02/03):
|
||||
`systemd-networkd-resolve-hook.socket` starts it at boot, it takes
|
||||
port 53 and pdns can't start after a reboot. coreapp-dev masks it
|
||||
through cloud-init; the installer should mask it too
|
||||
- `upgrade-federated.timer` has `Requires=upgrade-federated.service`, so
|
||||
the upgrade runs at every boot, not just at 5:00. It fails there
|
||||
(exit 2), and on the first reboot it removed the pdns container that
|
||||
couldn't start
|
||||
- Every Core timer (upgrade-federated, free-up-space, backuptool,
|
||||
dumpcerts, fix-nextcloud, nextcloud-maintenance) has
|
||||
`Requires=<its service>` in `[Unit]`, so its job also runs at every
|
||||
boot, about 5 s in, not just on its schedule. Evidence (2026-12-03):
|
||||
boots at 18:01:20 and 18:14:08 UTC; all four checked jobs started at
|
||||
18:01:25 and 18:14:13. Consequences:
|
||||
- upgrade-federated runs before the network is online (it has no
|
||||
`After=network-online.target`): `git pull` fails with "Could not
|
||||
resolve host: gitea.federated.computer", then `send_alert_upgrade`
|
||||
emails ALERTS_EMAIL ("upgrade failed to run on <ip> - couldn't
|
||||
pull from git") and posts a Matrix alert, and it exits 2
|
||||
(`/federated/logs/upgrade.log`). So every reboot sends a false
|
||||
alert
|
||||
- free-up-space runs `docker system prune -f` and
|
||||
`docker image prune -a --filter until=24h` while containers are
|
||||
still starting: at 18:01:25 it deleted the pdns container that
|
||||
had failed to start (port 53) and its image
|
||||
(`/federated/logs/freeupspace.log`). Any app container that is
|
||||
stopped at boot time goes the same way
|
||||
- `/federated/bin/upgrade` has an API token in it, readable by anyone
|
||||
with the image
|
||||
with the image; `lib/functions.sh` has the monitoring registrar's
|
||||
bearer token, and `uninstallapp`'s `set -x` prints it
|
||||
- `bin/start` doesn't know apps outside its fixed lists, so a new
|
||||
app in the generic format isn't started by `installapp`
|
||||
|
||||
## Next: the SDK (build, deploy and test an app on the Core)
|
||||
|
||||
### How the Core runs apps (studied 2026-12-03 on dev.fedcom.net)
|
||||
|
||||
- `/federated` is a git checkout of Federated's `Core` repo, updated by
|
||||
`/federated/bin/upgrade` (`git pull`). Untracked folders survive pulls.
|
||||
- Installed apps live in `/federated/apps/<app>/`: `docker-compose.yml`,
|
||||
`.env` (mode 600), secrets in files, data under `data/`.
|
||||
- Every container is on the external Docker network `core`
|
||||
(192.168.0.0/16) with a fixed `ipv4_address`. Federated's apps use
|
||||
192.168.0.7 to .121.
|
||||
- traefik (`providers.docker`, `exposedByDefault=false`) routes by labels:
|
||||
`traefik.enable=true`, `routers.<app>.rule=Host(`<app>.<domain>`)`,
|
||||
`entrypoints=websecure`, `tls.certresolver=letsencrypt` (DNS challenge
|
||||
through the Core's own pdns, so any hostname gets a certificate), and
|
||||
`services.<app>.loadbalancer.server.port` when the port isn't 80.
|
||||
- DNS: the zone has `*.<domain>` CNAME `www.<domain>` (the public IP), so
|
||||
every app hostname already resolves. Some apps also add their own A record.
|
||||
- `/federated/bin/installapp [-n] <app>` installs an app from either
|
||||
- `lib/<app>.sh` with `config_<app>`, `start_<app>`, `uninstall_<app>` and
|
||||
optionally `configsso_<app>` (Authelia OIDC) and `email_<app>`; or
|
||||
- the newer generic format, `services/<app>/`:
|
||||
- `service`: `NAME`, `DESCRIPTION`, `DOCS`, `CONTAINER`, `VERSION`,
|
||||
`INTERNAL_IP`, `DEPENDS`, `PORTS`, `MONITOR="https://<app>.@DOMAIN@|http_2xx"`
|
||||
- `docker-compose.yml.in` and `env.in`: templates. `@DOMAIN@` and other
|
||||
variables from `/etc/federated`; `@IMAGE_VERSION@`;
|
||||
`@NAME:RANDOM:LLLL...@` makes a random value (L = letter or digit)
|
||||
- `icon.png`
|
||||
- `install`: `. /federated/lib/helpers.sh` and `installGeneric <app>`
|
||||
(fills in the templates into `/federated/apps/<app>/`); installapp
|
||||
then runs `/federated/bin/start <app>`
|
||||
- optional `uninstall`, `timers/`, `services/` (systemd units)
|
||||
- installapp installs `DEPENDS` first; `uninstallapp <app>` reverses it.
|
||||
- superpanel's catalog lists `services/*/service`, so an app installed this
|
||||
way shows up in the Core's dashboard.
|
||||
|
||||
### Design (proposed)
|
||||
|
||||
An app is a folder in the generic format, kept anywhere on the workstation
|
||||
(its own git repo). A `coreapp` command, run inside that folder, works
|
||||
against the Core in the local VM (`coreapp-vm ip`):
|
||||
|
||||
- `coreapp new <name>`: scaffold the folder: `service`,
|
||||
`docker-compose.yml.in` with the traefik labels, `env.in`, `install`, a
|
||||
placeholder `icon.png`, a `Dockerfile` with a minimal web server, and a
|
||||
README. Its `INTERNAL_IP` comes from 192.168.200.0/24, well away from
|
||||
Federated's 192.168.0.x, and different for each app made on this machine.
|
||||
- `coreapp deploy`: build the image locally (`docker build`), copy it to the
|
||||
Core (`docker save | ssh docker load`, no registry needed), copy the folder
|
||||
to `/federated/services/<name>/`, then `installapp -n <name>` the first
|
||||
time. Later deploys re-render `docker-compose.yml` but keep `.env` (its
|
||||
random secrets), and restart the app.
|
||||
- `coreapp status`, `coreapp logs [-f]`, `coreapp shell`: on the Core.
|
||||
- `coreapp check`: the app answers at `https://<name>.<domain>/` as its
|
||||
`MONITOR` line says, with a valid certificate.
|
||||
- `coreapp remove`: `uninstallapp <name>` and remove its services folder.
|
||||
|
||||
Built and tested 2026-12-03 with a test app `hello` (busybox httpd):
|
||||
new, deploy (first install and redeploy), check, status, logs, remove all
|
||||
work against dev.fedcom.net; `https://hello.dev.fedcom.net/` answers through
|
||||
the relay.
|
||||
|
||||
What we learned:
|
||||
- `/federated/bin/start <app>` only starts apps in the fixed `CORE_APPS` /
|
||||
`EXTRA_APPS` lists in `lib/functions.sh`; for anything else it prints its
|
||||
usage. So `installapp` installs a new app but doesn't start it, and
|
||||
`start all` skips it. `coreapp deploy` starts it with the same
|
||||
`docker compose ... up -d`; `restart: always` covers reboots
|
||||
- `installapp` / `uninstallapp` call `update_monitors`, which registers or
|
||||
removes the app's `MONITOR` URL with Federated's external monitoring
|
||||
(blackboxregistrar.monitoreast.fedcom.net). Dev apps get registered too
|
||||
- `uninstallapp` runs with `set -x`; its trace includes the monitoring
|
||||
registrar's bearer token (in plain text in `lib/functions.sh`) and the
|
||||
Core's email addresses. coreapp keeps the trace in
|
||||
`~/.local/share/coreapp-dev/logs/` (mode 600)
|
||||
- `uninstallapp` only stops a generic app if the app has an `uninstall`
|
||||
script (sourced, so no `exit`); the template has one
|
||||
|
||||
- Decided 2026-12-03: apps in development are not registered with
|
||||
Federated's monitoring. `coreapp deploy` drops `MONITOR` from the copy of
|
||||
`service` on the Core
|
||||
- [ ] Document the app format fully in the README (done in each app's README)
|
||||
- [ ] Later: a database (`DEPENDS=postgresql`), SSO through Authelia, apps
|
||||
published for other Cores (registry, submitting to Federated)
|
||||
|
||||
## SDK packaging
|
||||
|
||||
|
||||
Reference in New Issue
Block a user