# Build stage
FROM golang:1.24-alpine AS builder

WORKDIR /app

# Copy dependency files first for layer caching
COPY go.mod go.sum ./
RUN go mod download

# Copy source
COPY . .

# Build binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /gateway ./main.go

# ─────────────────────────────────────────────
# Runtime stage
FROM alpine:3.21

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

WORKDIR /app

# Copy binary and swagger docs
COPY --from=builder /gateway .
COPY --from=builder /app/docs ./docs

# Non-root user for security
RUN addgroup -S gateway && adduser -S gateway -G gateway
USER gateway

EXPOSE 8000

ENTRYPOINT ["/app/gateway"]
