37 lines
710 B
Plaintext
37 lines
710 B
Plaintext
# ================================
|
||
# 1️⃣ Builder Stage
|
||
# ================================
|
||
FROM golang:1.25.3-alpine AS builder
|
||
|
||
WORKDIR /app
|
||
|
||
# Install git jika pakai private module
|
||
RUN apk add --no-cache git
|
||
|
||
# Cache dependency
|
||
COPY go.mod go.sum ./
|
||
RUN go mod download
|
||
|
||
# Copy source
|
||
COPY . .
|
||
|
||
# Build dari cmd/api
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
||
go build -ldflags="-s -w" \
|
||
-o app ./cmd/api
|
||
|
||
# ================================
|
||
# 2️⃣ Final Stage (Distroless)
|
||
# ================================
|
||
FROM gcr.io/distroless/base-debian12
|
||
|
||
WORKDIR /app
|
||
|
||
COPY --from=builder /app/app .
|
||
|
||
# Run as non-root (distroless default user)
|
||
USER nonroot:nonroot
|
||
|
||
EXPOSE 8080
|
||
|
||
ENTRYPOINT ["/app/app"] |