# 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.3.14-alpine AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build

FROM oven/bun:1.3.14-alpine
# ffmpeg drives the transcode pipeline. tzdata lets Intl resolve Europe/Amsterdam, without
# which every unlock time would silently fall back to UTC.
RUN apk add --no-cache ffmpeg 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"]
