@@ -124,37 +124,50 @@ func dockerBuild() error {
124124
125125 fmt .Printf ("Container Build Path: %v\n " , dco .Path )
126126
127- buildArgs := BuildArgs ( dco .BuildArgs )
127+ buildArgs ( & dco .BuildArgs )
128128
129129 fmt .Printf ("Base image: %s\n " , dco .BuildArgs .BaseImage )
130130
131131 fmt .Printf ("Build Args: %s\n " , buildArgs )
132132
133- session .Command ("docker" , "build" , "--no-cache" , "--pull" , fmt .Sprintf ("%v" , buildArgs ), fmt .Sprintf ("%s" , dco .Path )).Run ()
133+ session .Command ("docker" , "build" , "--no-cache" , "--pull" ,
134+ "--build-arg" , "BASE_IMAGE=" + dco .BuildArgs .BaseImage ,
135+ "--build-arg" , "VERSION=" + dco .BuildArgs .Version ,
136+ "--build-arg" , "TARGETARCH=" + dco .BuildArgs .TargetArch ,
137+ "--build-arg" , "COMMIT_SHA=" + dco .BuildArgs .CommitSHA ,
138+ "--build-arg" , "BUILD_ID=" + dco .BuildArgs .BuildId ,
139+ dco .Path ).Run ()
134140
135141 return nil
136142
137143}
138144
139- func buildArgs (b * BuildArgs ) string {
145+ func buildArgs (b * BuildArgs ) {
140146
141147 if b .BaseImage == "" {
142148 base , err := getIngressNginxBase ()
143149 CheckIfError (err , "Issue Retrieving base image" )
144- fmt .Printf ("Base Image set %s\n " , base )
145150 b .BaseImage = base
146151 }
147152
148- buildArgString := "--build-arg BASE_IMAGE=" + b .BaseImage
149-
150- return buildArgString
153+ if b .Version == "" {
154+ b .Version = "1.0.0-dev"
155+ }
156+ if b .TargetArch == "" {
157+ b .TargetArch = getArch ()
158+ }
159+ if b .CommitSHA == "" {
160+ sha , _ := sh .Command ("git" , "rev-parse" , "--short" , "HEAD" ).Output ()
161+ b .CommitSHA = strings .TrimSpace (string (sha ))
162+ }
163+ if b .BuildId == "" {
164+ b .BuildId = "UNSET"
165+ }
151166}
152167
153168func getIngressNginxBase () (string , error ) {
154- fmt .Print ("GET INGRESS NGINX BASE" )
155169 dat , err := os .ReadFile ("../NGINX_BASE" )
156170 CheckIfError (err , "Could not read NGINX_BASE file" )
157- fmt .Printf ("Get Ingress Dat: %v\n " , dat )
158171 datString := string (dat )
159172 //remove newline
160173 datString = strings .Replace (datString , "\n " , "" , - 1 )
0 commit comments