This commit is contained in:
14
Dockerfile
14
Dockerfile
@@ -3,35 +3,31 @@
|
|||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
FROM golang:1.25-alpine AS builder
|
FROM golang:1.25-alpine AS builder
|
||||||
|
|
||||||
# Install build tools
|
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Download dependencies first (better caching)
|
# Dependencies first (cache friendly)
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
# Copy source
|
# Copy the entire codebase
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build statically for small final image
|
# Build for the architecture of the host (ARM64 runner)
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server .
|
RUN CGO_ENABLED=0 go build -o server .
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# 2. Final minimal image
|
# 2. Final minimal runtime image
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
FROM alpine:3.20
|
FROM alpine:3.20
|
||||||
|
|
||||||
# Add non-root user for security
|
|
||||||
RUN adduser -D -g '' appuser
|
RUN adduser -D -g '' appuser
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy compiled binary
|
|
||||||
COPY --from=builder /app/server .
|
COPY --from=builder /app/server .
|
||||||
|
|
||||||
# Expose Gin port (change if your app uses another)
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|||||||
Reference in New Issue
Block a user