# ymz/sillytavern — pinned derivative of SillyTavern 1.19.0 with
#   0001 trusted-header SSO auto-provisioning, and
#   0002 trusted-header shared-secret enforcement, and
#   0003 Secure session cookie.
#
# The base image is pinned by tag *and* digest (2026-09-14). `git` ships in the
# upstream image, so the patch is applied to the exact files inside the image
# rather than copying patched sources around: the build fails closed if the
# patch stops applying, which is the whole point of a pinned derivative.
#
# Build (from this directory):  docker compose build
FROM ghcr.io/sillytavern/sillytavern:1.19.0@sha256:eef27ff0c7961f1a2f488400f581f48ff38f8b910c5d3b8d389138d71791bb14

COPY patches/ /tmp/ymz/

# Patches apply in filename order (0002 builds on 0001). Any failure aborts the
# build, so a stale patch can never ship a silently unpatched image.
RUN cd /home/node/app \
 && for p in /tmp/ymz/*.patch; do \
        echo "applying $p" \
        && git apply --verbose --whitespace=nowarn "$p" || exit 1; \
    done \
 && rm -rf /tmp/ymz \
 && grep -q "SSO_AUTO_PROVISION" src/users.js \
 && grep -q "TRUSTED_HEADER_SECRET" src/users.js \
 && grep -q "autoProvision" default/config.yaml \
 && grep -q "trustedHeaderSecret" default/config.yaml \
 && grep -q "secure: true" src/server-main.js \
 && grep -q "trust proxy" src/server-main.js \
 && chown node:node src/users.js default/config.yaml src/server-main.js

LABEL org.opencontainers.image.title="ymz/sillytavern" \
      org.opencontainers.image.description="SillyTavern 1.19.0 + YMZ trusted-header auto-provision patch (docs/04-sillytavern.md)" \
      org.opencontainers.image.version="1.19.0" \
      org.opencontainers.image.base.name="ghcr.io/sillytavern/sillytavern:1.19.0" \
      org.opencontainers.image.base.digest="sha256:eef27ff0c7961f1a2f488400f581f48ff38f8b910c5d3b8d389138d71791bb14"
