# syntax=docker/dockerfile:1
# ONCE Campfire, transpiled by Roundhouse and compiled by Spinel.
#
# Two stages. The first compiles pack/ — the generated C plus the Spinel
# runtime as source, with a Makefile that needs a C compiler and make and
# nothing else. The second carries only the binary and what it reads at
# run time. clang, not gcc: the build is one 12 MB translation unit, and
# clang compiles it in under half the time.

FROM debian:trixie-slim AS build
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y clang make libsqlite3-dev libjemalloc-dev libvips-dev && \
    rm -rf /var/lib/apt/lists/*
COPY pack /src
RUN make -C /src -j"$(nproc)" CC=clang

FROM debian:trixie-slim
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y libsqlite3-0 libjemalloc2 libvips42 ffmpeg && \
    rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY app/ ./
COPY --from=build /src/campfire ./campfire
# The SQLite database lives here; mount a volume to keep it across runs.
RUN mkdir -p storage
VOLUME /app/storage
ENV PORT=3000
EXPOSE 3000
CMD ["./campfire"]
