@@ -23,7 +23,7 @@ COPY . .
2323# Build the binary with optimizations
2424# Output to "/tmp" directory, because user can not copy built binary to "/workspace"
2525# 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) \
26+ RUN RACE=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) \
2727 go build \
2828 -mod=mod \
2929 -ldflags="-w -s \
@@ -34,18 +34,43 @@ RUN RACE=0 CGO_ENABLED=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) \
3434 -o /tmp/stackrox-mcp \
3535 ./cmd/stackrox-mcp
3636
37- # Stage 2: Runtime - Minimal runtime image
38- FROM registry.access.redhat.com/ubi9/ubi-micro@sha256:093a704be0eaef9bb52d9bc0219c67ee9db13c2e797da400ddb5d5ae6849fa10
37+
38+ # Stage 2: Runtime base - used to preserve rpmdb when installing packages
39+ FROM registry.access.redhat.com/ubi9/ubi-micro:latest@sha256:093a704be0eaef9bb52d9bc0219c67ee9db13c2e797da400ddb5d5ae6849fa10 AS ubi-micro-base
40+
41+
42+ # Stage 3: Package installer - installs ca-certificates and openssl into /ubi-micro-base-root/
43+ FROM registry.access.redhat.com/ubi9/ubi:latest@sha256:05fa0100593c08b5e9dde684cd3eaa94b4d5d7b3cc09944f1f73924e49fde036 AS package_installer
44+
45+ # Copy ubi-micro base to /ubi-micro-base-root/ to preserve its rpmdb
46+ COPY --from=ubi-micro-base / /ubi-micro-base-root/
47+
48+ # Install packages directly to /ubi-micro-base-root/ using --installroot
49+ # Note: --setopt=reposdir=/etc/yum.repos.d instructs dnf to use repo configurations pointing to RPMs
50+ # prefetched by Hermeto/Cachi2, instead of installroot's default UBI repos.
51+ # hadolint ignore=DL3041 # We are installing ca-certificates and openssl only to include trusted certs.
52+ RUN dnf install -y \
53+ --installroot=/ubi-micro-base-root/ \
54+ --releasever=9 \
55+ --setopt=install_weak_deps=False \
56+ --setopt=reposdir=/etc/yum.repos.d \
57+ --nodocs \
58+ ca-certificates \
59+ openssl && \
60+ dnf clean all --installroot=/ubi-micro-base-root/ && \
61+ rm -rf /ubi-micro-base-root/var/cache/*
62+
63+
64+ # Stage 4: Runtime - Minimal runtime image
65+ FROM ubi-micro-base
3966
4067# Set default environment variables
4168ENV LOG_LEVEL=INFO
4269
4370# Set working directory
4471WORKDIR /app
4572
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/
73+ COPY --from=package_installer /ubi-micro-base-root/ /
4974
5075# Copy binary from builder
5176COPY --from=builder /tmp/stackrox-mcp /app/stackrox-mcp
0 commit comments