@@ -458,12 +458,7 @@ For more options, run 'func deploy --help'`, err)
458458 if buildOptions , err = cfg .buildOptions (); err != nil {
459459 return
460460 }
461-
462- var (
463- digested bool
464- justBuilt bool
465- justPushed bool
466- )
461+ var digested bool
467462
468463 // Validate the image and check whether its digested or not
469464 if cfg .Image != "" {
@@ -483,20 +478,30 @@ For more options, run 'func deploy --help'`, err)
483478 if digested {
484479 f .Deploy .Image = cfg .Image
485480 } else {
486- // NOT digested, build & push the Function unless specified otherwise
487- if f , justBuilt , err = build (cmd , cfg .Build , f , client , buildOptions ); err != nil {
481+ // NOT digested: scaffold, build & push as per config
482+ var (
483+ shouldBuild bool
484+ justPushed bool
485+ )
486+ if shouldBuild , err = build (cmd , cfg .Build , f ); err != nil {
488487 return
489488 }
489+ if shouldBuild {
490+ if err = client .Scaffold (cmd .Context (), f , "" ); err != nil {
491+ return
492+ }
493+ if f , err = client .Build (cmd .Context (), f , buildOptions ... ); err != nil {
494+ return
495+ }
496+ }
490497 if cfg .Push {
491498 if f , justPushed , err = client .Push (cmd .Context (), f ); err != nil {
492499 return
493500 }
494501 }
495- // TODO: gauron99 - temporary fix for undigested image direct deploy
496- // (w/out build) This might be more complex to do than leaving like this
497- // image digests are created via the registry on push.
498- if (justBuilt || justPushed ) && f .Build .Image != "" {
499- // f.Build.Image is set in Push for now, just set it as a deployed image
502+ // image was just build and pushed to registry => potentially new image
503+ if (shouldBuild || justPushed ) && f .Build .Image != "" {
504+ // f.Build.Image is set when pushed to registry, just set it as a deployed image
500505 f .Deploy .Image = f .Build .Image
501506 }
502507 }
@@ -523,33 +528,24 @@ For more options, run 'func deploy --help'`, err)
523528 return f .Stamp ()
524529}
525530
526- // build when flag == 'auto' and the function is out-of-date, or when the
527- // flag value is explicitly truthy such as 'true' or '1'. Error if flag
528- // is neither 'auto' nor parseable as a boolean. Return CLI-specific error
529- // message verbeage suitable for both Deploy and Run commands which feature an
530- // optional build step. Boolean return value signifies if the image has gone
531- // through a build process.
532- func build (cmd * cobra.Command , flag string , f fn.Function , client * fn.Client , buildOptions []fn.BuildOption ) (fn.Function , bool , error ) {
533- var err error
531+ // build determines IF function should be built in current run returning an
532+ // error, if it occurs, during flag parsing
533+ func build (cmd * cobra.Command , flag string , f fn.Function ) (bool , error ) {
534534 if flag == "auto" {
535535 if f .Built () {
536536 fmt .Fprintln (cmd .OutOrStdout (), "function up-to-date. Force rebuild with --build" )
537- return f , false , nil
537+ return false , nil
538538 } else {
539- if f , err = client .Build (cmd .Context (), f , buildOptions ... ); err != nil {
540- return f , false , err
541- }
539+ return true , nil
542540 }
543541 } else if build , _ := strconv .ParseBool (flag ); build {
544- if f , err = client .Build (cmd .Context (), f , buildOptions ... ); err != nil {
545- return f , false , err
546- }
547- } else if _ , err = strconv .ParseBool (flag ); err != nil {
548- return f , false , fmt .Errorf ("invalid value for the build flag (%q), valid value is either 'auto' or a boolean" , flag )
542+ return true , nil
543+ } else if _ , err := strconv .ParseBool (flag ); err != nil {
544+ return false , fmt .Errorf ("invalid value for the build flag (%q), valid value is either 'auto' or a boolean" , flag )
549545 } else if ! build {
550- return f , false , nil
546+ return false , nil
551547 }
552- return f , true , nil
548+ return false , nil
553549}
554550
555551func NewRegistryValidator (path string ) survey.Validator {
0 commit comments