Fixes from the Leantime rehearsal: unhealthy apps, signin links and errors

Deploy now waits while an image's own HEALTHCHECK says "starting" and
stops on "unhealthy" with the check and its result, since traefik doesn't
route unhealthy containers (it used to say "Updated"); an update rolls
back, a first install says it stays installed, and a rollback waits until
the old version is routed again. coreapp signin follows a page's one
"Core SSO" or "Authelia" link, prints the app's visible error when it
doesn't end signed in, and has --help. The skill covers 127.0.0.1 among
trusted proxies, the image's HEALTHCHECK, COPY --chmod, $TMPDIR outside
the sandbox, patching an app's OIDC code for userinfo claims, and testing
a new account's first sign-in. PLAN: ID-token claims for Federated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 11:33:52 -07:00
co-authored by Claude Opus 5.5
parent cbdf0e5789
commit f4b869decd
8 changed files with 261 additions and 22 deletions
+52 -4
View File
@@ -1039,8 +1039,13 @@ def install_app(m, p, folder, origin, addon_ok, recreate):
run_logged([FEDERATED + "/bin/installapp", "-n", name], log, "installapp failed")
# installapp's start step only knows Federated's own apps
compose_up(m, log)
wait_until_answering(m, p)
wait_for_route(m, p)
try:
wait_until_answering(m, p)
wait_for_route(m, p)
except Refused as e:
# A new app has nothing to roll back to: it stays installed
raise Refused(f"{e}\n{name} is installed but not working. Deploying again "
f"updates it (its data and database stay); removing it deletes them.")
else:
before = service_value(f"{APPS}/{name}/.env", "IMAGE_VERSION")
if before == m["version"]:
@@ -1356,6 +1361,13 @@ def roll_back(m, p, backup, log):
stdout=f, stderr=subprocess.STDOUT)
if result.returncode != 0:
problems.append("starting the old version")
else:
# Until people can reach it again (traefik waits for the image's
# HEALTHCHECK, if it has one)
try:
wait_for_route(m, p)
except Refused:
problems.append("the old version is unhealthy too")
# The new version's image, unless it's the same tag as the old one
if old and (old["image"], old["version"]) != (m["image"], m["version"]):
run(["docker", "image", "rm", f"{m['image']}:{m['version']}"])
@@ -1457,14 +1469,50 @@ def wait_for_route(m, p):
# wait for traefik to give the same, not for "not 404")
direct = status("-H", f"Host: {host}", "-H", "X-Forwarded-Proto: https",
f"http://{p['address']}:{m['port']}{m['health']}")
for _ in range(30):
# traefik leaves out containers whose image's own HEALTHCHECK says
# they're starting or unhealthy: wait while it's starting, and stop on
# unhealthy (the route would never come)
started = time.monotonic()
while time.monotonic() - started < 180:
code = status("--resolve", f"{host}:443:{traefik}", f"https://{host}{m['health']}")
if code == direct or code not in ("", "000", "404", "502", "503"):
return
time.sleep(1)
health = container_health(m["name"])
if health == "unhealthy":
raise Refused(unhealthy_message(m, host))
if health != "starting" and time.monotonic() - started > 30:
break
time.sleep(2)
say(f"Note: traefik doesn't route https://{host}/ to it yet; it may take a moment.")
def container_health(name):
"""Docker's health status from the image's HEALTHCHECK: "starting",
"healthy", "unhealthy", or "" if the image has none."""
return run(["docker", "inspect", "-f",
"{{if .State.Health}}{{.State.Health.Status}}{{end}}", name]).stdout.strip()
def unhealthy_message(m, host):
out = run(["docker", "inspect", "-f", "{{json .Config.Healthcheck}}|{{json .State.Health}}",
m["name"]]).stdout
try:
check, _, health = out.partition("|")
test = " ".join(json.loads(check)["Test"])
log = json.loads(health).get("Log") or []
last = log[-1] if log else {}
result = f"exit code {last.get('ExitCode')}" + (
f", {' '.join(str(last.get('Output', '')).split())[-300:]}"
if str(last.get("Output", "")).strip() else "")
except (ValueError, KeyError, TypeError, AttributeError):
test, result = "?", "?"
return (f"Docker says {m['name']} is unhealthy, so traefik doesn't route https://{host}/ "
f"to it. The check is the image's own HEALTHCHECK, run inside the container "
f"({test}); its last result: {result}. If the app answers that check with an "
"error (e.g. it refuses requests from 127.0.0.1 because of a trusted-proxies "
"setting), fix that, or the HEALTHCHECK in the Dockerfile.")
def update(name, addon_ok):
"""An app installed from a repository, to its newest release."""
if not re.fullmatch(FIELDS["name"], name) or not is_ours(name):