FROM golang:1.23-alpine AS builder

RUN apk add --no-cache git ca-certificates

WORKDIR /build

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

COPY . .

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

# ---

FROM alpine:3.19

RUN apk add --no-cache ca-certificates tzdata && \
    addgroup -S autohero && \
    adduser -S autohero -G autohero

COPY --from=builder /build/autohero /usr/local/bin/autohero
COPY migrations/ /app/migrations/

USER autohero
WORKDIR /app

EXPOSE 8080

ENTRYPOINT ["autohero"]
