# Inference Co-op LibreChat — brand overlay on the official Cloudron package
#
# Build:  cloudron builder build --repository registry.inference.coop/co-op/librechat-custom --tag <yyyymmdd>-<gitsha>
# Deploy: cloudron update --app <app-id> --image registry.inference.coop/co-op/librechat-custom:<tag>
#         (run from THIS directory — the CLI reads CloudronManifest.json here)
#
# Rules that keep this image safe:
#   1. The base tag is PINNED to the exact appstore image the app runs
#      (manifest.dockerImage). Never a floating tag: a rebuild must never
#      silently pull a newer LibreChat than the one we validated.
#   2. NEVER edit CloudronManifest.json — the copy in this repo must stay
#      byte-identical to the OFFICIAL appstore manifest. `cloudron update`
#      reads it from the deploy directory and applies it to the app; a
#      hand-edited manifest that omits addons (postgresql, mongodb, oidc,
#      sendmail, localstorage) strips them from the app and crash-loops it
#      (mkdir: Read-only file system). That is what broke the sandbox on
#      2026-10-18 — the manifest, not the overlay, was the bug.
#   3. This image changes ONLY static brand assets. All behavior lives on the
#      persistent volume (/app/data/librechat.yaml, /app/data/env,
#      /app/data/mcp/) and survives image updates unchanged.
FROM cloudron/ai.librechat.cloudronapp:202610150224320000

# Login-page + header logo (the client bundle references assets/logo.svg)
COPY assets/logo.svg /app/code/librechat/client/dist/assets/logo.svg
# Browser favicons + PWA icons (referenced by dist/index.html + manifest.webmanifest)
COPY assets/favicon-32x32.png /app/code/librechat/client/dist/assets/favicon-32x32.png
COPY assets/favicon-16x16.png /app/code/librechat/client/dist/assets/favicon-16x16.png
COPY assets/apple-touch-icon-180x180.png /app/code/librechat/client/dist/assets/apple-touch-icon-180x180.png
COPY assets/icon-192x192.png /app/code/librechat/client/dist/assets/icon-192x192.png
COPY assets/maskable-icon.png /app/code/librechat/client/dist/assets/maskable-icon.png
# Figtree font (design kit, SIL OFL) — self-hosted, matches homepage/dashboard
COPY assets/fonts/ /app/code/librechat/client/dist/assets/fonts/

# Custom stylesheet and optional helper JS
COPY assets/custom.css /app/code/librechat/client/dist/assets/custom.css
# rebuild trigger
COPY assets/custom2.js /app/code/librechat/client/dist/assets/custom2.js

# Co-op UI strings: rename the "MCP Servers" button to "Tools" and replace
# the LibreChat footer tagline with the co-op footer. Non-fatal at build.
COPY patch_ui_strings.py /app/code/patch_ui_strings.py
RUN python3 /app/code/patch_ui_strings.py

# Inject branding into built HTML (dist) before image is packaged
# rebuild marker 20261019-$(date +%s)
RUN sed -i 's|<title>LibreChat</title>|<title>Inference Co‑op</title>|' /app/code/librechat/client/dist/index.html && \
    sed -i '/<title>Inference Co‑op<\/title>/a <link rel="stylesheet" href="assets/custom.css">' /app/code/librechat/client/dist/index.html && \
    sed -i '/<link rel="stylesheet" href="assets\/custom.css">/a <script src="assets/custom2.js"></script>' /app/code/librechat/client/dist/index.html && \
    sed -i 's|assets/logo.svg|assets/logo.svg?v=3|g' /app/code/librechat/client/dist/assets/index.*.js && \
    rm -f /app/code/librechat/client/dist/assets/index.*.js.gz /app/code/librechat/client/dist/assets/index.*.js.br
