# Reproducible source/patch inputs and the base versions match Element v1.12.35.
FROM --platform=linux/amd64 ghcr.io/pnpm/pnpm:12.14.0@sha256:71202ae73719148f6b6e129ca1e9fa3ceabbc9a037dc34800715606f2b5290a1 AS pnpm
FROM --platform=linux/amd64 docker.io/library/node:24-bullseye@sha256:25f3016fcdae6b5d65bd9bcb4064b7e4198ec8d49493fa40d73f9b463d04fb15 AS builder
COPY --from=pnpm /opt/pnpm /opt/pnpm
RUN ln -s /opt/pnpm/pnpm /usr/local/bin/pnpm
WORKDIR /src
COPY --from=upstream / /src/
ARG PENTA_DIST_VERSION
ENV CI=true HUSKY=0 NX_DAEMON=false NX_PARALLEL=1 NX_SKIP_NX_CACHE=true \
    NX_SKIP_REMOTE_CACHE=true NX_CLOUD=false NX_TASKS_RUNNER_DYNAMIC_OUTPUT=false \
    NODE_OPTIONS=--max-old-space-size=3072 RAYON_NUM_THREADS=2 \
    PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 ELECTRON_SKIP_BINARY_DOWNLOAD=1
RUN pnpm install --frozen-lockfile --network-concurrency=4 --child-concurrency=1
RUN VERSION="$PENTA_DIST_VERSION" pnpm --dir apps/web build --parallel=1
RUN test -s /src/apps/web/webapp/index.html && test -s /src/apps/web/webapp/sw.js \
    && test -s /src/apps/web/webapp/penta-branding/penta-chat-192.png

# Keep the same Nginx/entrypoint/healthcheck contract as the accepted image.
# Old hashed bundles remain readable for an already-open tab until normal reload;
# the new index, manifest, logos and all vector-icon aliases are overwritten.
FROM --platform=linux/amd64 ghcr.io/element-hq/element-web:v1.12.35@sha256:406b48b80153818284a235fa3600b2a5b5b6b0aa0e4ef4896b36d8d3461352f3
USER root
COPY --from=builder /src/apps/web/webapp /app
# The existing DEV Compose mounts its reviewed public /app/config.json. Fail
# closed without that mount instead of inheriting upstream's matrix.org sample.
RUN rm -f /app/config.json
ARG PENTA_UPSTREAM_COMMIT
ARG PENTA_PATCHSET_SHA256
ARG PENTA_PATCHED_SOURCE_SHA256
ARG PENTA_SOURCE_REVISION
LABEL org.opencontainers.image.title="Penta Chat" \
      org.opencontainers.image.source="https://github.com/element-hq/element-web" \
      org.opencontainers.image.revision="$PENTA_UPSTREAM_COMMIT" \
      org.penta-chat.patchset-sha256="$PENTA_PATCHSET_SHA256" \
      org.penta-chat.patched-source-sha256="$PENTA_PATCHED_SOURCE_SHA256" \
      org.penta-chat.source-revision="$PENTA_SOURCE_REVISION"
USER nginx
