Skip to content

Commit

Permalink
chore: remove Variants from PacakgeSpec struct
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdelapenya committed Oct 19, 2021
1 parent 8bb2079 commit 7a0d9bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
41 changes: 18 additions & 23 deletions dev-tools/mage/dockerbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion dev-tools/mage/pkgtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
Expand All @@ -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 \
Expand Down Expand Up @@ -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" }}
Expand All @@ -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
Expand Down

0 comments on commit 7a0d9bc

Please sign in to comment.