Skip to content

Commit dc5b1a2

Browse files
authored
[Heartbeat] Cleanup docker install / always add playwright deps (elastic#764)
This is the agent counterpart to elastic/beats#32122 Refactors Dockerfile handling of synthetics deps to rely on playwright install-deps rather than us manually keeping up to date with those. This should fix issues with newer playwrights needing additional deps. This also cleans up the Dockerfile a good amount, and fixes indentation. Finally, this removes the unused Dockerfile.elastic-agent.tmpl file since agent is now its own repo. It also cleans up some other metadata that no longer does anything. No changelog is specified because no user facing changes are present.
1 parent 940a56c commit dc5b1a2

File tree

1 file changed

+38
-50
lines changed

1 file changed

+38
-50
lines changed

dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,48 +44,6 @@ RUN for iter in {1..10}; do \
4444
(exit $exit_code)
4545
{{- end }}
4646

47-
{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
48-
RUN apt-get update -y && \
49-
for iter in {1..10}; do \
50-
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes \
51-
libglib2.0-0\
52-
libnss3\
53-
libnspr4\
54-
libatk1.0-0\
55-
libatk-bridge2.0-0\
56-
libcups2\
57-
libdrm2\
58-
libdbus-1-3\
59-
libxcb1\
60-
libxkbcommon0\
61-
libx11-6\
62-
libxcomposite1\
63-
libxdamage1\
64-
libxext6\
65-
libxfixes3\
66-
libxrandr2\
67-
libgbm1\
68-
libpango-1.0-0\
69-
libcairo2\
70-
libasound2\
71-
libatspi2.0-0\
72-
libxshmfence1 \
73-
fonts-noto-core\
74-
fonts-noto-cjk &&\
75-
apt-get clean all && \
76-
exit_code=0 && break || exit_code=$? && echo "apt-get error: retry $iter in 10s" && sleep 10; \
77-
done; \
78-
(exit $exit_code)
79-
ENV NODE_PATH={{ $beatHome }}/.node
80-
RUN echo \
81-
$NODE_PATH \
82-
{{ $beatHome }}/.config \
83-
{{ $beatHome }}/.synthetics \
84-
{{ $beatHome }}/.npm \
85-
{{ $beatHome }}/.cache \
86-
| xargs -IDIR sh -c 'mkdir -p DIR && chmod 0770 DIR'
87-
{{- end }}
88-
8947
LABEL \
9048
org.label-schema.build-date="{{ date }}" \
9149
org.label-schema.schema-version="1.0" \
@@ -172,9 +130,7 @@ RUN mkdir /app
172130
{{- else }}
173131
RUN groupadd --gid 1000 {{ .BeatName }}
174132
RUN useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user }}
175-
{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
176-
RUN chown {{ .user }} $NODE_PATH
177-
{{- end }}
133+
178134
{{- if contains .image_name "-cloud" }}
179135
# Generate folder for a stub command that will be overwritten at runtime
180136
RUN mkdir /app
@@ -193,12 +149,19 @@ RUN mkdir -p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_ins
193149
# heartbeat requires cap_net_raw,cap_setuid to run ICMP checks and change npm user
194150
setcap cap_net_raw,cap_setuid+p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}/heartbeat-*/heartbeat
195151

196-
USER {{ .user }}
197-
198152
{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
153+
USER root
154+
ENV NODE_PATH={{ $beatHome }}/.node
155+
RUN echo \
156+
$NODE_PATH \
157+
{{ $beatHome }}/.config \
158+
{{ $beatHome }}/.synthetics \
159+
{{ $beatHome }}/.npm \
160+
{{ $beatHome }}/.cache \
161+
| xargs -IDIR sh -c 'mkdir -p DIR && chmod 0770 DIR'
162+
199163
# Setup synthetics env vars
200164
ENV ELASTIC_SYNTHETICS_CAPABLE=true
201-
ENV SUITES_DIR={{ $beatHome }}/suites
202165
ENV NODE_VERSION=16.15.0
203166
ENV PATH="$NODE_PATH/node/bin:$PATH"
204167
# Install the latest version of @elastic/synthetics forcefully ignoring the previously
@@ -207,6 +170,9 @@ ENV PATH="$NODE_PATH/node/bin:$PATH"
207170
RUN cd {{$beatHome}}/.node \
208171
&& NODE_DOWNLOAD_URL="" \
209172
&& case "$(arch)" in \
173+
arm64) \
174+
NODE_DOWNLOAD_URL=https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz \
175+
;; \
210176
x86_64) \
211177
NODE_DOWNLOAD_URL=https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz \
212178
;; \
@@ -219,9 +185,31 @@ RUN cd {{$beatHome}}/.node \
219185
esac \
220186
&& mkdir -p node \
221187
&& curl ${NODE_DOWNLOAD_URL} | tar -xJ --strip 1 -C node \
222-
&& chmod ug+rwX -R $NODE_PATH \
223-
&& npm i -g -f @elastic/synthetics && chmod ug+rwX -R $NODE_PATH
188+
&& chmod ug+rwX -R $NODE_PATH
189+
190+
# Install synthetics as a regular user, installing npm deps as root odesn't work
191+
RUN chown -R {{ .user }} $NODE_PATH
192+
USER {{ .user }}
193+
# If this fails dump the NPM logs
194+
RUN npm i -g --loglevel verbose -f @elastic/synthetics || sh -c 'tail -n +1 /root/.npm/_logs/* && exit 1'
195+
RUN chmod ug+rwX -R $NODE_PATH
196+
USER root
197+
198+
# Install the deps as needed by the exact version of playwright elastic synthetics uses
199+
# We don't use npx playwright install-deps because that could pull a newer version
200+
# Install additional fonts as well
201+
RUN for iter in {1..10}; do \
202+
apt-get update -y && \
203+
$NODE_PATH/node/lib/node_modules/@elastic/synthetics/node_modules/.bin/playwright install-deps chromium && \
204+
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes \
205+
fonts-noto \
206+
fonts-noto-cjk && \
207+
exit_code=0 && break || exit_code=$? && echo "apt-get error: retry $iter in 10s" && sleep 10; \
208+
done; \
209+
(exit $exit_code)
210+
224211
{{- end }}
212+
USER {{ .user }}
225213

226214

227215
{{- range $i, $port := .ExposePorts }}

0 commit comments

Comments
 (0)