# ---- Build stage ----
FROM golang:1.22-alpine AS builder

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

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /bin/davserver ./cmd/server

# ---- Runtime stage ----
FROM alpine:3.19

RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app

COPY --from=builder /bin/davserver /usr/local/bin/davserver

# Default data and config locations
VOLUME ["/app/data"]
COPY config.yaml /app/config.yaml

EXPOSE 8080

ENTRYPOINT ["davserver", "-config", "/app/config.yaml"]
