master
text 179 lines 6.54 KB
Raw
1 # SPDX-License-Identifier: GPL-3.0-or-later
2
3 # This image contains preinstalled dependencies
4 # hadolint ignore=DL3007
5 FROM netdata/builder:v3 AS builder
6
7 # One of 'nightly' or 'stable'
8 ARG RELEASE_CHANNEL=nightly
9
10 ARG CFLAGS
11
12 ENV CFLAGS=$CFLAGS
13
14 ARG EXTRA_INSTALL_OPTS
15
16 ENV EXTRA_INSTALL_OPTS=$EXTRA_INSTALL_OPTS
17
18 ARG DEBUG_BUILD
19
20 ENV DEBUG_BUILD=$DEBUG_BUILD
21
22 ARG BUILD_ARCH
23
24 ENV BUILD_ARCH=$BUILD_ARCH
25
26 # Copy source
27 COPY --exclude='**/.git' \
28 --exclude='**/Dockerfile' \
29 . /opt/netdata.git
30 WORKDIR /opt/netdata.git
31
32 # Install from source
33 RUN chmod +x netdata-installer.sh && \
34 cp -rp /deps/* /usr/local/ && \
35 BUILD_ARCH="${BUILD_ARCH:-"$(uname -m)"}" && \
36 /bin/echo -e "INSTALL_TYPE='oci'\nPREBUILT_ARCH='${BUILD_ARCH}'" > ./system/.install-type && \
37 CFLAGS="$(packaging/docker/gen-cflags.sh)" LDFLAGS="-Wl,--gc-sections" ./netdata-installer.sh --dont-wait --dont-start-it \
38 --use-system-protobuf \
39 --disable-ebpf \
40 --enable-plugin-otel \
41 --enable-plugin-otel-signal-viewer \
42 --internal-systemd-journal \
43 ${EXTRA_INSTALL_OPTS} \
44 --install-no-prefix / \
45 "$([ "$RELEASE_CHANNEL" = stable ] && echo --stable-channel)"
46
47 # files to one directory
48 RUN mkdir -p /app/usr/sbin/ \
49 /app/usr/share \
50 /app/usr/libexec \
51 /app/usr/local \
52 /app/usr/lib \
53 /app/var/cache \
54 /app/var/lib \
55 /app/etc && \
56 mv /usr/share/netdata /app/usr/share/ && \
57 mv /usr/libexec/netdata /app/usr/libexec/ && \
58 mv /usr/lib/netdata /app/usr/lib/ && \
59 mv /var/cache/netdata /app/var/cache/ && \
60 mv /var/lib/netdata /app/var/lib/ && \
61 mv /etc/netdata /app/etc/ && \
62 mv /usr/sbin/netdata /app/usr/sbin/ && \
63 mv /usr/sbin/netdatacli /app/usr/sbin/ && \
64 mv /usr/sbin/nd-run /app/usr/sbin/ && \
65 mv /usr/sbin/systemd-cat-native /app/usr/sbin/ && \
66 mv packaging/docker/run.sh /app/usr/sbin/ && \
67 mv packaging/docker/health.sh /app/usr/sbin/ && \
68 mkdir -p /deps/etc && \
69 cp -rp /deps/etc /app/usr/local/etc && \
70 chmod -R o+rX /app && \
71 chmod +x /app/usr/sbin/run.sh && \
72 # Apply the permissions per https://learn.netdata.cloud/docs/collecting-metrics#file-permissions-and-ownership
73 # TODO: "5" is used for the "others" bit, not consistent with the documentation
74 chmod 0755 /app/usr/libexec/netdata/plugins.d/*.plugin && \
75 for name in cgroup-network \
76 local-listeners \
77 apps.plugin \
78 debugfs.plugin \
79 freeipmi.plugin \
80 go.d.plugin \
81 perf.plugin \
82 ndsudo \
83 slabinfo.plugin \
84 network-viewer.plugin \
85 otel-plugin \
86 otel-signal-viewer-plugin \
87 systemd-journal.plugin; do \
88 [ -f "/app/usr/libexec/netdata/plugins.d/$name" ] && chmod 4755 "/app/usr/libexec/netdata/plugins.d/$name"; \
89 done && \
90 # Group write permissions due to: https://github.com/netdata/netdata/pull/6543
91 find /app/var/lib/netdata /app/var/cache/netdata -type d -exec chmod 0770 {} \; && \
92 find /app/var/lib/netdata /app/var/cache/netdata -type f -exec chmod 0660 {} \; && \
93 chmod 0700 /app/var/lib/netdata/cloud.d
94
95 #####################################################################
96 # This image contains preinstalled dependencies
97 # hadolint ignore=DL3007
98 FROM netdata/base:v3 AS base
99
100 ARG BUILD_DATE
101 ARG BUILD_VERSION
102 LABEL org.opencontainers.image.authors="Netdatabot <bot@netdata.cloud>"
103 LABEL org.opencontainers.image.url="https://netdata.cloud"
104 LABEL org.opencontainers.image.documentation="https://learn.netdata.cloud"
105 LABEL org.opencontainers.image.source="https://github.com/netdata/netdata"
106 LABEL org.opencontainers.image.title="Netdata Agent"
107 LABEL org.opencontainers.image.description="Official Netdata Agent Docker Image"
108 LABEL org.opencontainers.image.vendor="Netdata Inc."
109 LABEL org.opencontainers.image.created=${BUILD_DATE}
110 LABEL org.opencontainers.image.version=${BUILD_VERSION}
111
112 ARG OFFICIAL_IMAGE=false
113 ENV NETDATA_OFFICIAL_IMAGE=$OFFICIAL_IMAGE
114
115 ONBUILD ENV NETDATA_OFFICIAL_IMAGE=false
116
117 ARG NETDATA_UID=201
118 ARG NETDATA_GID=201
119 ENV DOCKER_GRP=netdata
120 ENV DOCKER_USR=netdata
121 # If DISABLE_TELEMETRY is set, it will disable anonymous stats collection and reporting
122 #ENV DISABLE_TELEMETRY=1
123 ENV NETDATA_LISTENER_PORT=19999
124 EXPOSE $NETDATA_LISTENER_PORT
125
126 ENV NETDATA_EXTRA_DEB_PACKAGES=""
127
128 RUN mkdir -p /opt/src /var/log/netdata && \
129 ln -sf /dev/stdout /var/log/netdata/access.log && \
130 ln -sf /dev/stdout /var/log/netdata/aclk.log && \
131 ln -sf /dev/stdout /var/log/netdata/debug.log && \
132 ln -sf /dev/stderr /var/log/netdata/error.log && \
133 ln -sf /dev/stderr /var/log/netdata/daemon.log && \
134 ln -sf /dev/stdout /var/log/netdata/collector.log && \
135 ln -sf /dev/stdout /var/log/netdata/health.log && \
136 chown -R ${NETDATA_UID}:0 /var/log/netdata
137
138 # Using chmod/chown command with a "RUN" instruction to set the permission/ownership
139 # would bloat the image significantly, so we set the permission bits in the builder stage
140 # and then copy the files with the correct ownership.
141 # Own everything by root group due to https://github.com/netdata/netdata/pull/6543
142 COPY --from=builder --chown=0:0 --parents \
143 /app/./usr/sbin/ \
144 /app/./usr/share/netdata \
145 /app/./usr/libexec/netdata \
146 /app/./usr/local/etc \
147 /app/./etc/netdata \
148 /
149 COPY --from=builder --chown=${NETDATA_UID}:0 --parents \
150 /app/./usr/lib/netdata \
151 /app/./var/cache/netdata \
152 /app/./var/lib/netdata \
153 /
154
155 # Create netdata user
156 # hadolint ignore=DL3013
157 RUN addgroup --gid ${NETDATA_GID} --system "${DOCKER_GRP}" && \
158 adduser --system --no-create-home --shell /usr/sbin/nologin --uid ${NETDATA_UID} --home /etc/netdata --group "${DOCKER_USR}" && \
159 chown -R ${NETDATA_UID}:${NETDATA_GID} /var/lib/netdata/cloud.d && \
160 for name in cgroup-network \
161 local-listeners \
162 apps.plugin \
163 debugfs.plugin \
164 freeipmi.plugin \
165 go.d.plugin \
166 perf.plugin \
167 ndsudo \
168 slabinfo.plugin \
169 network-viewer.plugin \
170 otel-plugin \
171 otel-signal-viewer-plugin \
172 systemd-journal.plugin; do \
173 [ -f "/usr/libexec/netdata/plugins.d/$name" ] && test $(stat -c %a "/usr/libexec/netdata/plugins.d/$name") = "4755"; \
174 done && \
175 cp -va /etc/netdata /etc/netdata.stock
176
177 ENTRYPOINT ["/usr/sbin/run.sh"]
178
179 HEALTHCHECK --interval=60s --timeout=10s --retries=3 CMD /usr/sbin/health.sh