This commit is contained in:
39
Dockerfile
Normal file
39
Dockerfile
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# ------------------------------------------------------------
|
||||||
|
# 1. Build stage
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
FROM golang:1.22-alpine AS builder
|
||||||
|
|
||||||
|
# Install build tools
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Download dependencies first (better caching)
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy source
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build statically for small final image
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server .
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# 2. Final minimal image
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
FROM alpine:3.20
|
||||||
|
|
||||||
|
# Add non-root user for security
|
||||||
|
RUN adduser -D -g '' appuser
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy compiled binary
|
||||||
|
COPY --from=builder /app/server .
|
||||||
|
|
||||||
|
# Expose Gin port (change if your app uses another)
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
CMD ["./server"]
|
||||||
Reference in New Issue
Block a user