# Ktistec 3.13.0 from its tag: the project publishes no image. Its own Dockerfile, pinned: a static server built with
# Crystal, its scripts and styles with node
FROM docker.io/crystallang/crystal:1.19.1-alpine AS builder
RUN apk -U --no-progress add make sqlite-static yaml-dev musl-dev gc-dev gc-static pcre2-dev pcre2-static gmp-dev gmp-static
WORKDIR /build
RUN git clone --branch v3.13.0 --depth 1 https://github.com/toddsundsted/ktistec .
RUN shards install --production
RUN crystal build src/ktistec/server.cr --static --no-debug --release

FROM docker.io/library/node:22-alpine AS nodebuilder
WORKDIR /build
COPY --from=builder /build /build
RUN npm ci && npm run build

FROM docker.io/library/alpine:3.22
RUN apk -U --no-progress --no-cache add tzdata
WORKDIR /app
COPY --from=nodebuilder /build/etc /app/etc
COPY --from=nodebuilder /build/public /app/public
COPY --from=nodebuilder /build/server /bin/server
RUN mkdir /db && ln -s /app/public/uploads /uploads
ENV KTISTEC_DB=/db/ktistec.db
EXPOSE 3000
CMD ["/bin/server"]
