-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjob-exporter.common.dockerfile
More file actions
165 lines (144 loc) · 6.1 KB
/
job-exporter.common.dockerfile
File metadata and controls
165 lines (144 loc) · 6.1 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
############################
# builder: only for compiling python wheels
############################
FROM ubuntu:22.04 AS builder
ARG TARGETARCH
RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
python3-pip \
python3-dev \
build-essential \
gcc; \
rm -rf /var/lib/apt/lists/*
WORKDIR /w
# build wheels once
COPY requirements.txt /w/requirements.txt
RUN python3 -m pip install --no-cache-dir -U pip wheel && \
python3 -m pip wheel --no-cache-dir --wheel-dir /w/wheels \
-r /w/requirements.txt \
prometheus_client psutil filelock
############################
# nerdctl-builder: build nerdctl from source
############################
FROM golang:1.25.7 AS nerdctl-builder
ARG TARGETARCH
ARG NERDCTL_VERSION=2.2.1
WORKDIR /build
RUN set -eux; \
git clone --depth 1 --branch v${NERDCTL_VERSION} https://github.com/containerd/nerdctl.git .; \
make binaries; \
mkdir -p /opt/nerdctl; \
cp _output/nerdctl /opt/nerdctl/nerdctl; \
chmod +x /opt/nerdctl/nerdctl
############################
# runtime: minimal CUDA base with only essential components
############################
FROM mcr.microsoft.com/mirror/nvcr/nvidia/cuda:12.0.1-base-ubuntu22.04
ARG TARGETARCH
ARG ROCM_VERSION=6.2.2
ARG AMDGPU_VERSION=6.2.2
ARG DCGM_TARGET_VERSION=1:4.4.1-1
# --------------------------
# Install all components in single layer for size optimization
# --------------------------
RUN set -eux; \
# Base setup
apt-get update; \
apt-get upgrade -y; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
bash \
ca-certificates \
curl \
gnupg \
python3 \
kmod; \
# ROCm (runtime only) for AMD GPUs
if [ "$TARGETARCH" = "amd64" ]; then \
printf "Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600" \
> /etc/apt/preferences.d/rocm-pin-600; \
curl -sL https://repo.radeon.com/rocm/rocm.gpg.key | apt-key add -; \
echo "deb https://repo.radeon.com/rocm/apt/$ROCM_VERSION/ jammy main" \
> /etc/apt/sources.list.d/rocm.list; \
echo "deb https://repo.radeon.com/amdgpu/$AMDGPU_VERSION/ubuntu jammy main" \
> /etc/apt/sources.list.d/amdgpu.list; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends rdc amd-smi-lib; \
fi; \
# DCGM for GPU monitoring (NVIDIA)
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
datacenter-gpu-manager-4-core=${DCGM_TARGET_VERSION} \
datacenter-gpu-manager-4-cuda12=${DCGM_TARGET_VERSION} \
datacenter-gpu-manager-4-proprietary-cuda12=${DCGM_TARGET_VERSION}; \
# Clean up everything in single layer
apt-get remove -y curl gnupg; \
apt-get autoremove -y; \
apt-get clean; \
rm -rf /var/lib/apt/lists/* /var/cache/apt/* /tmp/* /var/tmp/*
# --------------------------
# nerdctl (copy from nerdctl-builder)
# --------------------------
COPY --from=nerdctl-builder /opt/nerdctl/nerdctl /usr/local/bin/nerdctl
# --------------------------
# python runtime deps (from wheels)
# --------------------------
COPY --from=builder /w/wheels /wheels
COPY requirements.txt /job_exporter/requirements.txt
RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3-pip numactl; \
python3 -m pip install --no-cache-dir -U pip && \
python3 -m pip install --no-cache-dir \
--no-index --find-links=/wheels \
-r /job_exporter/requirements.txt && \
python3 -m pip install --no-cache-dir \
--no-index --find-links=/wheels \
prometheus_client psutil filelock && \
# Set environment variable to allow sudo removal during autoremove
SUDO_FORCE_REMOVE=yes apt-get autoremove -y; \
apt-get clean; \
rm -rf /wheels /root/.cache /var/lib/apt/lists/* /var/cache/apt/* /tmp/* /var/tmp/*
# --------------------------
# app files
# --------------------------
COPY src/Moneo /Moneo
COPY src/*.py /job_exporter/
COPY build/moneo-*-exporter_entrypoint.sh ./
# --------------------------
# Final cleanup: remove unnecessary CUDA files to reduce image size
# --------------------------
RUN set -eux; \
# Remove CUDA static libraries (we only need shared libs for runtime)
find /usr/local/cuda-12.0 -name "*.a" -delete 2>/dev/null || true; \
find /usr/local/cuda-12.0 -name "*.la" -delete 2>/dev/null || true; \
# Remove CUDA development tools and samples
rm -rf /usr/local/cuda-12.0/nsight* \
/usr/local/cuda-12.0/libnvvp \
/usr/local/cuda-12.0/doc \
/usr/local/cuda-12.0/samples \
/usr/local/cuda-12.0/extras \
2>/dev/null || true; \
# Remove documentation and man pages
rm -rf /usr/share/doc/* \
/usr/share/man/* \
/usr/share/info/* \
2>/dev/null || true; \
# Final cache cleanup
rm -rf /var/cache/* /tmp/* /var/tmp/* 2>/dev/null || true