# ----- build -----
FROM golang:1.24 AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

COPY . .
# Si ton main est à la racine (main.go), garde ./ ; sinon mets le chemin du main
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/shelfy .

# ----- runtime -----
FROM alpine:3.20
# sh est présent (utile pour le "tee")
RUN adduser -D -u 10001 appuser
WORKDIR /app
COPY --from=builder /out/shelfy /app/shelfy
RUN chmod +x /app/shelfy && mkdir -p /app/data /app/upload /var/log/shelfy && chown -R appuser:appuser /app
USER appuser
ENTRYPOINT ["/bin/sh","-c","/app/shelfy 2>&1 | tee -a /var/log/shelfy/shelfy.log"]
