From 7a0d9bc5566e7803397fe1dea20d7f3da511645f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 19 Oct 2021 12:02:44 +0200 Subject: [PATCH] chore: remove Variants from PacakgeSpec struct As we prefer using the declarative way over the programmatic way, we do not need the variable. Instead, we'll use the YAML file for declaring the new variants --- dev-tools/mage/dockerbuilder.go | 41 ++++++++----------- dev-tools/mage/pkgtypes.go | 1 - .../docker/Dockerfile.elastic-agent.tmpl | 9 ++-- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/dev-tools/mage/dockerbuilder.go b/dev-tools/mage/dockerbuilder.go index 7d1a1376ad6c..b9c48c2c35f5 100644 --- a/dev-tools/mage/dockerbuilder.go +++ b/dev-tools/mage/dockerbuilder.go @@ -66,29 +66,25 @@ func (b *dockerBuilder) Build() error { return err } - // We always have at least one default variant - variants := append([]string{""}, b.PackageSpec.Variants...) - for _, variant := range variants { - if err := b.prepareBuild(variant); err != nil { - return errors.Wrap(err, "failed to prepare build") - } + if err := b.prepareBuild(); err != nil { + return errors.Wrap(err, "failed to prepare build") + } - tag, err := b.dockerBuild() - tries := 3 - for err != nil && tries != 0 { - fmt.Println(">> Building docker images again (after 10 s)") - // This sleep is to avoid hitting the docker build issues when resources are not available. - time.Sleep(time.Second * 10) - tag, err = b.dockerBuild() - tries -= 1 - } - if err != nil { - return errors.Wrap(err, "failed to build docker") - } + tag, err := b.dockerBuild() + tries := 3 + for err != nil && tries != 0 { + fmt.Println(">> Building docker images again (after 10 s)") + // This sleep is to avoid hitting the docker build issues when resources are not available. + time.Sleep(time.Second * 10) + tag, err = b.dockerBuild() + tries -= 1 + } + if err != nil { + return errors.Wrap(err, "failed to build docker") + } - if err := b.dockerSave(tag); err != nil { - return errors.Wrap(err, "failed to save docker as artifact") - } + if err := b.dockerSave(tag); err != nil { + return errors.Wrap(err, "failed to save docker as artifact") } return nil @@ -124,7 +120,7 @@ func (b *dockerBuilder) copyFiles() error { return nil } -func (b *dockerBuilder) prepareBuild(variant string) error { +func (b *dockerBuilder) prepareBuild() error { elasticBeatsDir, err := ElasticBeatsDir() if err != nil { return err @@ -134,7 +130,6 @@ func (b *dockerBuilder) prepareBuild(variant string) error { data := map[string]interface{}{ "ExposePorts": b.exposePorts(), "ModulesDirs": b.modulesDirs(), - "Variant": variant, } err = filepath.Walk(templatesDir, func(path string, info os.FileInfo, _ error) error { diff --git a/dev-tools/mage/pkgtypes.go b/dev-tools/mage/pkgtypes.go index 9a8ebc6d2ad3..c2c454c873d1 100644 --- a/dev-tools/mage/pkgtypes.go +++ b/dev-tools/mage/pkgtypes.go @@ -90,7 +90,6 @@ type PackageSpec struct { Files map[string]PackageFile `yaml:"files"` OutputFile string `yaml:"output_file,omitempty"` // Optional ExtraVars map[string]string `yaml:"extra_vars,omitempty"` // Optional - Variants []string `yaml:"variants"` // Optional evalContext map[string]interface{} packageDir string diff --git a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl index 0044852b1497..614062c3f024 100644 --- a/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl +++ b/dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl @@ -37,9 +37,6 @@ RUN readlink -f {{ $beatBinary }} | xargs setcap {{ .linux_capabilities }} FROM {{ .from }} -# Contains the elastic agent image variant, an empty string for the standard variant -# or "complete" for the bigger one. -ENV ELASTIC_AGENT_IMAGE_VARIANT={{.Variant}} ENV BEAT_SETUID_AS={{ .user }} {{- if contains .from "ubi-minimal" }} @@ -58,7 +55,7 @@ RUN case $(arch) in aarch64) YUM_FLAGS="-x bind-license";; esac; \ (exit $exit_code) {{- end }} -{{- if (and (eq .Variant "complete") (not (contains .from "ubi-minimal"))) }} +{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }} RUN for iter in {1..10}; do \ yum -y install atk cups gtk gdk xrandr pango libXcomposite libXcursor libXdamage \ libXext libXi libXtst cups-libs libXScrnSaver libXrandr GConf2 \ @@ -156,7 +153,7 @@ RUN mkdir /app {{- 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"))) }} +{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }} RUN chown {{ .user }} $NODE_PATH {{- end }} {{- if contains .image_name "-cloud" }} @@ -167,7 +164,7 @@ RUN chown {{ .user }} /app {{- end }} USER {{ .user }} -{{- if (and (eq .Variant "complete") (not (contains .from "ubi-minimal"))) }} +{{- if (and (contains .image_name "-complete") (not (contains .from "ubi-minimal"))) }} # Setup synthetics env vars ENV ELASTIC_SYNTHETICS_CAPABLE=true ENV SUITES_DIR={{ $beatHome }}/suites