-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathContainerfile
More file actions
125 lines (110 loc) · 5.83 KB
/
Copy pathContainerfile
File metadata and controls
125 lines (110 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Stage 1: Build websocat from vendored source
# websocat v1.14.1 — update via: make vendor-update VENDOR_NAME=websocat VENDOR_VERSION=v<NEW>
# Rust compat: https://github.com/vi/websocat#rust-versions — verify after bumping either version
# https://registry.access.redhat.com/ubi10
FROM registry.access.redhat.com/ubi10:10.2-1788218897@sha256:4690398669a07627339936c9e79b05233053056ce688efeb4400d3c1c530486b AS websocat-builder
RUN dnf install -y --setopt=install_weak_deps=0 --nodocs rust-toolset && \
dnf clean all
COPY vendor/websocat /src/websocat
WORKDIR /src/websocat
RUN cargo build --release \
--no-default-features --features signal_handler,unix_stdio && \
cp target/release/websocat /tmp/websocat && \
/tmp/websocat --version
# Stage 2a: Install helm from Red Hat CGW mirror (default)
# Comment this out and uncomment Stage 2b below when no binary available.
# https://registry.access.redhat.com/ubi10-minimal
FROM registry.access.redhat.com/ubi10-minimal:10.2-1788137716@sha256:d801168f5e8b108586c27a4fd5c92e3c1e8d061084383713926e2ca61b8b6c64 AS helm-builder
ARG TARGETPLATFORM
COPY Makefile artifacts.lock.yaml /tmp/
COPY hack/install-helm-binary.sh hack/verify-helm-tarball.sh /tmp/
RUN microdnf install -y --setopt=install_weak_deps=0 --nodocs tar gzip bash \
&& microdnf clean all \
&& HELM_VERSION=$(grep '^HELM_VERSION' /tmp/Makefile | sed 's/.*:= *//') \
&& CONTAINER_BUILD=true TARGETPLATFORM="${TARGETPLATFORM}" HELM_VERSION="${HELM_VERSION}" \
LOCKFILE=/tmp/artifacts.lock.yaml VERIFY_SCRIPT=/tmp/verify-helm-tarball.sh \
bash /tmp/install-helm-binary.sh \
&& rm -f /tmp/Makefile /tmp/artifacts.lock.yaml /tmp/install-helm-binary.sh /tmp/verify-helm-tarball.sh
# Stage 2b: Build helm from vendored source (use when no binary available in Stage 2a)
# Swap with Stage 2a: comment out Stage 2a, uncomment below, and use gomod prefetch instead of generic.
# update via: make vendor-update VENDOR_NAME=helm VENDOR_VERSION=v<NEW>
# https://registry.access.redhat.com/ubi10/go-toolset
# FROM registry.access.redhat.com/ubi10/go-toolset:1.26.5-1786496329@sha256:1db86a2b0f77c1197b011de5140236effc27b1a1724c0105d4926857a0756de5 AS helm-builder
# COPY Makefile /tmp/Makefile
# COPY vendor/helm /opt/app-root/src/helm
# WORKDIR /opt/app-root/src/helm
# RUN HELM_VERSION=$(grep '^HELM_VERSION' /tmp/Makefile | sed 's/.*:= *//') && \
# CGO_ENABLED=0 go build -mod=vendor -trimpath \
# -ldflags "-X helm.sh/helm/v4/internal/version.version=v${HELM_VERSION}" \
# -o /tmp/helm ./cmd/helm && \
# /tmp/helm version
# Stage 3: Final image
# https://registry.access.redhat.com/ubi10-minimal
FROM registry.access.redhat.com/ubi10-minimal:10.2-1788137716@sha256:d801168f5e8b108586c27a4fd5c92e3c1e8d061084383713926e2ca61b8b6c64
# Define build argument before using it in LABEL
ARG RHDH_MUST_GATHER_VERSION="0.0.0-unknown"
# Must-gather image for Red Hat Developer Hub (RHDH)
LABEL name="rhdh-must-gather" \
vendor="Red Hat" \
version="$RHDH_MUST_GATHER_VERSION" \
summary="Red Hat Developer Hub (RHDH) must-gather tool" \
description="Collects diagnostic information from RHDH deployments on Kubernetes and OpenShift clusters"
# Install basic tools and dependencies needed for must-gather operations
# Note: UBI10-minimal already has curl-minimal and coreutils-single installed
# We use --setopt=install_weak_deps=0 to avoid unnecessary dependencies
# and --nodocs to reduce image size
# findutils: provides find, xargs
# grep, sed: text processing used in sanitization and data collection
# jq: JSON processing (validated in common.sh)
# python3, python3-pip: required for yq (kislyuk/yq — jq wrapper for YAML)
# util-linux: provides setsid (required by oc adm must-gather)
# rsync: file synchronization tool (required by oc adm must-gather)
RUN microdnf install -y --setopt=install_weak_deps=0 --nodocs \
tar \
gzip \
bash \
findutils \
grep \
sed \
jq \
python3 \
python3-pip \
util-linux \
rsync \
&& microdnf clean all
COPY Makefile /tmp/Makefile
# argcomplete 3.7+ uses PEP 604 union types (str | bytes) in class-level
# annotations, which Python 3.9 evaluates at class definition time and fails.
# The hermetic Containerfile pins argcomplete via hash-locked requirements.txt.
RUN YQ_VERSION=$(grep '^YQ_VERSION' /tmp/Makefile | sed 's/.*:= *//') \
&& pip3 install --no-cache-dir "yq==${YQ_VERSION}" \
&& rm /tmp/Makefile
# Install oc and kubectl (OpenShift CLI)
# The OpenShift client package includes both oc and kubectl
# oc is required for OpenShift-specific features like 'oc adm inspect' and routes
# renovate: datasource=custom.openshift-client
RUN curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable-4.21/openshift-client-linux.tar.gz \
| tar xz -C /usr/local/bin/ oc kubectl \
&& chmod +x /usr/local/bin/oc /usr/local/bin/kubectl \
&& oc version --client \
&& kubectl version --client
# Copy helm binary from CGW mirror (helm-builder stage)
COPY --from=helm-builder /tmp/helm /usr/local/bin/helm
# Copy websocat binary built from source (vendor/websocat)
COPY --from=websocat-builder /tmp/websocat /usr/local/bin/websocat
# Create non-root user for running the container
# Using UID 1001 which is commonly used and works well with OpenShift's arbitrary UID assignment
RUN microdnf install -y --setopt=install_weak_deps=0 --nodocs shadow-utils \
&& groupadd -g 1001 must-gather \
&& useradd -u 1001 -g must-gather -s /bin/bash -m must-gather \
&& microdnf remove -y shadow-utils \
&& microdnf clean all
# Use our gather script in place of the original one
# Copy collection scripts
COPY collection-scripts/* /usr/bin/
RUN mv /usr/bin/must_gather /usr/bin/gather
# Set environment variable from build argument
ENV RHDH_MUST_GATHER_VERSION=$RHDH_MUST_GATHER_VERSION
# Run as non-root user
USER 1001
ENTRYPOINT ["/usr/bin/gather"]