From 1bc974aac58e564f6889f097886a4bf84dd62624 Mon Sep 17 00:00:00 2001 From: emilioalvap Date: Mon, 14 Mar 2022 15:33:44 +0100 Subject: [PATCH 1/2] unpack beats at build time on docker --- dev-tools/packaging/packages.yml | 1 + .../templates/docker/Dockerfile.elastic-agent.tmpl | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index 75696d83b38..bd543a7b9d0 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -482,6 +482,7 @@ shared: user: '{{ .BeatName }}' linux_capabilities: '' image_name: '' + beats_install_path: "install" files: 'elastic-agent.yml': source: 'elastic-agent.docker.yml' diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index f4e31cd3b01..c0843bb35d9 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -32,7 +32,7 @@ FROM {{ .from }} ENV BEAT_SETUID_AS={{ .user }} {{- if contains .from "ubi-minimal" }} -RUN for iter in {1..10}; do microdnf update -y && microdnf install -y findutils shadow-utils && microdnf clean all && exit_code=0 && break || exit_code=$? && echo "microdnf error: retry $iter in 10s" && sleep 10; done; (exit $exit_code) +RUN for iter in {1..10}; do microdnf update -y && microdnf install -y tar gzip findutils shadow-utils && microdnf clean all && exit_code=0 && break || exit_code=$? && echo "microdnf error: retry $iter in 10s" && sleep 10; done; (exit $exit_code) {{- else }} RUN for iter in {1..10}; do \ @@ -181,6 +181,16 @@ RUN mkdir /app RUN chown {{ .user }} /app {{- end }} {{- end }} + +RUN mkdir -p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }} && \ + for beatPath in {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/downloads/*.tar.gz; do \ + tar xf $beatPath -C {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}; \ + done && \ + chown -R {{ .user }}:{{ .user }} {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }} && \ + chown -R root:root {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}/*/*.yml && \ + chmod 0644 {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}/*/*.yml && \ + 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"))) }} From dc22ccd3c25612502a67b54cd9bf8fd6fb86bdb6 Mon Sep 17 00:00:00 2001 From: emilioalvap Date: Mon, 14 Mar 2022 17:04:59 +0100 Subject: [PATCH 2/2] Add comment on heartbeat caps --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index c0843bb35d9..0ed6ea5f0b7 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -182,6 +182,7 @@ RUN chown {{ .user }} /app {{- end }} {{- end }} +# Unpack beats to default install directory RUN mkdir -p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }} && \ for beatPath in {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/downloads/*.tar.gz; do \ tar xf $beatPath -C {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}; \ @@ -189,6 +190,7 @@ RUN mkdir -p {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_ins chown -R {{ .user }}:{{ .user }} {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }} && \ chown -R root:root {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}/*/*.yml && \ chmod 0644 {{ $beatHome }}/data/{{.BeatName}}-{{ commit_short }}/{{ .beats_install_path }}/*/*.yml && \ + # 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 }}