@@ -27,8 +27,6 @@ type Builder struct {
2727
2828 imageConfigName string
2929 imageTag string
30-
31- cmd command.Interface
3230}
3331
3432// NewBuilder creates a new custom builder
@@ -56,7 +54,7 @@ func (b *Builder) ShouldRebuild(cache *generated.CacheConfig, forceRebuild, igno
5654 // Loop over on change globs
5755 customFilesHash := ""
5856 for _ , pattern := range b .imageConf .Build .Custom .OnChange {
59- files , err := doublestar .Glob (* pattern )
57+ files , err := doublestar .Glob (pattern )
6058 if err != nil {
6159 return false , err
6260 }
@@ -88,27 +86,32 @@ func (b *Builder) Build(log logpkg.Logger) error {
8886 // Build arguments
8987 args := []string {}
9088
91- if b .imageConf .Build .Custom .ImageFlag != "" {
92- args = append (args , b . imageConf . Build . Custom . ImageFlag )
89+ for _ , arg := range b .imageConf .Build .Custom .Args {
90+ args = append (args , arg )
9391 }
9492
9593 if len (b .imageConf .Tags ) == 0 {
94+ if b .imageConf .Build .Custom .ImageFlag != "" {
95+ args = append (args , b .imageConf .Build .Custom .ImageFlag )
96+ }
97+
9698 args = append (args , b .imageConf .Image + ":" + b .imageTag )
9799 } else {
98100 for _ , tag := range b .imageConf .Tags {
101+ if b .imageConf .Build .Custom .ImageFlag != "" {
102+ args = append (args , b .imageConf .Build .Custom .ImageFlag )
103+ }
104+
99105 args = append (args , b .imageConf .Image + ":" + tag )
100106 }
101107 }
102108
103- if b .imageConf .Build .Custom .Args != nil {
104- for _ , arg := range b .imageConf .Build .Custom .Args {
105- args = append (args , * arg )
106- }
109+ for _ , arg := range b .imageConf .Build .Custom .AppendArgs {
110+ args = append (args , arg )
107111 }
108112
109- if b .cmd == nil {
110- b .cmd = command .NewStreamCommand (filepath .FromSlash (b .imageConf .Build .Custom .Command ), args )
111- }
113+ // Create the command
114+ cmd := command .NewStreamCommand (filepath .FromSlash (b .imageConf .Build .Custom .Command ), args )
112115
113116 // Determine output writer
114117 var writer io.Writer
@@ -120,7 +123,7 @@ func (b *Builder) Build(log logpkg.Logger) error {
120123
121124 log .Infof ("Build %s:%s with custom command %s %s" , b .imageConf .Image , b .imageTag , b .imageConf .Build .Custom .Command , strings .Join (args , " " ))
122125
123- err := b . cmd .Run (writer , writer , nil )
126+ err := cmd .Run (writer , writer , nil )
124127 if err != nil {
125128 return errors .Errorf ("Error building image: %v" , err )
126129 }
0 commit comments