@@ -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.
9091type 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.
490492func (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 }
@@ -791,7 +817,7 @@ func runFPM(spec PackageSpec, packageType PackageType) error {
791817 args = append (args , "--vendor" , spec .Vendor )
792818 }
793819 if spec .License != "" {
794- args = append (args , "--license" , strings .Replace (spec .License , " " , "-" , - 1 ))
820+ args = append (args , "--license" , strings .ReplaceAll (spec .License , " " , "-" ))
795821 }
796822 if spec .Description != "" {
797823 args = append (args , "--description" , spec .Description )
0 commit comments