diff --git a/PLAN.md b/PLAN.md index 5830f6f..be8da31 100644 --- a/PLAN.md +++ b/PLAN.md @@ -424,6 +424,12 @@ Done 2026-12-03: wordpress do - Without `docs`, the tile links a search of Federated's documentation; apps installed from a repository now default to the repository +- Icons (2026-12-03): an unusable `icon.png` (missing, a link, over 1 MB, + not a PNG) used to become the default silently. The installer now says + so; `coreapp deploy` also notes one that isn't square or is under 80px + (the tile is 40x40); `coreapp publish` refuses an unusable one, or one + that isn't committed. Only PNG: Superpanel's scripts take `icon.svg` + too, but an SVG can carry scripts, so it'd need cleaning first - [ ] Look at the dashboard signed in as an admin: the tiles' links and icons, and "Disk Usage by App" diff --git a/TEST.md b/TEST.md index bf00afe..1adb6f9 100644 --- a/TEST.md +++ b/TEST.md @@ -248,7 +248,17 @@ The Core's own scripts trace secrets, so their output goes to `title`, raise `version`, deploy: both files have the new title. After `coreapp remove`, neither has it. An app installed from a repository with no `docs` has `DOCS=` in `service` and applist. -12. On a Core whose tier isn't enterprise, deploying a new app asks before +12. Icons: `python3 core/coreapps manifest .` prints `icon=` and + `icon_note=`: no `icon.png` "missing"; a link, a non-PNG, or one over + 1 MB "bad" (with why); a PNG of 300x100 "ok" with a note to make it + square; 32x32 "ok" with a note that it's small; 256x256 and the + template's (128x128) "ok" with no note. Deploying with a non-PNG + `icon.png`: "Note: icon.png isn't a PNG, so the Core shows the default + icon instead." once, and the Core's `services//icon.png` is the + default. `coreapp publish` (in a git repository, `image` not + localhost/) refuses a non-PNG icon, and one in `.gitignore` ("isn't in + the repository"), before it looks at the registry. +13. 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. ### With a database diff --git a/bin/coreapp b/bin/coreapp index 091d2bf..44c0554 100755 --- a/bin/coreapp +++ b/bin/coreapp @@ -89,7 +89,7 @@ core_domain() { # --- The app in the current folder --------------------------------------- # From coreapp.toml, as checked by the installer -NAME="" TITLE="" VERSION="" IMAGE="" PORT="" HEALTH="" NEEDS="" +NAME="" TITLE="" VERSION="" IMAGE="" PORT="" HEALTH="" NEEDS="" ICON="" ICON_NOTE="" load_app() { load_manifest init_core @@ -110,6 +110,8 @@ load_manifest() { port) PORT="$value" ;; health) HEALTH="$value" ;; needs) NEEDS="$value" ;; + icon) ICON="$value" ;; + icon_note) ICON_NOTE="$value" ;; esac done <<< "$values" } @@ -220,6 +222,8 @@ cmd_deploy() { *) die "Usage: coreapp deploy [--recreate]" ;; esac load_app + # (The installer tells about an icon it can't use) + [[ "$ICON" != ok || -z "$ICON_NOTE" ]] || echo "Note: $ICON_NOTE" echo "Updating the installer on the Core ($REMOTE_INSTALLER)..." sync_installer @@ -456,6 +460,12 @@ coreapp deploy keeps working with that name." || die "This folder isn't a git repository. A published app is one (its tag is the release)." [[ -z "$(git status --porcelain)" ]] \ || die "There are uncommitted changes (git status). Commit them first, so the release matches a commit." + # The Core reads icon.png from the repository at the tag + [[ "$ICON" != bad ]] || die "$ICON_NOTE Fix it before publishing: a release can't be changed." + if [[ "$ICON" == ok ]] && ! git ls-files -s icon.png | grep -q '^100644 '; then + die "icon.png isn't in the repository (is it in .gitignore?), so Cores would show the default icon. Commit it first." + fi + [[ -z "$ICON_NOTE" ]] || echo "Note: $ICON_NOTE" commit="$(git rev-parse HEAD)" if git rev-parse -q --verify "refs/tags/$tag" > /dev/null; then [[ "$(git rev-parse "$tag^{commit}")" == "$commit" ]] \ diff --git a/core/coreapps b/core/coreapps index e602859..4806e8b 100755 --- a/core/coreapps +++ b/core/coreapps @@ -41,6 +41,7 @@ import json import os import re import shutil +import struct import subprocess import sys import tempfile @@ -560,16 +561,39 @@ def write(path, text, mode=0o644): os.chmod(path, mode) -def icon_from(folder): - """The app's icon.png if it's a reasonable PNG, else the default.""" +ICON_LIMIT = 1024 * 1024 + + +def icon_check(folder): + """The app's icon.png: ("ok", "missing" or "bad", a note for the + developer or "").""" path = os.path.join(folder, "icon.png") - try: - if not os.path.islink(path) and os.path.getsize(path) <= 1024 * 1024: - with open(path, "rb") as f: - if f.read(8) == b"\x89PNG\r\n\x1a\n": - return path - except OSError: - pass + default = "the Core shows the default icon instead" + if os.path.islink(path): + return "bad", f"icon.png is a link, so {default}. Make it a file." + if not os.path.isfile(path): + return "missing", f"No icon.png (a PNG file up to 1 MB), so {default}." + if os.path.getsize(path) > ICON_LIMIT: + return "bad", f"icon.png is bigger than 1 MB, so {default}." + with open(path, "rb") as f: + head = f.read(24) + if head[:8] != b"\x89PNG\r\n\x1a\n" or head[12:16] != b"IHDR": + return "bad", f"icon.png isn't a PNG, so {default}." + width, height = struct.unpack(">II", head[16:24]) + notes = [] + if width != height: + notes.append(f"icon.png is {width}x{height}; the dashboard shows it in a " + "square, so a square one looks best.") + if min(width, height) < 80: + notes.append(f"icon.png is small ({width}x{height}): the dashboard shows it " + "at 40x40 (80x80 pixels on sharp screens); 256x256 looks good.") + return "ok", " ".join(notes) + + +def icon_from(folder): + """The app's icon.png if it's usable, else the default.""" + if icon_check(folder)[0] == "ok": + return os.path.join(folder, "icon.png") return os.path.join(TEMPLATES, "icon.png") @@ -752,6 +776,9 @@ def install_app(m, p, folder, origin, addon_ok, recreate): say(f"{m['title']} {m['version']} from {origin['source']} ({origin['tag']}, " f"commit {origin['commit'][:12]})") ensure_image(m, pull=bool(origin)) + state, note = icon_check(folder) + if state != "ok": + say(f"Note: {note}") if p["state"] == "new": make_service_folder(m, p, folder, origin) @@ -1099,6 +1126,9 @@ def main(args): "health", "docs", "dbname"): print(f"{key}={m[key]}") print(f"needs={' '.join(m['needs'])}") + state, note = icon_check(rest[0]) + print(f"icon={state}") + print(f"icon_note={note}") return 0 if os.geteuid() != 0: raise Refused("Run coreapps as root on the Core.") diff --git a/skills/coreapp/SKILL.md b/skills/coreapp/SKILL.md index 6b6137b..043f51f 100644 --- a/skills/coreapp/SKILL.md +++ b/skills/coreapp/SKILL.md @@ -20,7 +20,7 @@ An app is a repository with: | `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) | +| `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: @@ -247,6 +247,10 @@ and make the Dockerfile fit the Core: (`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 too small; `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 diff --git a/templates/app/README.md b/templates/app/README.md index c474ed1..e508f91 100644 --- a/templates/app/README.md +++ b/templates/app/README.md @@ -22,7 +22,7 @@ coreapp remove # uninstall it from the Core |---|---| | `coreapp.toml` | What the Core needs to know: name, title, image and version, port, health path, and what it needs from the Core (`needs`) | | `Dockerfile`, `www/` | The app itself | -| `icon.png` | Its icon in the Core's dashboard (a PNG, up to 1 MB) | +| `icon.png` | Its icon in the Core's dashboard: a square PNG, 256x256 is good, up to 1 MB. This one is a placeholder | That's all an app has. The Core's side (the container on the Core's `core` network, the traefik route to `https://{{NAME}}.`, its settings and