Add the coreapp skill; fix /data ownership; deploy --recreate, shell <cmd>
skills/coreapp/SKILL.md teaches a Claude Code agent to make or port an app for Federated Core: coreapp.toml, the needs, porting an existing app, the deploy and test loop, troubleshooting, what isn't supported yet and how to report back. update.sh links it into ~/.claude/skills/coreapp; uninstall.sh removes the link. Rehearsed with a small app (memo-board) ported by a fresh agent using only the skill. The installer now gives /data to the image's user before starting the container: Docker created it as root, so non-root apps couldn't write. coreapp deploy --recreate always starts a new container (to test that data survives); coreapp shell '<command>' runs one command without a terminal. PLAN.md: what would change on the Core to put the installer in /federated/bin/coreapps/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,6 +157,9 @@ What we learned:
|
|||||||
reaches `https://authelia.<domain>` through traefik (`extra_hosts` to
|
reaches `https://authelia.<domain>` through traefik (`extra_hosts` to
|
||||||
traefik's address; Federated's apps use the public IP, which here would
|
traefik's address; Federated's apps use the public IP, which here would
|
||||||
loop out through the relay)
|
loop out through the relay)
|
||||||
|
- `/data` is a bind mount Docker creates as root, so an app running as
|
||||||
|
another user couldn't write there. The installer gives it to the image's
|
||||||
|
user (`Config.User`, resolved with `id` in the image if it's a name)
|
||||||
- Image names must include the registry: `coreapp/x` means Docker Hub, so a
|
- Image names must include the registry: `coreapp/x` means Docker Hub, so a
|
||||||
Core that had to pull it (after its boot-time prune, say) would get
|
Core that had to pull it (after its boot-time prune, say) would get
|
||||||
whatever is published there. Dev images are `localhost/coreapp/<name>`,
|
whatever is published there. Dev images are `localhost/coreapp/<name>`,
|
||||||
@@ -220,9 +223,12 @@ Steps:
|
|||||||
image). Show the source and what the app needs before installing
|
image). Show the source and what the app needs before installing
|
||||||
4. [ ] Email and AI needs (findings below), then other services: PowerDNS
|
4. [ ] Email and AI needs (findings below), then other services: PowerDNS
|
||||||
records beyond the wildcard, if an app needs other hostnames
|
records beyond the wildcard, if an app needs other hostnames
|
||||||
5. [ ] The skill: a Claude Code skill in coreapp-dev (installed by
|
5. The skill (moved ahead of 2-4, 2026-12-03): `skills/coreapp/SKILL.md`,
|
||||||
`update.sh`) that teaches `coreapp.toml`, the needs, the `coreapp`
|
linked into `~/.claude/skills/coreapp` by `update.sh`, so any Claude Code
|
||||||
commands and testing against the VM
|
agent on this computer can use it. Rehearsed with a small app
|
||||||
|
(`memo-board`)
|
||||||
|
- [ ] Test it with David's candidate app: an agent in that repository
|
||||||
|
uses the skill; what it struggles with becomes fixes
|
||||||
6. [ ] The Coreapps screen in Superpanel (Federated's code: needs their
|
6. [ ] The Coreapps screen in Superpanel (Federated's code: needs their
|
||||||
agreement). Until then, the installer could run as a small web app behind
|
agreement). Until then, the installer could run as a small web app behind
|
||||||
Authelia, for admins only
|
Authelia, for admins only
|
||||||
@@ -235,6 +241,71 @@ Later:
|
|||||||
Superpanel for others
|
Superpanel for others
|
||||||
- [ ] Monitoring for published apps (dev apps aren't registered)
|
- [ ] Monitoring for published apps (dev apps aren't registered)
|
||||||
|
|
||||||
|
### The installer in /federated/bin/coreapps/ (wanted, 2026-12-03)
|
||||||
|
|
||||||
|
David wants the installer on the Core in `/federated/bin/coreapps/`
|
||||||
|
instead of `/opt/coreapps`. What may need to change on the Core, for
|
||||||
|
Federated (checked on dev.fedcom.net):
|
||||||
|
|
||||||
|
1. **It has to come from the Core repo.** `/federated` is a git checkout
|
||||||
|
that `upgrade` pulls nightly. An untracked `bin/coreapps/` survives pulls
|
||||||
|
until the repo gets files of the same name; then `git pull` refuses, and
|
||||||
|
the upgrade fails (`bin/upgrade` already has a workaround for exactly
|
||||||
|
this with `bin/sync-calcomusers`). So Federated commits `bin/coreapps/`
|
||||||
|
to the Core repo, and Cores get it and its updates through `upgrade`
|
||||||
|
2. **coreapp-dev stops copying it there.** `coreapp deploy` replaces
|
||||||
|
`/opt/coreapps` on every deploy. Doing that in `/federated/bin/coreapps/`
|
||||||
|
would modify tracked files and break the next `git pull` the same way.
|
||||||
|
Instead coreapp-dev would use the Core's copy, and keep `/opt/coreapps`
|
||||||
|
only as an override for testing installer changes
|
||||||
|
3. **Layout.** Everything else in `/federated/bin` is a single executable
|
||||||
|
that Federated's scripts call by full path. A folder there means the
|
||||||
|
command is `/federated/bin/coreapps/coreapps`. Alternatives: the
|
||||||
|
command as `/federated/bin/coreapps` with its templates and needs in
|
||||||
|
`/federated/lib/coreapps/` (where Federated keeps shared files), or a
|
||||||
|
wrapper. Decide with Federated
|
||||||
|
4. **Python.** The installer needs Python 3.11 or newer (`tomllib`); the
|
||||||
|
Core's scripts are otherwise bash. The image has 3.14 today; Federated
|
||||||
|
would have to keep python3 in the image
|
||||||
|
5. **Superpanel has to run it as root on the host.** Superpanel runs
|
||||||
|
`installapp`/`uninstallapp` already (strings in its binary) but its
|
||||||
|
container only mounts `/federated/lib` (read-only), `/federated/apps`,
|
||||||
|
`/federated/logs` and the Docker socket, not `/federated/bin` or
|
||||||
|
`/federated/services`. How it reaches the host now is still to find out.
|
||||||
|
The Coreapps screen would call `coreapps plan`, `install`, `remove` and
|
||||||
|
`list` the same way
|
||||||
|
6. **Where the apps' files go.** The installer writes
|
||||||
|
`/federated/services/<name>/` (untracked, like the test apps now show in
|
||||||
|
`git status`). It works, and Superpanel's catalog and
|
||||||
|
`installapp`/`uninstallapp` find them there, but they're untracked files
|
||||||
|
in Federated's checkout. Federated may prefer a separate folder (e.g.
|
||||||
|
`/federated/coreapps/<name>/`) with `installapp`, `uninstallapp` and
|
||||||
|
`superpanel-generate-catalog` taught to look there too, and `.gitignore`
|
||||||
|
covering whatever stays in `services/`
|
||||||
|
7. **Starting and stopping.** `bin/start` and `bin/stop` only know the
|
||||||
|
fixed `CORE_APPS`/`EXTRA_APPS` lists, so `installapp` doesn't start a
|
||||||
|
coreapp and `start all`/`stop` skip them (the installer starts them
|
||||||
|
itself). They should also handle apps marked `.coreapp`
|
||||||
|
8. **The nightly upgrade.** `upgrade_federated` goes through installed
|
||||||
|
apps; for a coreapp `VERSION` equals `IMAGE_VERSION`, so nothing happens,
|
||||||
|
which is right (coreapps updates them). But `upgrade_app` reads the
|
||||||
|
current image with `cut -d: -f2`, which breaks on an image whose registry
|
||||||
|
has a port (`gitea.example.com:5000/owner/app`): it would think the image
|
||||||
|
changed and rewrite the compose file wrongly. Either skip apps marked
|
||||||
|
`.coreapp`, or parse the image properly
|
||||||
|
9. **free-up-space.** Its `docker image prune -a --filter until=24h` deletes
|
||||||
|
images of stopped apps. Published apps can be pulled again; a
|
||||||
|
`localhost/` dev image can't. Fine for published apps; for dev it means
|
||||||
|
a stopped test app may need `coreapp deploy` again
|
||||||
|
10. **Monitoring, billing.** `installapp` records non-hidden apps in
|
||||||
|
`ADDON_APPS` on non-enterprise tiers, and would register `MONITOR` URLs
|
||||||
|
(the installer writes none). Federated decides whether third-party apps
|
||||||
|
are billed as add-ons, and whether published apps get monitored
|
||||||
|
11. **Logs.** The installer keeps the Core scripts' output (which contains
|
||||||
|
secrets because of their `set -x`) in `/federated/logs/coreapps/`
|
||||||
|
(mode 700). Federated may want that elsewhere, or fewer secrets in the
|
||||||
|
traces (see "Tell Federated")
|
||||||
|
|
||||||
### What the Core offers apps (studied 2026-12-03)
|
### What the Core offers apps (studied 2026-12-03)
|
||||||
|
|
||||||
Superpanel (`federatedcomputer/superpanel` 26.12.01, a Go binary, at
|
Superpanel (`federatedcomputer/superpanel` 26.12.01, a Go binary, at
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ sibling add https://gitea.federated.computer/Federated_Computer/coreapp-dev.git
|
|||||||
|
|
||||||
This installs libvirt and QEMU/KVM, adds you to the `libvirt` group (log out
|
This installs libvirt and QEMU/KVM, adds you to the `libvirt` group (log out
|
||||||
and back in afterwards), sets up the `coreapp` VM network (10.123.0.0/24) and
|
and back in afterwards), sets up the `coreapp` VM network (10.123.0.0/24) and
|
||||||
installs Docker and the `coreapp-vm` and `coreapp` commands. CoreDesktop's `update` keeps them current.
|
installs Docker, the `coreapp-vm` and `coreapp` commands, and the `coreapp`
|
||||||
|
skill for Claude Code. CoreDesktop's `update` keeps them current.
|
||||||
|
|
||||||
## A Core in a VM
|
## A Core in a VM
|
||||||
|
|
||||||
@@ -78,9 +79,9 @@ 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 deploy` | Build its image, copy it to the Core over SSH, install it, or update it keeping its settings and data |
|
| `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 |
|
||||||
| `coreapp status` / `logs [-f]` / `shell` | Its container, its log, a shell in it |
|
| `coreapp status` / `logs [-f]` / `shell [command]` | Its container, its log, a shell in it (or one command, without a terminal) |
|
||||||
| `coreapp list` | The apps on the Core installed this way |
|
| `coreapp list` | The apps on the Core installed this way |
|
||||||
| `coreapp remove` | Uninstall it from the Core, with its database and sign-in client (asks first) |
|
| `coreapp remove` | Uninstall it from the Core, with its database and sign-in client (asks first) |
|
||||||
|
|
||||||
@@ -134,5 +135,6 @@ stay installed.
|
|||||||
| `templates/app/` | What `coreapp new` starts from |
|
| `templates/app/` | What `coreapp new` starts from |
|
||||||
| `templates/postgres/`, `templates/sso/` | Example apps laid over it by `--postgres` / `--sso`: their files replace the base's; `*.append` files are added to the base file, `.remove` lists base files to drop, `.needs` goes into `needs` |
|
| `templates/postgres/`, `templates/sso/` | Example apps laid over it by `--postgres` / `--sso`: their files replace the base's; `*.append` files are added to the base file, `.remove` lists base files to drop, `.needs` goes into `needs` |
|
||||||
| `templates/postgres-sso/` | The example app when both are used |
|
| `templates/postgres-sso/` | The example app when both are used |
|
||||||
|
| `skills/coreapp/` | A Claude Code skill for making apps; `update.sh` links it into `~/.claude/skills/` |
|
||||||
| `uninstall.sh` | Removes what coreapp-dev set up |
|
| `uninstall.sh` | Removes what coreapp-dev set up |
|
||||||
| [PLAN.md](PLAN.md), [TEST.md](TEST.md) | What's next, and how to test it |
|
| [PLAN.md](PLAN.md), [TEST.md](TEST.md) | What's next, and how to test it |
|
||||||
|
|||||||
@@ -141,6 +141,19 @@ On a machine you can rebuild (it removes the network every VM uses):
|
|||||||
`~/.config/coreapp-dev`.
|
`~/.config/coreapp-dev`.
|
||||||
4. `bash install.sh` puts everything back.
|
4. `bash install.sh` puts everything back.
|
||||||
|
|
||||||
|
## The skill
|
||||||
|
|
||||||
|
1. After `bash update.sh`, `~/.claude/skills/coreapp` is a link to
|
||||||
|
`skills/coreapp` in the clone; running it again changes nothing. With a
|
||||||
|
real folder already at that path, it says so and leaves it.
|
||||||
|
2. `uninstall.sh` removes the link (only if it points at a
|
||||||
|
`skills/coreapp`).
|
||||||
|
3. Rehearsal: give an agent a small app with the usual problems (listens on
|
||||||
|
127.0.0.1, keeps its files next to the code, a hard-coded secret) and the
|
||||||
|
task "make it run on our Core as a Coreapp and test it". It should read
|
||||||
|
the skill, write `coreapp.toml` and a Dockerfile, move state to `/data`,
|
||||||
|
use `APP_SECRET`, deploy, check, and report what it couldn't test.
|
||||||
|
|
||||||
## The installer (coreapps), off the Core
|
## The installer (coreapps), off the Core
|
||||||
|
|
||||||
`coreapps manifest <dir>` checks a `coreapp.toml` without a Core. With a
|
`coreapps manifest <dir>` checks a `coreapp.toml` without a Core. With a
|
||||||
@@ -184,12 +197,16 @@ The Core's own scripts trace secrets, so their output goes to
|
|||||||
certificate can take a minute).
|
certificate can take a minute).
|
||||||
4. Change `www/index.html`, `coreapp deploy`: "Updating hello to 0.1.0",
|
4. Change `www/index.html`, `coreapp deploy`: "Updating hello to 0.1.0",
|
||||||
the container is recreated, the page shows the change, `.env` is
|
the container is recreated, the page shows the change, `.env` is
|
||||||
unchanged. `coreapp deploy` again: "The Core already has this image."
|
unchanged. `coreapp deploy` again: "The Core already has this image.",
|
||||||
|
and the container is the same (`docker inspect -f '{{.Created}}'`);
|
||||||
|
`coreapp deploy --recreate`: a new container, same data.
|
||||||
5. Raise `version` to 0.2.0, `coreapp deploy`: "Updated"; the container
|
5. Raise `version` to 0.2.0, `coreapp deploy`: "Updated"; the container
|
||||||
runs `:0.2.0`; `docker image ls localhost/coreapp/hello` on the Core lists
|
runs `:0.2.0`; `docker image ls localhost/coreapp/hello` on the Core lists
|
||||||
only 0.2.0.
|
only 0.2.0.
|
||||||
6. `coreapp status` (address and port), `coreapp logs`, `coreapp shell`
|
6. `coreapp status` (address and port), `coreapp logs`, `coreapp shell`
|
||||||
(exit with `exit`), `coreapp list` (all apps installed by coreapps).
|
(exit with `exit`), `coreapp shell 'id; echo $APP_URL'` (prints both,
|
||||||
|
no terminal needed, also when piped), `coreapp list` (all apps installed
|
||||||
|
by coreapps).
|
||||||
7. `coreapp remove`, answering y: on the Core, `/federated/apps/hello`,
|
7. `coreapp remove`, answering y: on the Core, `/federated/apps/hello`,
|
||||||
`/federated/services/hello`, the container and the image are gone, and
|
`/federated/services/hello`, the container and the image are gone, and
|
||||||
the catalog no longer lists `hello`.
|
the catalog no longer lists `hello`.
|
||||||
@@ -200,7 +217,11 @@ The Core's own scripts trace secrets, so their output goes to
|
|||||||
`coreapp-vm ssh /opt/coreapps/coreapps install <dir>` on a copy)
|
`coreapp-vm ssh /opt/coreapps/coreapps install <dir>` on a copy)
|
||||||
- with the app installed with `needs = ["postgres"]`, deploying with
|
- with the app installed with `needs = ["postgres"]`, deploying with
|
||||||
`needs = []` ("drops needs postgres")
|
`needs = []` ("drops needs postgres")
|
||||||
9. On a Core whose tier isn't enterprise, deploying a new app asks before
|
9. `/data` is writable by the app: with an image that runs as `nobody`
|
||||||
|
(the `--postgres`/`--sso` examples), `coreapp shell` then
|
||||||
|
`touch /data/x` works; on the Core, `/federated/apps/<name>/data` belongs
|
||||||
|
to uid 65534.
|
||||||
|
10. On a Core whose tier isn't enterprise, deploying a new app asks before
|
||||||
it's recorded as an add-on; answering no deploys nothing.
|
it's recorded as an add-on; answering no deploys nothing.
|
||||||
|
|
||||||
### With a database
|
### With a database
|
||||||
|
|||||||
+19
-6
@@ -6,11 +6,13 @@
|
|||||||
# coreapp new [--postgres] [--sso] <name>
|
# coreapp new [--postgres] [--sso] <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, or both)
|
# sign-in through the Core's Authelia, or both)
|
||||||
# coreapp deploy build, copy to the Core, install or update
|
# coreapp deploy [--recreate]
|
||||||
|
# build, copy to the Core, install or update
|
||||||
|
# (--recreate: a new container even if nothing changed)
|
||||||
# coreapp check the app answers at https://<name>.<domain>/
|
# coreapp check the app answers at https://<name>.<domain>/
|
||||||
# coreapp status its container, address and URL
|
# coreapp status its container, address and URL
|
||||||
# coreapp logs [-f] its log
|
# coreapp logs [-f] its log
|
||||||
# coreapp shell a shell in its container
|
# coreapp shell [command] a shell in its container, or run one command there
|
||||||
# coreapp remove uninstall it from the Core (asks first)
|
# coreapp remove uninstall it from the Core (asks first)
|
||||||
# coreapp list the apps on the Core installed this way
|
# coreapp list the apps on the Core installed this way
|
||||||
#
|
#
|
||||||
@@ -187,7 +189,12 @@ cmd_new() {
|
|||||||
# --- deploy -----------------------------------------------------------------
|
# --- deploy -----------------------------------------------------------------
|
||||||
|
|
||||||
cmd_deploy() {
|
cmd_deploy() {
|
||||||
local plan state tier answer local_id core_id addon=""
|
local plan state tier answer local_id core_id addon="" recreate=""
|
||||||
|
case "${1:-}" in
|
||||||
|
--recreate) recreate=--recreate ;;
|
||||||
|
"") ;;
|
||||||
|
*) die "Usage: coreapp deploy [--recreate]" ;;
|
||||||
|
esac
|
||||||
load_app
|
load_app
|
||||||
|
|
||||||
echo "Updating the installer on the Core ($REMOTE_INSTALLER)..."
|
echo "Updating the installer on the Core ($REMOTE_INSTALLER)..."
|
||||||
@@ -220,7 +227,7 @@ cmd_deploy() {
|
|||||||
|
|
||||||
# Install, or update (which recreates the container if the image changed,
|
# Install, or update (which recreates the container if the image changed,
|
||||||
# even under the same version)
|
# even under the same version)
|
||||||
installer install $addon || exit 1
|
installer install $addon $recreate || exit 1
|
||||||
[[ "$state" == new ]] && echo "(coreapp check tests it from the internet.)"
|
[[ "$state" == new ]] && echo "(coreapp check tests it from the internet.)"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -278,7 +285,13 @@ cmd_logs() {
|
|||||||
|
|
||||||
cmd_shell() {
|
cmd_shell() {
|
||||||
load_app
|
load_app
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
# One command, without a terminal, so scripts and agents can use it:
|
||||||
|
# coreapp shell 'ls -l /data'
|
||||||
|
core "docker exec $NAME sh -c $(printf '%q' "$*")"
|
||||||
|
else
|
||||||
core_tty "docker exec -it $NAME sh -c 'command -v bash > /dev/null && exec bash || exec sh'"
|
core_tty "docker exec -it $NAME sh -c 'command -v bash > /dev/null && exec bash || exec sh'"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_remove() {
|
cmd_remove() {
|
||||||
@@ -302,11 +315,11 @@ cmd="${1:-help}"
|
|||||||
[[ $# -gt 0 ]] && shift
|
[[ $# -gt 0 ]] && shift
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
new) cmd_new "$@" ;;
|
new) cmd_new "$@" ;;
|
||||||
deploy) cmd_deploy ;;
|
deploy) cmd_deploy "$@" ;;
|
||||||
check) cmd_check ;;
|
check) cmd_check ;;
|
||||||
status) cmd_status ;;
|
status) cmd_status ;;
|
||||||
logs) cmd_logs "$@" ;;
|
logs) cmd_logs "$@" ;;
|
||||||
shell) cmd_shell ;;
|
shell) cmd_shell "$@" ;;
|
||||||
remove | rm) cmd_remove ;;
|
remove | rm) cmd_remove ;;
|
||||||
list | ls) cmd_list ;;
|
list | ls) cmd_list ;;
|
||||||
help | -h | --help) usage ;;
|
help | -h | --help) usage ;;
|
||||||
|
|||||||
+42
-8
@@ -10,7 +10,10 @@ whoever wrote the app.
|
|||||||
|
|
||||||
coreapps manifest <dir> check <dir>/coreapp.toml, print its values
|
coreapps manifest <dir> check <dir>/coreapp.toml, print its values
|
||||||
coreapps plan <dir> what install would do on this Core
|
coreapps plan <dir> what install would do on this Core
|
||||||
coreapps install [--addon-ok] <dir> install the app, or update it
|
coreapps install [--addon-ok] [--recreate] <dir>
|
||||||
|
install the app, or update it
|
||||||
|
(--recreate: a new container even if
|
||||||
|
nothing changed)
|
||||||
coreapps remove <name> uninstall an app installed by coreapps
|
coreapps remove <name> uninstall an app installed by coreapps
|
||||||
coreapps list the apps installed by coreapps
|
coreapps list the apps installed by coreapps
|
||||||
|
|
||||||
@@ -352,9 +355,39 @@ def ensure_image(m):
|
|||||||
raise Refused(f"Couldn't pull {ref}: {out.stderr.strip()}")
|
raise Refused(f"Couldn't pull {ref}: {out.stderr.strip()}")
|
||||||
|
|
||||||
|
|
||||||
def compose_up(name, log):
|
def image_user(ref):
|
||||||
|
"""The uid:gid the image runs as, or None for root (or unknown)."""
|
||||||
|
user = run(["docker", "image", "inspect", "-f", "{{.Config.User}}", ref]).stdout.strip()
|
||||||
|
if user in ("", "0", "root", "0:0", "root:root"):
|
||||||
|
return None
|
||||||
|
if re.fullmatch(r"[0-9]+(:[0-9]+)?", user):
|
||||||
|
uid, _, gid = user.partition(":")
|
||||||
|
return int(uid), int(gid or uid)
|
||||||
|
# A user name: ask the image (needs `id` in it)
|
||||||
|
out = run(["docker", "run", "--rm", "--network", "none", "--entrypoint", "sh", ref,
|
||||||
|
"-c", "id -u; id -g"])
|
||||||
|
ids = out.stdout.split()
|
||||||
|
if out.returncode == 0 and len(ids) == 2 and all(i.isdigit() for i in ids):
|
||||||
|
return int(ids[0]), int(ids[1])
|
||||||
|
say(f"Note: couldn't tell which user {ref} runs as ({user}); /data stays root's.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_data(m):
|
||||||
|
"""/data, owned by the user the app runs as, so it can write there."""
|
||||||
|
data = f"{APPS}/{m['name']}/data"
|
||||||
|
os.makedirs(data, exist_ok=True)
|
||||||
|
ids = image_user(f"{m['image']}:{m['version']}")
|
||||||
|
if ids and (os.stat(data).st_uid, os.stat(data).st_gid) != ids:
|
||||||
|
os.chown(data, *ids)
|
||||||
|
|
||||||
|
|
||||||
|
def compose_up(m, log, recreate=False):
|
||||||
|
name = m["name"]
|
||||||
|
prepare_data(m)
|
||||||
run_logged(["docker", "compose", "-f", f"{APPS}/{name}/docker-compose.yml",
|
run_logged(["docker", "compose", "-f", f"{APPS}/{name}/docker-compose.yml",
|
||||||
"-p", name, "up", "-d", "--remove-orphans"], log,
|
"-p", name, "up", "-d", "--remove-orphans",
|
||||||
|
*(["--force-recreate"] if recreate else [])], log,
|
||||||
f"Starting {name} failed")
|
f"Starting {name} failed")
|
||||||
|
|
||||||
|
|
||||||
@@ -385,7 +418,7 @@ for need in "$@"; do . services/$NAME_ID/needs/$need/setup; done
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def install(folder, addon_ok):
|
def install(folder, addon_ok, recreate=False):
|
||||||
m = read_manifest(folder)
|
m = read_manifest(folder)
|
||||||
p = plan(m)
|
p = plan(m)
|
||||||
name = m["name"]
|
name = m["name"]
|
||||||
@@ -402,7 +435,7 @@ def install(folder, addon_ok):
|
|||||||
log = log_path(name, "install")
|
log = log_path(name, "install")
|
||||||
run_logged([FEDERATED + "/bin/installapp", "-n", name], log, "installapp failed")
|
run_logged([FEDERATED + "/bin/installapp", "-n", name], log, "installapp failed")
|
||||||
# installapp's start step only knows Federated's own apps
|
# installapp's start step only knows Federated's own apps
|
||||||
compose_up(name, log)
|
compose_up(m, log)
|
||||||
else:
|
else:
|
||||||
say(f"Updating {name} to {m['version']}...")
|
say(f"Updating {name} to {m['version']}...")
|
||||||
log = log_path(name, "update")
|
log = log_path(name, "update")
|
||||||
@@ -413,7 +446,7 @@ def install(folder, addon_ok):
|
|||||||
stdout=f, stderr=subprocess.STDOUT, env=env)
|
stdout=f, stderr=subprocess.STDOUT, env=env)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Refused(f"Updating failed (whole log on the Core: {log}).")
|
raise Refused(f"Updating failed (whole log on the Core: {log}).")
|
||||||
compose_up(name, log)
|
compose_up(m, log, recreate)
|
||||||
|
|
||||||
wait_until_answering(m, p)
|
wait_until_answering(m, p)
|
||||||
if p["state"] == "update":
|
if p["state"] == "update":
|
||||||
@@ -522,9 +555,10 @@ def main(args):
|
|||||||
return 0
|
return 0
|
||||||
if cmd == "install" and rest:
|
if cmd == "install" and rest:
|
||||||
addon_ok = "--addon-ok" in rest
|
addon_ok = "--addon-ok" in rest
|
||||||
folders = [a for a in rest if a != "--addon-ok"]
|
recreate = "--recreate" in rest
|
||||||
|
folders = [a for a in rest if a not in ("--addon-ok", "--recreate")]
|
||||||
if len(folders) == 1:
|
if len(folders) == 1:
|
||||||
return install(folders[0], addon_ok)
|
return install(folders[0], addon_ok, recreate)
|
||||||
if cmd == "remove" and len(rest) == 1:
|
if cmd == "remove" and len(rest) == 1:
|
||||||
return remove(rest[0])
|
return remove(rest[0])
|
||||||
if cmd == "list" and not rest:
|
if cmd == "list" and not rest:
|
||||||
|
|||||||
@@ -0,0 +1,284 @@
|
|||||||
|
---
|
||||||
|
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://<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.
|
||||||
|
- `/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://<name>.<domain>`, 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.<domain>
|
||||||
|
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 []
|
||||||
|
```
|
||||||
|
|
||||||
|
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/<name>`: `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.<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 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`).
|
||||||
|
|
||||||
|
### `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 |
|
||||||
|
|
||||||
|
The client is fixed, so the app has to fit it:
|
||||||
|
|
||||||
|
- Redirect URI: exactly `https://<name>.<domain>/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.<domain>` 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`).
|
||||||
|
|
||||||
|
### Not available yet
|
||||||
|
|
||||||
|
Email (sending mail through the Core), 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).
|
||||||
|
- **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"]` 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://<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).
|
||||||
|
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 '<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.200.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.
|
||||||
|
- `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/<name>-install.log`
|
||||||
|
only when a deploy fails in the installer itself.
|
||||||
|
|
||||||
|
## 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.
|
||||||
@@ -55,6 +55,10 @@ if [ ${#vms[@]} -gt 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$HOME/.local/bin/coreapp-vm" "$HOME/.local/bin/coreapp"
|
rm -f "$HOME/.local/bin/coreapp-vm" "$HOME/.local/bin/coreapp"
|
||||||
|
# The skill's link, if it's ours
|
||||||
|
if [[ "$(readlink "$HOME/.claude/skills/coreapp" 2> /dev/null)" == */skills/coreapp ]]; then
|
||||||
|
rm -f "$HOME/.claude/skills/coreapp"
|
||||||
|
fi
|
||||||
|
|
||||||
if command -v virsh > /dev/null && v net-info "$NETWORK" &> /dev/null; then
|
if command -v virsh > /dev/null && v net-info "$NETWORK" &> /dev/null; then
|
||||||
echo "Removing coreapp-dev's VM network..."
|
echo "Removing coreapp-dev's VM network..."
|
||||||
|
|||||||
@@ -182,4 +182,15 @@ for cmd in coreapp-vm coreapp; do
|
|||||||
ln -sfn "$SELF/bin/$cmd" "$HOME/.local/bin/$cmd"
|
ln -sfn "$SELF/bin/$cmd" "$HOME/.local/bin/$cmd"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# The coreapp skill, for Claude Code agents making apps on this computer
|
||||||
|
# (in any repository): a symlink too. A skill of that name that isn't ours
|
||||||
|
# is left alone
|
||||||
|
SKILL_LINK="$HOME/.claude/skills/coreapp"
|
||||||
|
if [ -L "$SKILL_LINK" ] || [ ! -e "$SKILL_LINK" ]; then
|
||||||
|
mkdir -p "$HOME/.claude/skills"
|
||||||
|
ln -sfn "$SELF/skills/coreapp" "$SKILL_LINK"
|
||||||
|
else
|
||||||
|
echo "Note: $SKILL_LINK exists and isn't coreapp-dev's; left it as it is."
|
||||||
|
fi
|
||||||
|
|
||||||
echo "coreapp-dev's host software is up to date."
|
echo "coreapp-dev's host software is up to date."
|
||||||
|
|||||||
Reference in New Issue
Block a user