Snipe-IT rehearsal: slow starts, image volumes, HTML-as-text mail

Deploy waits up to 5 minutes for an app to answer, printing its last log
line every 30 s, and stops early when the container exits or restarts
three times. It notes VOLUMEs the image declares outside /data, and
uninstall removes anonymous volumes (down -v). coreapp inbox renders HTML
sent in a text/plain part.

Skill: no first-come setup wizard even without sso (admin at startup,
password by reset), no new sign-in code for apps without OIDC, upstream
scripts that read shell variables, a step between upstream steps, the
image's VOLUMEs, a slow first install, three-part min_version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 13:12:46 -07:00
co-authored by Claude Opus 5.5
parent f4b869decd
commit 114b364cef
7 changed files with 112 additions and 15 deletions
+40 -4
View File
@@ -778,6 +778,17 @@ def write(path, text, mode=0o644):
ICON_LIMIT = 1024 * 1024
def image_volumes(m):
"""Paths outside /data that the app's image declares as VOLUMEs."""
out = run(["docker", "image", "inspect", "-f", "{{json .Config.Volumes}}",
f"{m['image']}:{m['version']}"]).stdout
try:
paths = sorted(json.loads(out) or {})
except ValueError:
return []
return [p for p in paths if p.rstrip("/") != "/data" and not p.startswith("/data/")]
def icon_check(folder):
"""The app's icon.png: ("ok", "missing" or "bad", a note for the
developer or "")."""
@@ -1028,6 +1039,10 @@ def install_app(m, p, folder, origin, addon_ok, recreate):
state, note = icon_check(folder)
if state != "ok":
say(f"Note: {note}")
for path in image_volumes(m):
say(f"Note: the image declares VOLUME {path}. Docker gives that its own anonymous "
"volume, which isn't the app's /data: it isn't backed up with the app or kept "
"for a rollback. Point the app's files there at /data instead.")
if p["new_extensions"]:
say(f"Enabling PostgreSQL extension(s) {', '.join(p['new_extensions'])} in "
@@ -1425,6 +1440,10 @@ def remove_old_images(m):
remove_images(m["image"], keep=m["version"])
# How long deploy waits for an app to answer after starting it
ANSWER_WAIT = 300
def wait_until_answering(m, p):
name = m["name"]
url = f"http://{p['address']}:{m['port']}{m['health']}"
@@ -1433,10 +1452,24 @@ def wait_until_answering(m, p):
headers = {"Host": f"{name}.{p['domain']}", "X-Forwarded-Proto": "https",
"X-Forwarded-Host": f"{name}.{p['domain']}"}
say(f"Waiting for it to answer at {url}...")
for _ in range(30):
state = run(["docker", "inspect", "-f", "{{.State.Status}}", name]).stdout.strip()
# A first start can take minutes (an app's database migrations), so
# wait while the container runs, saying what it's doing now and then
started = time.monotonic()
shown = started
while time.monotonic() - started < ANSWER_WAIT:
state, _, restarts = run(["docker", "inspect", "-f", "{{.State.Status}} {{.RestartCount}}",
name]).stdout.strip().partition(" ")
if state not in ("running", "created", "restarting"):
break
if restarts.isdigit() and int(restarts) >= 3:
state = f"{state}, restarted {restarts} times"
break
if time.monotonic() - shown >= 30:
shown = time.monotonic()
tail = run(["docker", "logs", "--tail", "1", name])
line = " ".join((tail.stdout + tail.stderr).split())[:150]
say(f" still starting ({time.monotonic() - started:.0f} s)"
+ (f"; its log: {line}" if line else ""))
try:
with urllib.request.urlopen(urllib.request.Request(url, headers=headers),
timeout=2) as r:
@@ -1450,7 +1483,8 @@ def wait_until_answering(m, p):
time.sleep(2)
logs = run(["docker", "logs", "--tail", "20", name])
sys.stderr.write(logs.stdout + logs.stderr)
raise Refused(f"{name} doesn't answer at {url} (state: {state or 'missing'}; "
raise Refused(f"{name} doesn't answer at {url} after "
f"{time.monotonic() - started:.0f} s (state: {state or 'missing'}; "
"its log is above).")
@@ -1823,7 +1857,9 @@ def mail_text(message):
content = part.get_content()
except (LookupError, UnicodeError):
content = part.get_payload(decode=True).decode("utf-8", "replace")
if part.get_content_subtype() == "html":
# Some apps put HTML in the part they label plain text (Snipe-IT)
looks_html = re.match(r"\s*(<!doctype html|<html)", content, re.I)
if part.get_content_subtype() == "html" or looks_html:
parser = TextOfHTML()
parser.feed(content)
content = parser.text()