1- FROM golang:1.24-alpine AS builder
2-
3- WORKDIR /app
4-
5- # Copy the source code
6- COPY . .
7-
8- # Build the operator application
9- WORKDIR /app
10- RUN CGO_ENABLED=0 GOOS=linux go build -o /app/bin/client ./cmd/client
11-
12- # Use a small alpine image for the final container
13- FROM alpine:latest
14-
15- # Install basic dependencies
16- RUN apk --no-cache add \
17- ca-certificates \
18- bash \
19- curl \
20- wget \
21- tar \
22- gzip \
23- jq
24-
25- # Install kubectl (multi-arch)
26- RUN ARCH=$(uname -m) && \
27- if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" ; elif [ "$ARCH" = "aarch64" ]; then ARCH="arm64" ; fi && \
28- curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl" && \
29- chmod +x kubectl && \
30- mv kubectl /usr/local/bin/
31-
32- # Install Cilium CLI (multi-arch)
33- RUN ARCH=$(uname -m) && \
34- if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" ; elif [ "$ARCH" = "aarch64" ]; then ARCH="arm64" ; fi && \
35- CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt) && \
36- curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${ARCH}.tar.gz{,.sha256sum} && \
37- sha256sum -c cilium-linux-${ARCH}.tar.gz.sha256sum && \
38- tar xzvfC cilium-linux-${ARCH}.tar.gz /usr/local/bin && \
39- rm cilium-linux-${ARCH}.tar.gz cilium-linux-${ARCH}.tar.gz.sha256sum
40-
41- # Install Trivy (multi-arch)
42- RUN ARCH=$(uname -m) && \
43- if [ "$ARCH" = "x86_64" ]; then TRIVY_ARCH="64bit" ; elif [ "$ARCH" = "aarch64" ]; then TRIVY_ARCH="ARM64" ; fi && \
44- TRIVY_VERSION=$(curl -s "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1 /' | sed 's/v//' ) && \
45- wget https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz && \
46- tar zxvf trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz && \
47- mv trivy /usr/local/bin/ && \
48- rm trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz
49-
50- # Pre-download Trivy vulnerability database during build
51- # This ensures the operator doesn't need internet access at runtime
52- RUN mkdir -p /root/.cache/trivy && \
53- trivy image --download-db-only --cache-dir /root/.cache/trivy && \
54- chmod -R 755 /root/.cache/trivy
55-
56- WORKDIR /app
57-
58- # Set environment variables for Trivy to use offline mode with pre-downloaded DB
59- ENV TRIVY_OFFLINE=true
60- ENV TRIVY_CACHE_DIR=/root/.cache/trivy
61- ENV TRIVY_DB_REPOSITORY=""
62-
63- # Copy the binary from the builder stage
64- COPY --from=builder /app/bin/client .
65-
66- # Verify tools are installed and Trivy database is ready
67- RUN kubectl version --client=true && \
68- cilium version --client && \
69- trivy --version && \
70- echo "Testing Trivy offline mode..." && \
71- trivy image --offline-scan --skip-db-update alpine:latest || echo "Trivy offline test completed (exit code expected for test image)" && \
72- jq --version && \
73- bash --version
74-
75- # Run the client
1+ FROM golang:1.25-alpine AS builder
2+
3+ WORKDIR /app
4+
5+ # Copy the source code
6+ COPY . .
7+
8+ # Build the operator application
9+ WORKDIR /app
10+ RUN CGO_ENABLED=0 GOOS=linux go build -o /app/bin/client ./cmd/client
11+
12+ # Use a small alpine image for the final container
13+ FROM alpine:latest
14+
15+ # Install basic dependencies
16+ RUN apk --no-cache add \
17+ ca-certificates \
18+ bash \
19+ curl \
20+ wget \
21+ tar \
22+ gzip \
23+ jq
24+
25+ # Install kubectl (multi-arch) - pinned to v1.31.0 for reliability
26+ RUN ARCH=$(uname -m) && \
27+ if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" ; elif [ "$ARCH" = "aarch64" ]; then ARCH="arm64" ; fi && \
28+ curl -LO "https://dl.k8s.io/release/v1.31.0/bin/linux/${ARCH}/kubectl" && \
29+ chmod +x kubectl && \
30+ mv kubectl /usr/local/bin/
31+
32+ # Install Cilium CLI (multi-arch)
33+ RUN ARCH=$(uname -m) && \
34+ if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" ; elif [ "$ARCH" = "aarch64" ]; then ARCH="arm64" ; fi && \
35+ CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt) && \
36+ curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${ARCH}.tar.gz{,.sha256sum} && \
37+ sha256sum -c cilium-linux-${ARCH}.tar.gz.sha256sum && \
38+ tar xzvfC cilium-linux-${ARCH}.tar.gz /usr/local/bin && \
39+ rm cilium-linux-${ARCH}.tar.gz cilium-linux-${ARCH}.tar.gz.sha256sum
40+
41+ # Install Trivy (multi-arch)
42+ RUN ARCH=$(uname -m) && \
43+ if [ "$ARCH" = "x86_64" ]; then TRIVY_ARCH="64bit" ; elif [ "$ARCH" = "aarch64" ]; then TRIVY_ARCH="ARM64" ; fi && \
44+ TRIVY_VERSION=$(curl -s "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1 /' | sed 's/v//' ) && \
45+ wget https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz && \
46+ tar zxvf trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz && \
47+ mv trivy /usr/local/bin/ && \
48+ rm trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz
49+
50+ # Install Helm (multi-arch)
51+ RUN ARCH=$(uname -m) && \
52+ if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" ; elif [ "$ARCH" = "aarch64" ]; then ARCH="arm64" ; fi && \
53+ curl -fsSL https://get.helm.sh/helm-v3.16.3-linux-${ARCH}.tar.gz -o helm.tar.gz && \
54+ tar xzf helm.tar.gz && \
55+ mv linux-${ARCH}/helm /usr/local/bin/ && \
56+ rm -rf helm.tar.gz linux-${ARCH}
57+
58+ # Pre-download Trivy vulnerability database during build
59+ # This ensures the operator doesn't need internet access at runtime
60+ RUN mkdir -p /root/.cache/trivy && \
61+ trivy image --download-db-only --cache-dir /root/.cache/trivy && \
62+ chmod -R 755 /root/.cache/trivy
63+
64+ WORKDIR /app
65+
66+ # Set environment variables for Trivy to use offline mode with pre-downloaded DB
67+ ENV TRIVY_OFFLINE=true
68+ ENV TRIVY_CACHE_DIR=/root/.cache/trivy
69+ ENV TRIVY_DB_REPOSITORY=""
70+
71+ # Copy the binary from the builder stage
72+ COPY --from=builder /app/bin/client .
73+
74+ # Verify tools are installed and Trivy database is ready
75+ RUN kubectl version --client=true && \
76+ cilium version --client && \
77+ helm version --short && \
78+ trivy --version && \
79+ echo "Testing Trivy offline mode..." && \
80+ trivy image --offline-scan --skip-db-update alpine:latest || echo "Trivy offline test completed (exit code expected for test image)" && \
81+ jq --version && \
82+ bash --version
83+
84+ # Run the client
7685CMD ["/app/client" ]
0 commit comments