# Stage 1: Builder
FROM golang:1.25-alpine AS builder

WORKDIR /app

# Install git and build dependencies
RUN apk add --no-cache git

# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o api ./cmd/api && \
    CGO_ENABLED=0 GOOS=linux go build -o seed ./cmd/seed

# Stage 2: Production
FROM alpine:latest AS production

RUN apk --no-cache add ca-certificates

WORKDIR /app

# Copy binary from builder
COPY --from=builder /app/api .
COPY --from=builder /app/seed .

# Copy migrations
COPY internal/db/migrations ./migrations

EXPOSE 8080

CMD ["./api"]
