FROM golang:1.26-bookworm@sha256:5f68ec6805843bd3981a951ffada82a26a0bd2631045c8f7dba483fa868f5ec5 AS build

WORKDIR /src

COPY go.mod go.sum ./
RUN go mod download

COPY cmd ./cmd
COPY internal ./internal
COPY web ./web

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o /out/maintainarr ./cmd/maintainarr

FROM debian:bookworm-slim@sha256:96e378d7e6531ac9a15ad505478fcc2e69f371b10f5cdf87857c4b8188404716

RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates tzdata \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=build /out/maintainarr /app/maintainarr
COPY web/static /app/web/static

RUN mkdir -p /app/data

ENV MAINTAINARR_ADDR=:8080
ENV MAINTAINARR_DB_PATH=/app/data/maintainarr.db
ENV MAINTAINARR_LOG_ARCHIVE_DIR=/app/data/log-archives
ENV MAINTAINARR_BASE_URL=http://localhost:8080

EXPOSE 8080

CMD ["/app/maintainarr"]
