Templating creating new policy
This commit is contained in:
38
Dockerfile
38
Dockerfile
@@ -1,31 +1,37 @@
|
||||
# ---- Build Stage ----
|
||||
FROM golang:latest AS builder
|
||||
FROM golang:1.26 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod files first (better caching)
|
||||
COPY go.mod ./
|
||||
RUN go mod download
|
||||
# ---- Step 1: Copy go.mod/go.sum for caching ----
|
||||
# Copy only the minimal files first for layer caching
|
||||
COPY libshared/go.mod libshared/go.sum ./libshared/
|
||||
COPY policy-manager/go.mod policy-manager/go.sum ./policy-manager/
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
# ---- Step 2: Download dependencies ----
|
||||
RUN go -C libshared mod download
|
||||
RUN go -C policy-manager mod download
|
||||
|
||||
# Build static binary
|
||||
# ---- Step 3: Copy full source code ----
|
||||
COPY libshared ./libshared
|
||||
COPY policy-manager ./policy-manager
|
||||
|
||||
# ---- Step 4: Create Go workspace inside container ----
|
||||
RUN go work init ./policy-manager ./libshared
|
||||
|
||||
## Optional: verify workspace
|
||||
#RUN go work list
|
||||
|
||||
# ---- Step 5: Build binary ----
|
||||
WORKDIR /app/policy-manager
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server
|
||||
|
||||
# ---- Runtime Stage ----
|
||||
FROM gcr.io/distroless/base-debian12
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/policy-manager/server .
|
||||
|
||||
# Copy only the binary from builder
|
||||
COPY --from=builder /app/server .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8080
|
||||
|
||||
# Run as non-root user
|
||||
USER nonroot:nonroot
|
||||
|
||||
ENTRYPOINT ["/app/server"]
|
||||
|
||||
ENTRYPOINT ["/app/server"]
|
||||
Reference in New Issue
Block a user