@@ -22,6 +22,7 @@ import (
22
22
"slices"
23
23
"strconv"
24
24
"strings"
25
+ "text/template"
25
26
26
27
"github.com/magefile/mage/mg"
27
28
"github.com/magefile/mage/sh"
@@ -87,6 +88,7 @@ type OSPackageArgs struct {
87
88
88
89
// PackageSpec specifies package metadata and the contents of the package.
89
90
type PackageSpec struct {
91
+ << << << < HEAD
90
92
Name string `yaml:"name,omitempty"`
91
93
ServiceName string `yaml:"service_name,omitempty"`
92
94
OS string `yaml:"os,omitempty"`
@@ -107,6 +109,30 @@ type PackageSpec struct {
107
109
OutputFile string `yaml:"output_file,omitempty"` // Optional
108
110
ExtraVars map [string ]string `yaml:"extra_vars,omitempty"` // Optional
109
111
Components []packaging.BinarySpec `yaml:"components"` // Optional: Components required for this package
112
+ == == == =
113
+ Name string `yaml:"name,omitempty"`
114
+ ServiceName string `yaml:"service_name,omitempty"`
115
+ OS string `yaml:"os,omitempty"`
116
+ Arch string `yaml:"arch,omitempty"`
117
+ Vendor string `yaml:"vendor,omitempty"`
118
+ Snapshot bool `yaml:"snapshot"`
119
+ FIPS bool `yaml:"fips"`
120
+ Version string `yaml:"version,omitempty"`
121
+ License string `yaml:"license,omitempty"`
122
+ URL string `yaml:"url,omitempty"`
123
+ Description string `yaml:"description,omitempty"`
124
+ DockerVariant DockerVariant `yaml:"docker_variant,omitempty"`
125
+ DockerImageNameTemplate string `yaml:"docker_image_name_template,omitempty"` // Optional: template of the docker image name
126
+ PreInstallScript string `yaml:"pre_install_script,omitempty"`
127
+ PostInstallScript string `yaml:"post_install_script,omitempty"`
128
+ PostRmScript string `yaml:"post_rm_script,omitempty"`
129
+ Files map [string ]PackageFile `yaml:"files"`
130
+ Qualifier string `yaml:"qualifier,omitempty"` // Optional
131
+ OutputFile string `yaml:"output_file,omitempty"` // Optional
132
+ ExtraVars map [string ]string `yaml:"extra_vars,omitempty"` // Optional
133
+ ExtraTags []string `yaml:"extra_tags,omitempty"` // Optional
134
+ Components []packaging.BinarySpec `yaml:"components"` // Optional: Components required for this package
135
+ >> >> >> > 79 dec1cc2 (Add docker image name template and renamed fips cloud specs (#8429 ))
110
136
111
137
evalContext map [string ]interface {}
112
138
packageDir string
@@ -475,6 +501,30 @@ func (s PackageSpec) Evaluate(args ...map[string]interface{}) PackageSpec {
475
501
476
502
// ImageName computes the image name from the spec.
477
503
func (s PackageSpec ) ImageName () string {
504
+ if s .DockerImageNameTemplate != "" {
505
+ imageNameTmpl , err := template .New ("dockerImageTemplate" ).Parse (s .DockerImageNameTemplate )
506
+ if err != nil {
507
+ panic (fmt .Errorf ("parsing docker image name template for %s variant %s: %w" , s .Name , s .DockerVariant , err ))
508
+ }
509
+
510
+ data := s .toMap ()
511
+ for k , v := range varMap () {
512
+ data [k ] = v
513
+ }
514
+
515
+ buf := new (strings.Builder )
516
+ err = imageNameTmpl .Execute (buf , data )
517
+ if err != nil {
518
+ panic (fmt .Errorf ("rendering docker image name template for %s variant %s: %w" , s .Name , s .DockerVariant , err ))
519
+ }
520
+
521
+ imageName := buf .String ()
522
+ if mg .Verbose () {
523
+ log .Printf ("rendered image name for %s variant %s: %s" , s .Name , s .DockerVariant , imageName )
524
+ }
525
+ return imageName
526
+ }
527
+
478
528
if s .DockerVariant == Basic {
479
529
// no suffix for basic docker variant
480
530
return s .Name
@@ -774,7 +824,7 @@ func runFPM(spec PackageSpec, packageType PackageType) error {
774
824
args = append (args , "--vendor" , spec .Vendor )
775
825
}
776
826
if spec .License != "" {
777
- args = append (args , "--license" , strings .Replace (spec .License , " " , "-" , - 1 ))
827
+ args = append (args , "--license" , strings .ReplaceAll (spec .License , " " , "-" ))
778
828
}
779
829
if spec .Description != "" {
780
830
args = append (args , "--description" , spec .Description )
0 commit comments