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:
+42
-8
@@ -10,7 +10,10 @@ whoever wrote the app.
|
||||
|
||||
coreapps manifest <dir> check <dir>/coreapp.toml, print its values
|
||||
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 list the apps installed by coreapps
|
||||
|
||||
@@ -352,9 +355,39 @@ def ensure_image(m):
|
||||
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",
|
||||
"-p", name, "up", "-d", "--remove-orphans"], log,
|
||||
"-p", name, "up", "-d", "--remove-orphans",
|
||||
*(["--force-recreate"] if recreate else [])], log,
|
||||
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)
|
||||
p = plan(m)
|
||||
name = m["name"]
|
||||
@@ -402,7 +435,7 @@ def install(folder, addon_ok):
|
||||
log = log_path(name, "install")
|
||||
run_logged([FEDERATED + "/bin/installapp", "-n", name], log, "installapp failed")
|
||||
# installapp's start step only knows Federated's own apps
|
||||
compose_up(name, log)
|
||||
compose_up(m, log)
|
||||
else:
|
||||
say(f"Updating {name} to {m['version']}...")
|
||||
log = log_path(name, "update")
|
||||
@@ -413,7 +446,7 @@ def install(folder, addon_ok):
|
||||
stdout=f, stderr=subprocess.STDOUT, env=env)
|
||||
if result.returncode != 0:
|
||||
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)
|
||||
if p["state"] == "update":
|
||||
@@ -522,9 +555,10 @@ def main(args):
|
||||
return 0
|
||||
if cmd == "install" and 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:
|
||||
return install(folders[0], addon_ok)
|
||||
return install(folders[0], addon_ok, recreate)
|
||||
if cmd == "remove" and len(rest) == 1:
|
||||
return remove(rest[0])
|
||||
if cmd == "list" and not rest:
|
||||
|
||||
Reference in New Issue
Block a user