FROM golang:1.20 AS builder

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y libolm-dev

WORKDIR /build

COPY . .
RUN go build -ldflags="-s -w" -o matrix-pretix -v .

FROM debian:bullseye-slim

ARG DEBIAN_FRONTEND=noninteractive

RUN groupadd --gid 999 --system matrix-pretix && useradd --gid 999 --system --uid 999 matrix-pretix

RUN apt-get update && apt-get install -y ca-certificates libolm3

COPY --from=builder /build/matrix-pretix /usr/local/bin/matrix-pretix

USER matrix-pretix

VOLUME /data
WORKDIR /data

EXPOSE 8080

CMD ["/usr/local/bin/matrix-pretix", "/config.json"]
