# Base stage
FROM golang:1.25-alpine AS base
WORKDIR /app
RUN apk add --no-cache git curl
COPY go.mod go.sum ./
RUN go mod download

# Development stage
FROM base AS dev
RUN go install github.com/air-verse/air@latest
COPY . .
EXPOSE 8090
CMD ["air", "-c", ".air.toml"]

# Builder stage
FROM base AS builder
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

# Production stage
FROM alpine:latest AS prod
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/main .
COPY --from=builder /app/pb_public ./pb_public
COPY --from=builder /app/migrations ./migrations
EXPOSE 8090
CMD ["./main", "serve", "--dev", "--http", "0.0.0.0:8090"]
