22# Produces a compact container image with roxie and all required dependencies
33# Supports multi-architecture builds (amd64, arm64)
44
5- # Stage 1: Build roxie binary
6- FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi9/go-toolset:1.25@sha256:2830e4bd1c394ed506c00a9abbb4d00445e2e72e8ef4e3cd51e0da0db66dee12 AS builder
5+ # Supports standard and slim variant.
6+ # Slim variant doesn't come with support for GKE gcloud authentication, Azure, AWS.
7+ # Useful for distributing roxie binaries via image registry.
8+ ARG VARIANT=standard
79
8- # Build arguments for cross-compilation
9- # These are automatically provided by Docker buildx
10+ # STAGE: builder-slim.
11+ FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi9/go-toolset:1.25@sha256:2830e4bd1c394ed506c00a9abbb4d00445e2e72e8ef4e3cd51e0da0db66dee12 AS builder-slim
12+
13+ # # Install required tools via microdnf.
14+ # RUN microdnf install -y \
15+ # podman fuse-overlayfs \
16+ # # Core utilities
17+ # tar \
18+ # gzip \
19+ # unzip \
20+ # ca-certificates \
21+ # # Clean up
22+ # && microdnf clean all \
23+ # && rm -rf /var/cache/yum
24+
25+ # Build arguments for cross-compilation.
26+ # These are automatically provided by Docker buildx.
1027ARG TARGETOS
1128ARG TARGETARCH
29+ ARG VERSION
30+ ARG BUILD_DATE
31+ ARG GIT_COMMIT
1232
1333WORKDIR /build
1434
@@ -19,16 +39,6 @@ RUN go mod download
1939# Copy source code
2040COPY . .
2141
22- # Build roxie binary with version info and cross-compilation support
23- ARG VERSION=0.1
24- ARG GIT_COMMIT=unknown
25- ARG BUILD_DATE=unknown
26- RUN echo "Building for ${TARGETOS}/${TARGETARCH}" && \
27- CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
28- -ldflags "-w -s -X main.version=${VERSION} -X main.gitCommit=${GIT_COMMIT} -X main.buildDate=${BUILD_DATE}" \
29- -o roxie \
30- ./cmd
31-
3242# Download gcloud SDK in builder stage to avoid UBI filesystem restrictions
3343# Latest version including checksums can be found at:
3444# https://docs.cloud.google.com/sdk/docs/install-sdk#linux
@@ -133,6 +143,14 @@ RUN ARCH=${TARGETARCH:-amd64} && \
133143 echo "${KUBECTL_SHA256} /usr/local/bin/kubectl" | sha256sum -c - && \
134144 chmod +x /usr/local/bin/kubectl
135145
146+ RUN CGO_ENABLED=0 \
147+ GOOS=${TARGETOS} \
148+ GOARCH=${TARGETARCH} \
149+ VERSION=${VERSION} \
150+ BUILD_DATE=${BUILD_DATE} \
151+ GIT_COMMIT=${GIT_COMMIT} \
152+ make build && cp /build/roxie /usr/local/bin/roxie
153+
136154# Install roxctl - architecture-aware
137155# The mirror has architecture-specific binaries: 'roxctl' (amd64) and 'roxctl-arm64'
138156ARG ROXCTL_VERSION=4.10.0
@@ -155,29 +173,44 @@ RUN ARCH=${TARGETARCH:-amd64} && \
155173 echo "${ROXCTL_SHA256} /usr/local/bin/roxctl" | sha256sum -c - && \
156174 chmod +x /usr/local/bin/roxctl
157175
158- # Install podman (required for extracting operator bundles)
159- # fuse-overlayfs provides better performance but vfs driver is more compatible
160- RUN microdnf install -y podman fuse-overlayfs \
161- && microdnf clean all
176+ # Install kubectl - architecture-aware
177+ ARG KUBECTL_VERSION=v1.35.3
178+ RUN ARCH=${TARGETARCH:-amd64} && \
179+ echo "Installing kubectl for ${ARCH}" && \
180+ curl -fsSLo /usr/local/bin/kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl"
162181
163- # Install common kubectl credential plugins for cloud provider authentication
164- # This enables kubectl to work with GKE, EKS, AKS, and OpenShift clusters
165- # without requiring users to manage different auth plugins
182+ COPY scripts/roxcurl /usr/local/bin/roxcurl
166183
167- # 1. Google Cloud (GKE) - gke-gcloud-auth-plugin
168- # Copy gcloud SDK from builder stage (extracted there to avoid UBI filesystem restrictions)
169- COPY --from=builder /tmp/google-cloud-sdk /opt/google-cloud-sdk
170- RUN ln -s /opt/google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud && \
171- ln -s /opt/google-cloud-sdk/bin/gke-gcloud-auth-plugin /usr/local/bin/gke-gcloud-auth-plugin
184+ RUN chown 1001:0 /usr/local/bin/* && chmod +x /usr/local/bin/*
185+
186+ # STAGE: builder-standard (based on builder-slim).
187+
188+ FROM builder-slim AS builder-standard
189+
190+ ARG TARGETARCH
191+
192+ # Default python 3.9 from the go-toolset image is not supported by the gcloud SDK.
193+ RUN dnf install -y python312 && alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
194+ # Download gcloud SDK in builder stage to avoid UBI filesystem restrictions.
195+ ARG GCLOUD_VERSION=561.0.0
196+ RUN ARCH=${TARGETARCH:-amd64} && \
197+ if [ "${ARCH}" = "amd64" ]; then \
198+ GCLOUD_ARCH="x86_64" ; \
199+ elif [ "${ARCH}" = "arm64" ]; then \
200+ GCLOUD_ARCH="arm" ; \
201+ else \
202+ echo "ERROR: Unsupported architecture: ${ARCH}" ; exit 1; \
203+ fi && \
204+ curl -fsSL "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-${GCLOUD_VERSION}-linux-${GCLOUD_ARCH}.tar.gz" | \
205+ tar -xz -C /tmp && \
206+ /tmp/google-cloud-sdk/bin/gcloud components install gke-gcloud-auth-plugin --quiet
172207
173208# 2. AWS (EKS) - aws-iam-authenticator
174209# Using GitHub releases for latest version (AWS S3 bucket has outdated versions)
175210ARG AWS_IAM_AUTH_VERSION=0.7.12
176211RUN ARCH=${TARGETARCH:-amd64} && \
177212 echo "Installing aws-iam-authenticator v${AWS_IAM_AUTH_VERSION} for ${ARCH}" && \
178- curl -fsSLo /usr/local/bin/aws-iam-authenticator \
179- "https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${AWS_IAM_AUTH_VERSION}/aws-iam-authenticator_${AWS_IAM_AUTH_VERSION}_linux_${ARCH}" && \
180- chmod +x /usr/local/bin/aws-iam-authenticator
213+ curl -fsSLo /usr/local/bin/aws-iam-authenticator "https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${AWS_IAM_AUTH_VERSION}/aws-iam-authenticator_${AWS_IAM_AUTH_VERSION}_linux_${ARCH}"
181214
182215# 3. Azure (AKS) - kubelogin
183216RUN ARCH=${TARGETARCH:-amd64} && \
@@ -187,13 +220,26 @@ RUN ARCH=${TARGETARCH:-amd64} && \
187220 -o /tmp/kubelogin.zip && \
188221 unzip -q /tmp/kubelogin.zip -d /tmp && \
189222 mv /tmp/bin/linux_${ARCH}/kubelogin /usr/local/bin/kubelogin && \
190- chmod +x /usr/local/bin/kubelogin && \
191223 rm -rf /tmp/kubelogin.zip /tmp/bin
192224
193- # Copy roxie binary and scripts from builder
194- COPY --from=builder /build/roxie /usr/local/bin/roxie
195- COPY scripts/roxcurl /usr/local/bin/roxcurl
196- RUN chmod +x /usr/local/bin/roxcurl
225+ RUN chmod +x /usr/local/bin/*
226+
227+ # STAGE: runtime-slim (copies from builder-slim).
228+ FROM registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:83006d535923fcf1345067873524a3980316f51794f01d8655be55d6e9387183 AS runtime-slim
229+
230+ ARG VARIANT=standard
231+
232+ USER 0
233+
234+ RUN microdnf install -y \
235+ podman fuse-overlayfs \
236+ # Core utilities
237+ tar \
238+ gzip \
239+ unzip \
240+ ca-certificates && \
241+ # Clean up
242+ microdnf clean all && rm -rf /var/cache/yum
197243
198244# Create non-root user with / as home directory for simplified volume mounting
199245# This allows users to mount credentials directly at their standard paths:
@@ -213,17 +259,48 @@ RUN mkdir -p /etc/containers && \
213259 echo 'graphroot = "/.local/share/containers/storage"' >> /etc/containers/storage.conf && \
214260 chmod 644 /etc/containers/storage.conf /etc/containers/registries.conf
215261
216- # Set working directory
217- WORKDIR /workspace
262+ LABEL maintainer="StackRox" \
263+ description="roxie - Advanced Cluster Security deployment tool with all dependencies" \
264+ io.k8s.description="Deploy and manage Red Hat Advanced Cluster Security on Kubernetes clusters" \
265+ io.k8s.display-name="roxie ACS Deployment Tool (${VARIANT} variant)"
266+
267+ # Copy executables from builder.
268+ COPY --from=builder-slim /usr/local/bin/* /usr/local/bin
218269
219- # Switch to non-root user (users can override with --user root if needed)
220270USER roxie
271+ WORKDIR /
221272
222- # Set environment variables
223273ENV HOME=/ \
224274 KUBECONFIG=/kubeconfig \
225275 PATH=/usr/local/bin:$PATH
226276
227277# Display version information on container start
228278ENTRYPOINT ["/usr/local/bin/roxie" ]
229279CMD ["--help" ]
280+
281+ FROM runtime-slim AS runtime-standard
282+
283+ USER 0
284+
285+ # Install required tools via microdnf.
286+ RUN microdnf install -y python312 && \
287+ alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
288+ microdnf clean all && \
289+ rm -rf /var/cache/yum
290+
291+ # Copy executables from builder.
292+ COPY --from=builder-slim --chown=0:0 /usr/local/bin/* /usr/local/bin
293+
294+ # Install common kubectl credential plugins for cloud provider authentication
295+ # This enables kubectl to work with GKE, EKS, AKS, and OpenShift clusters
296+ # without requiring users to manage different auth plugins
297+
298+ # 1. Google Cloud (GKE) - gke-gcloud-auth-plugin
299+ # Copy gcloud SDK from builder stage (extracted there to avoid UBI filesystem restrictions)
300+ COPY --from=builder-standard /tmp/google-cloud-sdk /opt/google-cloud-sdk
301+ RUN ln -s /opt/google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud && \
302+ ln -s /opt/google-cloud-sdk/bin/gke-gcloud-auth-plugin /usr/local/bin/gke-gcloud-auth-plugin
303+
304+ USER roxie
305+
306+ FROM runtime-${VARIANT} AS final
0 commit comments