From 472a6605603656b93eb50f9e77c49b0a7f8e8165 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 27 Sep 2021 17:44:06 +0100 Subject: [PATCH 01/18] Support cloud variant --- dev-tools/packaging/packages.yml | 10 ++++++---- .../templates/docker/Dockerfile.elastic-agent.tmpl | 11 ++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index e3f45990424..869a6dc4dcf 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -1001,8 +1001,9 @@ specs: <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large - # packages too big to fit in the main image - variants: ["complete"] + # packages too big to fit in the main image. In addition, the 'cloud' + # variant for the specific cloud requirements. + variants: ["complete", "cloud"] files: '{{.BeatName}}{{.BinaryExt}}': source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} @@ -1027,8 +1028,9 @@ specs: <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large - # packages too big to fit in the main image - variants: ["complete"] + # packages too big to fit in the main image. In addition, the 'cloud' + # variant for the specific cloud requirements. + variants: ["complete", "cloud"] files: '{{.BeatName}}{{.BinaryExt}}': source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 8f38ae5d68d..be748b75da0 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -22,6 +22,10 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s {{- end }} {{- range $i, $modulesd := .ModulesDirs }} chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ +{{- end }} +{{- if (and (eq .Variant "cloud") (not (contains .from "ubi-minimal"))) }} + tar -xvf metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" --directory && \ + tar -xvf filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" --directory && \ {{- end }} true @@ -41,7 +45,7 @@ RUN case $(arch) in aarch64) YUM_FLAGS="-x bind-license";; esac; \ yum install -y epel-release && \ yum update -y $YUM_FLAGS && \ yum install -y jq && \ - + yum clean all && \ exit_code=0 && break || exit_code=$? && echo "yum error: retry $iter in 10s" && sleep 10; \ done; \ @@ -134,6 +138,11 @@ RUN mkdir /licenses COPY --from=home {{ $beatHome }}/LICENSE.txt /licenses COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses +{{- if (and (eq .Variant "cloud") (not (contains .from "ubi-minimal"))) }} +COPY --from=home /opt/filebeat /opt/filebeat +COPY --from=home /opt/metricbeat /opt/metricbeat +{{- end }} + {{- if ne .user "root" }} RUN groupadd --gid 1000 {{ .BeatName }} RUN useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user }} From a0dec422c3e847f97ce1faf9a32742bd9963220c Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 27 Sep 2021 17:44:21 +0100 Subject: [PATCH 02/18] [ci] build cloud variant --- .ci/packaging.groovy | 4 +++- Jenkinsfile | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.ci/packaging.groovy b/.ci/packaging.groovy index 04301526e4d..ebae3598d6a 100644 --- a/.ci/packaging.groovy +++ b/.ci/packaging.groovy @@ -335,10 +335,12 @@ def tagAndPush(Map args = [:]) { } // supported image flavours def variants = ["", "-oss", "-ubi8"] - // + if(beatName == 'elastic-agent'){ variants.add("-complete") + variants.add("-cloud") } + variants.each { variant -> tags.each { tag -> // TODO: diff --git a/Jenkinsfile b/Jenkinsfile index 2321ef2c338..be5c4515ab2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -459,9 +459,9 @@ def tagAndPush(Map args = [:]) { // supported image flavours def variants = ["", "-oss", "-ubi8"] - // only add complete variant for the elastic-agent if(beatName == 'elastic-agent'){ variants.add("-complete") + variants.add("-cloud") } variants.each { variant -> From f902af516e9c72dee84e797324f24a0dc89e9809 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 27 Sep 2021 17:48:13 +0100 Subject: [PATCH 03/18] Add folder --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index be748b75da0..fc57f0f7b46 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -24,8 +24,8 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ {{- end }} {{- if (and (eq .Variant "cloud") (not (contains .from "ubi-minimal"))) }} - tar -xvf metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" --directory && \ - tar -xvf filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" --directory && \ + tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" --directory && \ + tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" --directory && \ {{- end }} true From 14c5499c4d85a4e05cab3143afe4569b79ce0f71 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 27 Sep 2021 18:30:10 +0100 Subject: [PATCH 04/18] Apply suggestions from code review --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index fc57f0f7b46..422fb180b73 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -24,8 +24,8 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ {{- end }} {{- if (and (eq .Variant "cloud") (not (contains .from "ubi-minimal"))) }} - tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" --directory && \ - tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" --directory && \ + tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" && \ + tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" && \ {{- end }} true From 093a855b8dbc275c6b45436b7c8fd28553c6267a Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 10:51:27 +0100 Subject: [PATCH 05/18] Usean extra spec similar to the ubi8 variant https://github.com/elastic/beats/pull/20576 --- dev-tools/packaging/packages.yml | 22 ++++++++++++++----- .../docker/Dockerfile.elastic-agent.tmpl | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index 869a6dc4dcf..41b10744db6 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -449,6 +449,16 @@ shared: from: 'arm64v8/centos:7' buildFrom: 'arm64v8/centos:7' + - &cloud_agent_docker_spec + <<: *agent_docker_spec + extra_vars: + image_name: '{{.BeatName}}-cloud' + + - &cloud_agent_docker_arm_spec + <<: *agent_docker_arm_spec + extra_vars: + image_name: '{{.BeatName}}-cloud' + # Deb/RPM spec for community beats. - &deb_rpm_spec <<: *common @@ -998,12 +1008,12 @@ specs: types: [docker] spec: <<: *agent_docker_spec + <<: *cloud_agent_docker_spec <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large - # packages too big to fit in the main image. In addition, the 'cloud' - # variant for the specific cloud requirements. - variants: ["complete", "cloud"] + # packages too big to fit in the main image. + variants: ["complete"] files: '{{.BeatName}}{{.BinaryExt}}': source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} @@ -1025,12 +1035,12 @@ specs: types: [docker] spec: <<: *agent_docker_arm_spec + <<: *cloud_agent_docker_arm_spec <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large - # packages too big to fit in the main image. In addition, the 'cloud' - # variant for the specific cloud requirements. - variants: ["complete", "cloud"] + # packages too big to fit in the main image. + variants: ["complete"] files: '{{.BeatName}}{{.BinaryExt}}': source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index fc57f0f7b46..12a86495339 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -23,7 +23,7 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s {{- range $i, $modulesd := .ModulesDirs }} chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ {{- end }} -{{- if (and (eq .Variant "cloud") (not (contains .from "ubi-minimal"))) }} +{{- if contains .from "-cloud" }} tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" --directory && \ tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" --directory && \ {{- end }} @@ -138,7 +138,7 @@ RUN mkdir /licenses COPY --from=home {{ $beatHome }}/LICENSE.txt /licenses COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses -{{- if (and (eq .Variant "cloud") (not (contains .from "ubi-minimal"))) }} +{{- if contains .from "-cloud" }} COPY --from=home /opt/filebeat /opt/filebeat COPY --from=home /opt/metricbeat /opt/metricbeat {{- end }} From 3c6520dc30d933d9444c90a8e697fbec8dd53cfc Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 11:01:23 +0100 Subject: [PATCH 06/18] Revmove empty line --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 4688773d13e..b94d78b83b0 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -45,7 +45,6 @@ RUN case $(arch) in aarch64) YUM_FLAGS="-x bind-license";; esac; \ yum install -y epel-release && \ yum update -y $YUM_FLAGS && \ yum install -y jq && \ - yum clean all && \ exit_code=0 && break || exit_code=$? && echo "yum error: retry $iter in 10s" && sleep 10; \ done; \ From 0fe8ad0f3a5f770f139aaa6764e215dd6a801509 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 15:25:46 +0100 Subject: [PATCH 07/18] Use the right variable --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index b94d78b83b0..fc652e46c67 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -23,7 +23,7 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s {{- range $i, $modulesd := .ModulesDirs }} chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ {{- end }} -{{- if contains .from "-cloud" }} +{{- if contains .image_name "-cloud" }} tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" && \ tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" && \ {{- end }} @@ -137,7 +137,7 @@ RUN mkdir /licenses COPY --from=home {{ $beatHome }}/LICENSE.txt /licenses COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses -{{- if contains .from "-cloud" }} +{{- if contains .image_name "-cloud" }} COPY --from=home /opt/filebeat /opt/filebeat COPY --from=home /opt/metricbeat /opt/metricbeat {{- end }} From f160c7e36f7d2c122224a1f53b1426f612e4be5f Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 15:27:44 +0100 Subject: [PATCH 08/18] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel de la Peña --- dev-tools/packaging/packages.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index 41b10744db6..4225d210adf 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -449,15 +449,11 @@ shared: from: 'arm64v8/centos:7' buildFrom: 'arm64v8/centos:7' - - &cloud_agent_docker_spec + - &agent_docker_cloud_spec <<: *agent_docker_spec extra_vars: image_name: '{{.BeatName}}-cloud' - - &cloud_agent_docker_arm_spec - <<: *agent_docker_arm_spec - extra_vars: - image_name: '{{.BeatName}}-cloud' # Deb/RPM spec for community beats. - &deb_rpm_spec @@ -1008,7 +1004,7 @@ specs: types: [docker] spec: <<: *agent_docker_spec - <<: *cloud_agent_docker_spec + <<: *agent_docker_cloud_spec <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large @@ -1035,7 +1031,7 @@ specs: types: [docker] spec: <<: *agent_docker_arm_spec - <<: *cloud_agent_docker_arm_spec + <<: *agent_docker_cloud_spec <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large From 6b8e09d83a34660bc3f5451c421dbc511ea3f19a Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 15:28:03 +0100 Subject: [PATCH 09/18] Apply suggestions from code review --- dev-tools/packaging/packages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index 4225d210adf..c57ea913e48 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -454,7 +454,6 @@ shared: extra_vars: image_name: '{{.BeatName}}-cloud' - # Deb/RPM spec for community beats. - &deb_rpm_spec <<: *common From f2bab3386fc602f6a5e8f0390a2a4c17f5a1a230 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 15:28:30 +0100 Subject: [PATCH 10/18] Apply suggestions from code review --- dev-tools/packaging/packages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index c57ea913e48..6236e65c533 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -1007,7 +1007,7 @@ specs: <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large - # packages too big to fit in the main image. + # packages too big to fit in the main image variants: ["complete"] files: '{{.BeatName}}{{.BinaryExt}}': @@ -1034,7 +1034,7 @@ specs: <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large - # packages too big to fit in the main image. + # packages too big to fit in the main image variants: ["complete"] files: '{{.BeatName}}{{.BinaryExt}}': From 304ed83e63b111b37510b6e434977be68633cd98 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 15:45:13 +0100 Subject: [PATCH 11/18] See https://github.com/elastic/elasticsearch/pull/74980/files\#diff-6f6cf07546466eb24c7e953bb1cf8979fa514329b348a493726eceaf1b470820R274-R276 --- .../templates/docker/Dockerfile.elastic-agent.tmpl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index fc652e46c67..11ba05eec57 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -24,8 +24,8 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ {{- end }} {{- if contains .image_name "-cloud" }} - tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*metricbeat" && \ - tar -xvf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz --strip-components 1 --directory /opt --wildcards "*filebeat" && \ + tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz -C /opt/filebeat --strip-components=1 && \ + tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz -C /opt/metricbeat --strip-components=1 && \ {{- end }} true @@ -138,8 +138,7 @@ COPY --from=home {{ $beatHome }}/LICENSE.txt /licenses COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses {{- if contains .image_name "-cloud" }} -COPY --from=home /opt/filebeat /opt/filebeat -COPY --from=home /opt/metricbeat /opt/metricbeat +COPY --from=home /opt /opt {{- end }} {{- if ne .user "root" }} From 636c46a2da06a43d42f111df1a59574fb0ad2893 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 15:51:46 +0100 Subject: [PATCH 12/18] Add entrypoint for cloud --- .../templates/docker/Dockerfile.elastic-agent.tmpl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 11ba05eec57..786e37c9b6d 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -179,7 +179,6 @@ RUN cd {{$beatHome}}/.node \ {{- end }} - {{- range $i, $port := .ExposePorts }} EXPOSE {{ $port }} {{- end }} @@ -190,4 +189,10 @@ EXPOSE {{ $port }} ENV LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE=/ WORKDIR {{ $beatHome }} + +{{- if contains .image_name "-cloud" }} +ENTRYPOINT ["/bin/tini", "--"] +CMD ["/app/apm.sh"] +{{- else }} ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/docker-entrypoint"] +{{- end }} From 5c2c93e155727840a296081a2fd75cef8fa9a019 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 17:46:31 +0100 Subject: [PATCH 13/18] Create folder, grant permissions and use the tini location --- .../templates/docker/Dockerfile.elastic-agent.tmpl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 786e37c9b6d..4bc8107fda3 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -24,6 +24,7 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s chmod 0775 {{ $beatHome}}/{{ $modulesd }} && \ {{- end }} {{- if contains .image_name "-cloud" }} + mkdir -p /opt/filebeat /opt/metricbeat && \ tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz -C /opt/filebeat --strip-components=1 && \ tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz -C /opt/metricbeat --strip-components=1 && \ {{- end }} @@ -147,6 +148,11 @@ RUN useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user {{- if (and (eq .Variant "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 +RUN chown {{ .user }} /app +{{- end }} {{- end }} USER {{ .user }} @@ -191,8 +197,11 @@ ENV LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE=/ WORKDIR {{ $beatHome }} {{- if contains .image_name "-cloud" }} -ENTRYPOINT ["/bin/tini", "--"] +ENTRYPOINT ["/usr/bin/bin/tini", "--"] CMD ["/app/apm.sh"] +# Generate a stub command that will be overwritten at runtime +RUN echo -e '#!/bin/sh\nexec /usr/local/bin/docker-entrypoint' > /app/apm.sh && \ + chmod 0555 /app/apm.sh {{- else }} ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/docker-entrypoint"] {{- end }} From 203c429442e6fa4a039179a5d7f5b058d49ff5fd Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 18:06:16 +0100 Subject: [PATCH 14/18] Fix entrypoint --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 4bc8107fda3..f673e248d44 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -197,7 +197,7 @@ ENV LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE=/ WORKDIR {{ $beatHome }} {{- if contains .image_name "-cloud" }} -ENTRYPOINT ["/usr/bin/bin/tini", "--"] +ENTRYPOINT ["/usr/bin/tini", "--"] CMD ["/app/apm.sh"] # Generate a stub command that will be overwritten at runtime RUN echo -e '#!/bin/sh\nexec /usr/local/bin/docker-entrypoint' > /app/apm.sh && \ From 98ebbc8915b61a2a59cb2810863d89f5d61a84bf Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 18:55:58 +0100 Subject: [PATCH 15/18] Support spec for cloud only --- dev-tools/packaging/packages.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/packages.yml b/dev-tools/packaging/packages.yml index 6236e65c533..42bb9eba364 100644 --- a/dev-tools/packaging/packages.yml +++ b/dev-tools/packaging/packages.yml @@ -433,6 +433,7 @@ shared: docker_entrypoint: 'docker-entrypoint.elastic-agent.tmpl' user: '{{ .BeatName }}' linux_capabilities: '' + image_name: '' files: 'elastic-agent.yml': source: 'elastic-agent.docker.yml' @@ -1003,7 +1004,6 @@ specs: types: [docker] spec: <<: *agent_docker_spec - <<: *agent_docker_cloud_spec <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large @@ -1013,6 +1013,19 @@ specs: '{{.BeatName}}{{.BinaryExt}}': source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} + # Cloud specific docker image + - os: linux + arch: amd64 + types: [docker] + spec: + <<: *agent_docker_spec + <<: *agent_docker_cloud_spec + <<: *elastic_docker_spec + <<: *elastic_license_for_binaries + files: + '{{.BeatName}}{{.BinaryExt}}': + source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} + - os: linux arch: amd64 types: [docker] @@ -1030,7 +1043,6 @@ specs: types: [docker] spec: <<: *agent_docker_arm_spec - <<: *agent_docker_cloud_spec <<: *elastic_docker_spec <<: *elastic_license_for_binaries # This image gets a 'complete' variant for synthetics and other large @@ -1040,6 +1052,19 @@ specs: '{{.BeatName}}{{.BinaryExt}}': source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} + # Cloud specific docker image + - os: linux + arch: arm64 + types: [docker] + spec: + <<: *agent_docker_arm_spec + <<: *agent_docker_cloud_spec + <<: *elastic_docker_spec + <<: *elastic_license_for_binaries + files: + '{{.BeatName}}{{.BinaryExt}}': + source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} + - os: linux arch: arm64 types: [docker] From de602d32d93adfc8c6b95f7349e27d54755f21e6 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 18:57:23 +0100 Subject: [PATCH 16/18] Support a root user --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index f673e248d44..2f0ddc72302 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -153,6 +153,11 @@ RUN chown {{ .user }} $NODE_PATH RUN mkdir /app RUN chown {{ .user }} /app {{- end }} +{{- else }} +{{- if contains .image_name "-cloud" }} +# Generate folder for a stub command that will be overwritten at runtime +RUN mkdir /app +{{- end }} {{- end }} USER {{ .user }} From 17375767ea539040fec3790fb3abe740ebb3881d Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 29 Sep 2021 18:57:53 +0100 Subject: [PATCH 17/18] Avoid negative condition --- .../templates/docker/Dockerfile.elastic-agent.tmpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 2f0ddc72302..29d31e13dad 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -142,7 +142,12 @@ COPY --from=home {{ $beatHome }}/NOTICE.txt /licenses COPY --from=home /opt /opt {{- end }} -{{- if ne .user "root" }} +{{- if eq .user "root" }} +{{- if contains .image_name "-cloud" }} +# Generate folder for a stub command that will be overwritten at runtime +RUN mkdir /app +{{- end }} +{{- else }} RUN groupadd --gid 1000 {{ .BeatName }} RUN useradd -M --uid 1000 --gid 1000 --groups 0 --home {{ $beatHome }} {{ .user }} {{- if (and (eq .Variant "complete") (not (contains .from "ubi-minimal"))) }} @@ -153,11 +158,6 @@ RUN chown {{ .user }} $NODE_PATH RUN mkdir /app RUN chown {{ .user }} /app {{- end }} -{{- else }} -{{- if contains .image_name "-cloud" }} -# Generate folder for a stub command that will be overwritten at runtime -RUN mkdir /app -{{- end }} {{- end }} USER {{ .user }} From 2d8119d99087df2724a56929635d55484821a73b Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 1 Oct 2021 09:02:16 +0100 Subject: [PATCH 18/18] Use the right location folder --- .../packaging/templates/docker/Dockerfile.elastic-agent.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 29d31e13dad..bbd31850ccb 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -25,8 +25,8 @@ RUN mkdir -p {{ $beatHome }}/data {{ $beatHome }}/data/elastic-agent-{{ commit_s {{- end }} {{- if contains .image_name "-cloud" }} mkdir -p /opt/filebeat /opt/metricbeat && \ - tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz -C /opt/filebeat --strip-components=1 && \ - tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz -C /opt/metricbeat --strip-components=1 && \ + tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/metricbeat-*.tar.gz -C /opt/metricbeat --strip-components=1 && \ + tar xf {{ $beatHome }}/data/elastic-agent-*/downloads/filebeat-*.tar.gz -C /opt/filebeat --strip-components=1 && \ {{- end }} true