Skip to content

Commit

Permalink
[Heartbeat] Cleanup docker install / always add playwright deps (elas…
Browse files Browse the repository at this point in the history
…tic#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.
  • Loading branch information
andrewvc authored Aug 9, 2022
1 parent 940a56c commit dc5b1a2
Showing 1 changed file with 38 additions and 50 deletions.
88 changes: 38 additions & 50 deletions dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,6 @@ RUN for iter in {1..10}; do \
(exit $exit_code)
{{- end }}

{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
RUN apt-get update -y && \
for iter in {1..10}; do \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes \
libglib2.0-0\
libnss3\
libnspr4\
libatk1.0-0\
libatk-bridge2.0-0\
libcups2\
libdrm2\
libdbus-1-3\
libxcb1\
libxkbcommon0\
libx11-6\
libxcomposite1\
libxdamage1\
libxext6\
libxfixes3\
libxrandr2\
libgbm1\
libpango-1.0-0\
libcairo2\
libasound2\
libatspi2.0-0\
libxshmfence1 \
fonts-noto-core\
fonts-noto-cjk &&\
apt-get clean all && \
exit_code=0 && break || exit_code=$? && echo "apt-get error: retry $iter in 10s" && sleep 10; \
done; \
(exit $exit_code)
ENV NODE_PATH={{ $beatHome }}/.node
RUN echo \
$NODE_PATH \
{{ $beatHome }}/.config \
{{ $beatHome }}/.synthetics \
{{ $beatHome }}/.npm \
{{ $beatHome }}/.cache \
| xargs -IDIR sh -c 'mkdir -p DIR && chmod 0770 DIR'
{{- end }}

LABEL \
org.label-schema.build-date="{{ date }}" \
org.label-schema.schema-version="1.0" \
Expand Down Expand Up @@ -172,9 +130,7 @@ RUN mkdir /app
{{- else }}
RUN groupadd --gid 1000 {{ .BeatName }}
RUN useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user }}
{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
RUN chown {{ .user }} $NODE_PATH
{{- end }}

{{- if contains .image_name "-cloud" }}
# Generate folder for a stub command that will be overwritten at runtime
RUN mkdir /app
Expand All @@ -193,12 +149,19 @@ RUN mkdir -p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_ins
# heartbeat requires cap_net_raw,cap_setuid to run ICMP checks and change npm user
setcap cap_net_raw,cap_setuid+p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}/heartbeat-*/heartbeat

USER {{ .user }}

{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }}
USER root
ENV NODE_PATH={{ $beatHome }}/.node
RUN echo \
$NODE_PATH \
{{ $beatHome }}/.config \
{{ $beatHome }}/.synthetics \
{{ $beatHome }}/.npm \
{{ $beatHome }}/.cache \
| xargs -IDIR sh -c 'mkdir -p DIR && chmod 0770 DIR'

# Setup synthetics env vars
ENV ELASTIC_SYNTHETICS_CAPABLE=true
ENV SUITES_DIR={{ $beatHome }}/suites
ENV NODE_VERSION=16.15.0
ENV PATH="$NODE_PATH/node/bin:$PATH"
# Install the latest version of @elastic/synthetics forcefully ignoring the previously
Expand All @@ -207,6 +170,9 @@ ENV PATH="$NODE_PATH/node/bin:$PATH"
RUN cd {{$beatHome}}/.node \
&& NODE_DOWNLOAD_URL="" \
&& case "$(arch)" in \
arm64) \
NODE_DOWNLOAD_URL=https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz \
;; \
x86_64) \
NODE_DOWNLOAD_URL=https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz \
;; \
Expand All @@ -219,9 +185,31 @@ RUN cd {{$beatHome}}/.node \
esac \
&& mkdir -p node \
&& curl ${NODE_DOWNLOAD_URL} | tar -xJ --strip 1 -C node \
&& chmod ug+rwX -R $NODE_PATH \
&& npm i -g -f @elastic/synthetics && chmod ug+rwX -R $NODE_PATH
&& chmod ug+rwX -R $NODE_PATH

# Install synthetics as a regular user, installing npm deps as root odesn't work
RUN chown -R {{ .user }} $NODE_PATH
USER {{ .user }}
# If this fails dump the NPM logs
RUN npm i -g --loglevel verbose -f @elastic/synthetics || sh -c 'tail -n +1 /root/.npm/_logs/* && exit 1'
RUN chmod ug+rwX -R $NODE_PATH
USER root

# Install the deps as needed by the exact version of playwright elastic synthetics uses
# We don't use npx playwright install-deps because that could pull a newer version
# Install additional fonts as well
RUN for iter in {1..10}; do \
apt-get update -y && \
$NODE_PATH/node/lib/node_modules/@elastic/synthetics/node_modules/.bin/playwright install-deps chromium && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes \
fonts-noto \
fonts-noto-cjk && \
exit_code=0 && break || exit_code=$? && echo "apt-get error: retry $iter in 10s" && sleep 10; \
done; \
(exit $exit_code)

{{- end }}
USER {{ .user }}


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

0 comments on commit dc5b1a2

Please sign in to comment.