-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
373 lines (327 loc) · 10.9 KB
/
Dockerfile
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
ARG ALPINE_VERSION=3.20
ARG GOLANG_VERSION=1.23
# ===========================
FROM alpine:${ALPINE_VERSION} as systemd-builder
RUN apk add --no-cache \
autoconf \
bash \
cmake \
coreutils \
g++ \
gcc \
git \
gperf \
libcap-dev \
libseccomp-dev \
lz4-dev \
make \
meson \
musl-dev \
musl-libintl \
ninja \
patch \
py3-jinja2 \
rsync \
util-linux-dev \
xz-dev \
zstd-dev
ARG SYSTEMD_VERSION=v254.4
ARG SYSTEMD_LIB_VERSION=0.37.0
ARG OPENEMBEDDED_CORE_SHA=8063bcb2d4fcfeded5edac3b0895151e8dc8bf0f
ENV CFLAGS=-Os
WORKDIR /work/systemd
RUN cd /work \
&& git clone --depth=1 -b ${SYSTEMD_VERSION} https://github.com/systemd/systemd-stable.git systemd \
&& git clone --depth=10000 https://github.com/openembedded/openembedded-core.git \
&& (cd openembedded-core && git checkout ${OPENEMBEDDED_CORE_SHA}) \
&& cp openembedded-core/meta/recipes-core/systemd/systemd/*.patch systemd/
ENV CFLAGS=-D__UAPI_DEF_ETHHDR=0
RUN ls -1 *.patch | xargs -n1 patch -p1 -i
RUN ./configure \
-Dgshadow=false \
-Didn=false \
-Dutmp=false
RUN ninja -C build libsystemd.so.${SYSTEMD_LIB_VERSION}
RUN cp -v $(find build -name "libsystemd.so.${SYSTEMD_LIB_VERSION}" -type f) /usr/local/lib/
RUN strip -s /usr/local/lib/libsystemd.so.${SYSTEMD_LIB_VERSION}
# ===========================
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS agent-builder
RUN apk add --no-cache \
aws-cli \
bash \
ca-certificates \
cmake \
curl \
g++ \
gcc \
git \
libffi-dev \
make \
musl-dev \
patch \
py3-boto3 \
py3-botocore \
py3-docker-py \
py3-dulwich \
py3-isort \
py3-packaging \
py3-pip \
py3-prompt_toolkit \
py3-requests \
py3-ruamel.yaml \
py3-semver \
py3-toml \
py3-urllib3=~1 \
py3-wheel \
py3-yaml \
python3-dev
ARG DATADOG_VERSION=7.57.1
# datadog-agent has both branch and tag of the version. refs/tags/version must be checked-out.
RUN git clone --depth=1 https://github.com/DataDog/datadog-agent.git /build/datadog-agent \
&& cd /build/datadog-agent \
&& git fetch --depth=1 origin refs/tags/${DATADOG_VERSION}:refs/tags/${DATADOG_VERSION} \
&& git checkout refs/tags/${DATADOG_VERSION}
WORKDIR /build/datadog-agent
ARG DATADOG_AGENT_BUILDIMAGES_VERSION=bf31b4201bf857cb83549e71913c19cf077861aa
ARG CI_ONLY_DEPS=" \
codeowners \
docker-squash \
reno \
"
ARG SYSTEM_PYTHON_DEPS=" \
awscli \
boto3 \
botocore \
docker \
dulwich \
isort \
packaging \
pyyaml \
requests \
ruamel.yaml \
semver \
toml \
urllib3 \
wheel \
"
RUN mkdir -p buildimages \
&& git -C buildimages init \
&& git -C buildimages remote add origin https://github.com/DataDog/datadog-agent-buildimages.git \
&& git -C buildimages fetch --depth 1 origin ${DATADOG_AGENT_BUILDIMAGES_VERSION} \
&& git -C buildimages checkout FETCH_HEAD \
&& for d in ${CI_ONLY_DEPS} ${SYSTEM_PYTHON_DEPS}; do \
sed "/^$d\(=\|$\)/di" -i requirements.txt buildimages/requirements.txt buildimages/requirements/constraints.txt; \
done \
&& sed 's|-r .*/DataDog/datadog-agent-buildimages/main/requirements.txt|-r buildimages/requirements.txt|' -i requirements.txt \
&& python3 -m pip install -r requirements.txt --break-system-packages
RUN invoke deps
ENV CGO_CFLAGS="-Os -I/build/datadog-agent/dev/include" \
CGO_LDFLAGS="-L/build/datadog-agent/dev/lib" \
GOFLAGS="-ldflags=-w -ldflags=-s"
RUN invoke rtloader.make \
--python-runtimes=3 \
--cmake-options="\
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_CXX_FLAGS=-Os \
-DCMAKE_C_FLAGS=-Os" \
&& invoke rtloader.install
RUN strip -s /build/datadog-agent/dev/lib/*.so
COPY --from=systemd-builder /work/systemd/src/systemd/ /usr/include/systemd/
RUN invoke agent.build \
--python-runtimes=3 \
--exclude-rtloader \
--build-exclude=jmx,kubeapiserver,gce,ec2,orchestrator
RUN mkdir -p /agent-bin \
&& mkdir -p /agent-embedded \
&& touch /agent-bin/.keep
ARG ENABLE_PROCESS_AGENT=0
RUN set -eu; \
if [ ${ENABLE_PROCESS_AGENT} -eq 1 ]; then \
invoke process-agent.build \
--python-runtimes=3; \
mv bin/process-agent/process-agent /agent-bin/; \
fi
ARG ENABLE_SECURITY_AGENT=0
RUN set -eu; \
if [ ${ENABLE_SECURITY_AGENT} -eq 1 ]; then \
invoke security-agent.build; \
mv bin/security-agent/security-agent /agent-bin/; \
fi
ARG ENABLE_TRACE_AGENT=0
RUN set -eu; \
if [ ${ENABLE_TRACE_AGENT} -eq 1 ]; then \
invoke trace-agent.build \
--python-runtimes=3; \
mv bin/trace-agent/trace-agent /agent-bin/; \
fi
RUN mkdir -p \
/opt/datadog-agent/bin/agent/dist \
/opt/datadog-agent/run \
/etc/datadog-agent \
&& touch /opt/datadog-agent/requirements-agent-release.txt \
&& touch /opt/datadog-agent/final_constraints-py3.txt
RUN cp /build/datadog-agent/bin/agent/agent /opt/datadog-agent/bin/agent/agent
RUN cp -r \
/build/datadog-agent/bin/agent/dist/checks \
/build/datadog-agent/bin/agent/dist/config.py \
/build/datadog-agent/bin/agent/dist/utils \
/build/datadog-agent/bin/agent/dist/views \
/opt/datadog-agent/bin/agent/dist/
RUN cp -r /build/datadog-agent/bin/agent/dist/conf.d /etc/datadog-agent/conf.d/
RUN cp \
/build/datadog-agent/Dockerfiles/agent/datadog-docker.yaml \
/build/datadog-agent/Dockerfiles/agent/datadog-ecs.yaml \
/build/datadog-agent/bin/agent/dist/system-probe.yaml \
/etc/datadog-agent/
RUN cp \
/build/datadog-agent/bin/agent/dist/datadog.yaml \
/etc/datadog-agent/datadog.yaml.example
# Remove unused configs
RUN rm -rf \
/etc/datadog-agent/conf.d/apm.yaml.default \
/etc/datadog-agent/conf.d/process_agent.yaml.default \
/etc/datadog-agent/conf.d/winproc.d \
/etc/datadog-agent/conf.d/jmx.d \
/etc/datadog-agent/conf.d/kubernetes_apiserver.d
# ===========================
FROM alpine:${ALPINE_VERSION} AS datadog-agent
RUN apk add \
aws-cli \
bash \
ca-certificates \
coreutils \
libffi \
libgcc \
libseccomp \
libstdc++ \
lz4-libs \
openssl-dev \
py3-cryptography \
py3-jellyfish \
py3-python-gssapi \
py3-packaging \
py3-pip \
py3-prometheus-client \
py3-protobuf \
py3-psutil \
py3-pysocks \
py3-requests \
py3-requests-toolbelt \
py3-simplejson \
py3-six \
py3-wheel \
py3-wrapt \
py3-yaml \
python3 \
xz-libs \
zstd-libs \
&& rm -f /var/cache/apk/* \
&& find /usr -name "*.pyc" -delete \
&& find /usr -name "__pycache__" -delete
RUN echo -e "[global]\nbreak-system-packages = true" >> /etc/pip.conf
ARG S6_OVERLAY_VERSION=2.1.0.2
RUN wget https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-amd64.tar.gz \
&& tar xzf /s6-overlay-amd64.tar.gz \
&& rm /s6-overlay-amd64.tar.gz
RUN mkdir -p \
/checks.d \
/conf.d \
/opt/datadog-agent \
/opt/datadog-agent/run \
/var/log/datadog \
&& touch /opt/datadog-agent/requirements-agent-release.txt \
&& touch /opt/datadog-agent/final_constraints-py3.txt \
&& ln -s /usr /opt/datadog-agent/embedded
COPY --from=systemd-builder /usr/local/lib/libsystemd.so* /usr/lib/
RUN SYSTEMD_SO=$(find /usr/lib/ -name "libsystemd.so.*.*.*" | head -n1) \
&& ln -s ${SYSTEMD_SO} $(echo ${SYSTEMD_SO} | sed 's/.[0-9]\+$//') \
&& ln -s ${SYSTEMD_SO} $(echo ${SYSTEMD_SO} | sed 's/.[0-9]\+.[0-9]\+$//') \
&& ln -s ${SYSTEMD_SO} $(echo ${SYSTEMD_SO} | sed 's/.[0-9]\+.[0-9]\+.[0-9]\+$//')
# Install datadog agent
COPY --from=agent-builder /build/datadog-agent/Dockerfiles/agent/s6-services /etc/services.d/
COPY --from=agent-builder /build/datadog-agent/Dockerfiles/agent/cont-init.d /etc/cont-init.d/
COPY --from=agent-builder /build/datadog-agent/Dockerfiles/agent/entrypoint.sh /bin/entrypoint.sh
COPY --from=agent-builder /build/datadog-agent/Dockerfiles/agent/entrypoint.d /opt/entrypoints
COPY --from=agent-builder \
/build/datadog-agent/Dockerfiles/agent/probe.sh \
/build/datadog-agent/Dockerfiles/agent/initlog.sh \
/build/datadog-agent/Dockerfiles/agent/secrets-helper/readsecret.py \
/
COPY --from=agent-builder /build/datadog-agent/dev/lib/* /usr/lib/
COPY --from=agent-builder /etc/datadog-agent /etc/datadog-agent/
COPY --from=agent-builder /opt/datadog-agent /opt/datadog-agent/
COPY --from=agent-builder /agent-bin/* /usr/bin/
COPY --from=agent-builder /agent-embedded /usr/
# Disable omitted agents
RUN if [ ! -f /usr/bin/process-agent ]; then rm -rf /etc/services.d/process; fi \
&& if [ ! -f /usr/bin/security-agent ]; then rm -rf /etc/services.d/security; fi \
&& if [ ! -f /usr/bin/trace-agent ]; then rm -rf /etc/services.d/trace; fi \
&& if [ ! -f /usr/bin/system-probe ]; then rm -rf /etc/services.d/sysprobe; fi
ENV DOCKER_DD_AGENT=true \
DD_PYTHON_VERSION=3 \
PATH=/opt/datadog-agent/bin/agent/:/opt/datadog-agent/embedded/bin:$PATH \
S6_KEEP_ENV=1 \
S6_LOGGING=0 \
S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \
S6_READ_ONLY_ROOT=1
ARG INTEGRATIONS_CORE="\
btrfs \
disk \
ssh_check \
statsd \
system_core \
system_swap"
ARG DATADOG_INTEGRATIONS_CORE_VERSION=7.57.1
RUN apk add --virtual .build-deps \
g++ \
gcc \
git \
linux-headers \
musl-dev \
python3-dev \
&& git clone --depth=1 https://github.com/DataDog/integrations-core.git /tmp/integrations-core \
&& cd /tmp/integrations-core \
&& git fetch --depth=1 origin refs/tags/${DATADOG_INTEGRATIONS_CORE_VERSION}:refs/tags/${DATADOG_INTEGRATIONS_CORE_VERSION} \
&& git checkout refs/tags/${DATADOG_INTEGRATIONS_CORE_VERSION} \
&& for d in \
botocore \
cryptography \
gssapi \
jellyfish \
prometheus-client \
protobuf \
pysocks \
pyyaml \
requests \
requests_toolbelt \
simplejson \
six \
wheel \
wrapt \
; do \
sed "/\"$d=/di" -i datadog_checks_base/pyproject.toml; \
done \
&& python3 -m pip install \
"./datadog_checks_base[deps, http]" \
$(echo ${INTEGRATIONS_CORE} | xargs -n1 echo | sed 's|^|./|') \
&& apk del --force-broken-world .build-deps \
&& cd / && rm -rf /tmp/integrations-core \
&& rm -f /var/cache/apk/* \
&& find /usr -name "*.pyc" -delete \
&& find /usr -name "__pycache__" -delete \
&& rm -rf \
/usr/lib/python*/site-packages/twisted/test \
/usr/lib/python*/site-packages/docutils
# note: removed packages from datadog_checks_base/pyproject.toml
# botocore: seems not used at all https://github.com/DataDog/integrations-core/search?q=botocore
# other packages: installed as Alpine package
# note: removed directories
# twisted/test: unit test of twisted package
# docutils: indirect dev dependency
EXPOSE 8125/udp 8126/tcp
HEALTHCHECK --interval=30s --timeout=5s --retries=2 \
CMD ["/probe.sh"]
ARG DATADOG_VERSION=7.57.1
ENV DATADOG_INTEGRATIONS_CORE_VERSION=${DATADOG_INTEGRATIONS_CORE_VERSION} \
DATADOG_VERSION=${DATADOG_VERSION}
CMD ["/bin/entrypoint.sh"]