|
| 1 | +# Multi-stage Dockerfile for ACS MCP Server build on Konflux |
| 2 | + |
| 3 | +# Stage 1: Builder - Build the Go binary |
| 4 | +FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_9_golang_1.25@sha256:bd531796aacb86e4f97443797262680fbf36ca048717c00b6f4248465e1a7c0c AS builder |
| 5 | + |
| 6 | +# Build arguments for application version and branding |
| 7 | +ARG VERSION=dev |
| 8 | +ARG SERVER_NAME="acs-mcp-server" |
| 9 | +ARG PRODUCT_DISPLAY_NAME="Red Hat Advanced Cluster Security (ACS)" |
| 10 | + |
| 11 | +# Set working directory |
| 12 | +WORKDIR /workspace |
| 13 | + |
| 14 | +# Copy go module files first for better layer caching |
| 15 | +COPY go.mod go.sum ./ |
| 16 | + |
| 17 | +# Download dependencies (cached layer) |
| 18 | +RUN go mod download |
| 19 | + |
| 20 | +# Copy source code |
| 21 | +COPY . . |
| 22 | + |
| 23 | +# Build the binary with optimizations |
| 24 | +# Output to "/tmp" directory, because user can not copy built binary to "/workspace" |
| 25 | +# Go build uses "venodr" mode and that fails, that's why explicit "-mod=mod" is set. |
| 26 | +RUN RACE=0 CGO_ENABLED=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) \ |
| 27 | + go build \ |
| 28 | + -mod=mod \ |
| 29 | + -ldflags="-w -s \ |
| 30 | + -X 'github.com/stackrox/stackrox-mcp/internal/config.version=${VERSION}' \ |
| 31 | + -X 'github.com/stackrox/stackrox-mcp/internal/config.serverName=${SERVER_NAME}' \ |
| 32 | + -X 'github.com/stackrox/stackrox-mcp/internal/config.productDisplayName=${PRODUCT_DISPLAY_NAME}'" \ |
| 33 | + -trimpath \ |
| 34 | + -o /tmp/stackrox-mcp \ |
| 35 | + ./cmd/stackrox-mcp |
| 36 | + |
| 37 | +# Stage 2: Runtime - Minimal runtime image |
| 38 | +FROM registry.access.redhat.com/ubi9/ubi-micro@sha256:093a704be0eaef9bb52d9bc0219c67ee9db13c2e797da400ddb5d5ae6849fa10 |
| 39 | + |
| 40 | +# Set default environment variables |
| 41 | +ENV LOG_LEVEL=INFO |
| 42 | + |
| 43 | +# Set working directory |
| 44 | +WORKDIR /app |
| 45 | + |
| 46 | +# Copy trusted certificates from builder |
| 47 | +COPY --from=builder /etc/pki/ca-trust/extracted/ /etc/pki/ca-trust/extracted/ |
| 48 | +COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/ |
| 49 | + |
| 50 | +# Copy binary from builder |
| 51 | +COPY --from=builder /tmp/stackrox-mcp /app/stackrox-mcp |
| 52 | + |
| 53 | +# Set ownership for OpenShift arbitrary UID support |
| 54 | +# Files owned by 4000, group 0 (root), with group permissions matching user |
| 55 | +RUN chown -R 4000:0 /app && \ |
| 56 | + chmod -R g=u /app |
| 57 | + |
| 58 | +# Switch to non-root user (can be overridden by OpenShift SCC) |
| 59 | +USER 4000 |
| 60 | + |
| 61 | +# Expose port for MCP server |
| 62 | +EXPOSE 8080 |
| 63 | + |
| 64 | +# Run the application |
| 65 | +ENTRYPOINT ["/app/stackrox-mcp"] |
0 commit comments