# syntax=docker/dockerfile:1

# Pinned rather than floating: this app lies dormant eleven months of the year, and the
# image is what guarantees it starts the same way next December as it did this one.
FROM oven/bun:1.4.4-alpine AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build

FROM oven/bun:1.4.4-alpine
# ffmpeg drives the transcode pipeline. tzdata lets Intl resolve Europe/Amsterdam, without
# which every unlock time would silently fall back to UTC.
#
# ffmpeg is held to the 8.1 line rather than an exact release: Alpine keeps only the newest
# build of each package on a branch, so "ffmpeg=8.1.3-r0" would stop building the day 8.1.4
# lands. `~8.1` takes patch releases and refuses a jump to 8.2 or 9. Either way CI runs the
# full smoke suite against this exact image before it is pushed.
RUN apk add --no-cache "ffmpeg~8.1" tzdata

WORKDIR /app
# adapter-node bundles everything; the app has no runtime dependencies, so build/ is all of it.
COPY --from=build /app/build ./build

RUN mkdir -p /var/lib/mamma-calendar && chown -R bun:bun /var/lib/mamma-calendar
USER bun

ENV NODE_ENV=production \
    DATA_DIR=/var/lib/mamma-calendar \
    TIMEZONE=Europe/Amsterdam \
    PORT=3000 \
    BODY_SIZE_LIMIT=629145600

EXPOSE 3000
VOLUME ["/var/lib/mamma-calendar"]

CMD ["bun", "./build/index.js"]
