Skip to content

Commit ce2cd86

Browse files
committed
Add docker image name template and renamed fips cloud specs
1 parent 61fed75 commit ce2cd86

File tree

2 files changed

+81
-23
lines changed

2 files changed

+81
-23
lines changed

dev-tools/mage/pkgtypes.go

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"slices"
2424
"strconv"
2525
"strings"
26+
"text/template"
2627

2728
"github.com/magefile/mage/mg"
2829
"github.com/magefile/mage/sh"
@@ -88,27 +89,28 @@ type OSPackageArgs struct {
8889

8990
// PackageSpec specifies package metadata and the contents of the package.
9091
type PackageSpec struct {
91-
Name string `yaml:"name,omitempty"`
92-
ServiceName string `yaml:"service_name,omitempty"`
93-
OS string `yaml:"os,omitempty"`
94-
Arch string `yaml:"arch,omitempty"`
95-
Vendor string `yaml:"vendor,omitempty"`
96-
Snapshot bool `yaml:"snapshot"`
97-
FIPS bool `yaml:"fips"`
98-
Version string `yaml:"version,omitempty"`
99-
License string `yaml:"license,omitempty"`
100-
URL string `yaml:"url,omitempty"`
101-
Description string `yaml:"description,omitempty"`
102-
DockerVariant DockerVariant `yaml:"docker_variant,omitempty"`
103-
PreInstallScript string `yaml:"pre_install_script,omitempty"`
104-
PostInstallScript string `yaml:"post_install_script,omitempty"`
105-
PostRmScript string `yaml:"post_rm_script,omitempty"`
106-
Files map[string]PackageFile `yaml:"files"`
107-
Qualifier string `yaml:"qualifier,omitempty"` // Optional
108-
OutputFile string `yaml:"output_file,omitempty"` // Optional
109-
ExtraVars map[string]string `yaml:"extra_vars,omitempty"` // Optional
110-
ExtraTags []string `yaml:"extra_tags,omitempty"` // Optional
111-
Components []packaging.BinarySpec `yaml:"components"` // Optional: Components required for this package
92+
Name string `yaml:"name,omitempty"`
93+
ServiceName string `yaml:"service_name,omitempty"`
94+
OS string `yaml:"os,omitempty"`
95+
Arch string `yaml:"arch,omitempty"`
96+
Vendor string `yaml:"vendor,omitempty"`
97+
Snapshot bool `yaml:"snapshot"`
98+
FIPS bool `yaml:"fips"`
99+
Version string `yaml:"version,omitempty"`
100+
License string `yaml:"license,omitempty"`
101+
URL string `yaml:"url,omitempty"`
102+
Description string `yaml:"description,omitempty"`
103+
DockerVariant DockerVariant `yaml:"docker_variant,omitempty"`
104+
DockerImageNameTemplate string `yaml:"docker_image_name_template,omitempty"` // Optional: template of the docker image name
105+
PreInstallScript string `yaml:"pre_install_script,omitempty"`
106+
PostInstallScript string `yaml:"post_install_script,omitempty"`
107+
PostRmScript string `yaml:"post_rm_script,omitempty"`
108+
Files map[string]PackageFile `yaml:"files"`
109+
Qualifier string `yaml:"qualifier,omitempty"` // Optional
110+
OutputFile string `yaml:"output_file,omitempty"` // Optional
111+
ExtraVars map[string]string `yaml:"extra_vars,omitempty"` // Optional
112+
ExtraTags []string `yaml:"extra_tags,omitempty"` // Optional
113+
Components []packaging.BinarySpec `yaml:"components"` // Optional: Components required for this package
112114

113115
evalContext map[string]interface{}
114116
packageDir string
@@ -488,6 +490,30 @@ func (s PackageSpec) Evaluate(args ...map[string]interface{}) PackageSpec {
488490

489491
// ImageName computes the image name from the spec.
490492
func (s PackageSpec) ImageName() string {
493+
if s.DockerImageNameTemplate != "" {
494+
imageNameTmpl, err := template.New("dockerImageTemplate").Parse(s.DockerImageNameTemplate)
495+
if err != nil {
496+
panic(fmt.Errorf("parsing docker image name template for %s variant %s: %w", s.Name, s.DockerVariant, err))
497+
}
498+
499+
data := s.toMap()
500+
for k, v := range varMap() {
501+
data[k] = v
502+
}
503+
504+
buf := new(strings.Builder)
505+
err = imageNameTmpl.Execute(buf, data)
506+
if err != nil {
507+
panic(fmt.Errorf("rendering docker image name template for %s variant %s: %w", s.Name, s.DockerVariant, err))
508+
}
509+
510+
imageName := buf.String()
511+
if mg.Verbose() {
512+
log.Printf("rendered image name for %s variant %s: %s", s.Name, s.DockerVariant, imageName)
513+
}
514+
return imageName
515+
}
516+
491517
if s.DockerVariant == Basic {
492518
return s.Name
493519
}

dev-tools/packaging/packages.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ shared:
503503

504504
- &agent_docker_spec
505505
<<: *agent_binary_spec
506+
# Default docker image name is <spec name>-<docker variant>
506507
extra_vars:
507508
dockerfile: 'Dockerfile.elastic-agent.tmpl'
508509
docker_entrypoint: 'docker-entrypoint.elastic-agent.tmpl'
@@ -1551,7 +1552,7 @@ specs:
15511552
source: data/{{.BeatName}}-{{ commit_short }}/{{.BeatName}}{{.BinaryExt}}
15521553
symlink: true
15531554
mode: 0755
1554-
1555+
# remove this spec once the elastic-agent-cloud-fips below is correctly uploaded as a DRA
15551556
- os: linux
15561557
arch: amd64
15571558
types: [ docker ]
@@ -1561,10 +1562,11 @@ specs:
15611562
<<: *agent_docker_fips_spec
15621563
<<: *docker_elastic_spec
15631564
<<: *elastic_license_for_binaries
1565+
name: "elastic-agent-fips-cloud"
15641566
files:
15651567
'{{.BeatName}}{{.BinaryExt}}':
15661568
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
1567-
1569+
# remove this spec once the elastic-agent-cloud-fips below is correctly uploaded as a DRA
15681570
- os: linux
15691571
arch: arm64
15701572
types: [ docker ]
@@ -1574,6 +1576,34 @@ specs:
15741576
<<: *agent_docker_fips_spec
15751577
<<: *docker_elastic_spec
15761578
<<: *elastic_license_for_binaries
1579+
name: "elastic-agent-fips-cloud"
1580+
files:
1581+
'{{.BeatName}}{{.BinaryExt}}':
1582+
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
1583+
1584+
- os: linux
1585+
arch: amd64
1586+
types: [ docker ]
1587+
spec:
1588+
<<: *docker_fips_spec
1589+
<<: *agent_docker_fips_spec
1590+
# The cloud image is always based on Wolfi
1591+
<<: *docker_builder_spec
1592+
<<: *agent_docker_cloud_fips_spec
1593+
<<: *elastic_license_for_binaries
1594+
files:
1595+
'{{.BeatName}}{{.BinaryExt}}':
1596+
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
1597+
- os: linux
1598+
arch: arm64
1599+
types: [ docker ]
1600+
spec:
1601+
<<: *docker_fips_spec
1602+
<<: *agent_docker_fips_spec
1603+
# The cloud image is always based on Wolfi
1604+
<<: *docker_builder_arm_spec
1605+
<<: *agent_docker_cloud_fips_spec
1606+
<<: *elastic_license_for_binaries
15771607
files:
15781608
'{{.BeatName}}{{.BinaryExt}}':
15791609
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
@@ -1588,6 +1618,7 @@ specs:
15881618
<<: *docker_builder_spec
15891619
<<: *agent_docker_cloud_fips_spec
15901620
<<: *elastic_license_for_binaries
1621+
docker_image_name_template: "{{.BeatName}}-cloud-fips"
15911622
files:
15921623
'{{.BeatName}}{{.BinaryExt}}':
15931624
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
@@ -1601,6 +1632,7 @@ specs:
16011632
<<: *docker_builder_arm_spec
16021633
<<: *agent_docker_cloud_fips_spec
16031634
<<: *elastic_license_for_binaries
1635+
docker_image_name_template: "{{.BeatName}}-cloud-fips"
16041636
files:
16051637
'{{.BeatName}}{{.BinaryExt}}':
16061638
source: ./build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}

0 commit comments

Comments
 (0)