@@ -334,64 +334,125 @@ func (cmd *InitCmd) initDevspace(f factory.Factory, configLoader loader.ConfigLo
334334 break
335335 }
336336
337+ developProject := "I want to develop this project and my current working dir contains the source code"
338+ deployProject := "I just want to deploy this project"
339+ defaultProjectAction := deployProject
340+ if ! configureManager .IsRemoteDeployment (imageName ) {
341+ defaultProjectAction = developProject
342+ }
343+ developOrDeployProject , err := cmd .log .Question (& survey.QuestionOptions {
344+ Question : "Do you want to develop this project with DevSpace or just deploy it? [Use arrows to move, type to filter]" ,
345+ Options : []string {developProject , deployProject },
346+ DefaultValue : defaultProjectAction ,
347+ })
348+ if err != nil {
349+ return err
350+ }
351+
337352 image := ""
338- for {
339- if ! mustAddComponentChart {
340- manifests , err := cmd .render (f , config )
341- if err != nil {
342- return errors .Wrap (err , "error rendering deployment" )
343- }
353+ if developOrDeployProject == developProject {
354+ for {
355+ if ! mustAddComponentChart {
356+ manifests , err := cmd .render (f , config )
357+ if err != nil {
358+ return errors .Wrap (err , "error rendering deployment" )
359+ }
344360
345- images , err := parseImages (manifests )
346- if err != nil {
347- return errors .Wrap (err , "error parsing images" )
348- }
361+ images , err := parseImages (manifests )
362+ if err != nil {
363+ return errors .Wrap (err , "error parsing images" )
364+ }
349365
350- if len ( images ) == 0 {
351- return fmt . Errorf ( "no images found for the selected deployments" )
352- }
366+ imageManual := "Manually enter the image I want to work on"
367+ imageSkip := "Skip (do not add dev configuration for any images)"
368+ imageAnswer := ""
353369
354- image , err = cmd .log .Question (& survey.QuestionOptions {
355- Question : "Which image do you want to develop with DevSpace?" ,
356- DefaultValue : images [0 ],
357- Options : images ,
358- })
359- if err != nil {
360- return err
370+ if len (images ) > 0 {
371+ imageAnswer , err = cmd .log .Question (& survey.QuestionOptions {
372+ Question : "Which image do you want to develop with DevSpace?" ,
373+ DefaultValue : images [0 ],
374+ Options : append (images , []string {imageManual , imageSkip }... ),
375+ })
376+ if err != nil {
377+ return err
378+ }
379+ } else {
380+ imageAnswer , err = cmd .log .Question (& survey.QuestionOptions {
381+ Question : "Couldn’t find any images in your manifests/helm charts. Do you want to skip this step?" ,
382+ Options : []string {imageManual , imageSkip },
383+ })
384+ if err != nil {
385+ return err
386+ }
387+ }
388+
389+ if imageAnswer == imageSkip {
390+ break
391+ } else if imageAnswer == imageManual {
392+ imageQuestion := "What is the main container image of this project?"
393+
394+ if selectedDeploymentOption == DeployOptionHelm {
395+ imageQuestion = "What is the main container image of this project which is deployed by this Helm chart? (e.g. ecr.io/project/image)"
396+ }
397+
398+ if selectedDeploymentOption == DeployOptionKubectl {
399+ imageQuestion = "What is the main container image of this project which is deployed by these manifests? (e.g. ecr.io/project/image)"
400+ }
401+
402+ if selectedDeploymentOption == DeployOptionKustomize {
403+ imageQuestion = "What is the main container image of this project which is deployed by this Kustomization? (e.g. ecr.io/project/image)"
404+ }
405+
406+ image , err = cmd .log .Question (& survey.QuestionOptions {
407+ Question : imageQuestion ,
408+ ValidationMessage : "Please enter a valid container image from a Kubernetes pod (e.g. myregistry.tld/project/image)" ,
409+ ValidationFunc : func (name string ) error {
410+ _ , _ , err := dockerfile .GetStrippedDockerImageName (strings .ToLower (name ))
411+ return err
412+ },
413+ })
414+ if err != nil {
415+ return err
416+ }
417+ } else {
418+ image = imageAnswer
419+ }
361420 }
362- }
363421
364- err = configureManager .AddImage (imageName , image , projectNamespace + "/" + projectName , cmd .Dockerfile )
365- if err != nil {
366- if err .Error () != "" {
367- cmd .log .Errorf ("Error: %s" , err .Error ())
422+ err = configureManager .AddImage (imageName , image , projectNamespace + "/" + projectName , cmd .Dockerfile )
423+ if err != nil {
424+ if err .Error () != "" {
425+ cmd .log .Errorf ("Error: %s" , err .Error ())
426+ }
427+ } else {
428+ break
368429 }
369- } else {
370- break
371430 }
372431 }
373432
374- image = config .Images [imageName ].Image
375-
376433 // Determine app port
377434 portString := ""
378435
379- // Try to get ports from dockerfile
380- ports , err := dockerfile .GetPorts (config .Images [imageName ].Dockerfile )
381- if err == nil {
382- if len (ports ) == 1 {
383- portString = strconv .Itoa (ports [0 ])
384- } else if len (ports ) > 1 {
385- portString , err = cmd .log .Question (& survey.QuestionOptions {
386- Question : "Which port is your application listening on?" ,
387- DefaultValue : strconv .Itoa (ports [0 ]),
388- })
389- if err != nil {
390- return err
391- }
436+ if len (config .Images ) > 0 {
437+ image = config .Images [imageName ].Image
392438
393- if portString == "" {
439+ // Try to get ports from dockerfile
440+ ports , err := dockerfile .GetPorts (config .Images [imageName ].Dockerfile )
441+ if err == nil {
442+ if len (ports ) == 1 {
394443 portString = strconv .Itoa (ports [0 ])
444+ } else if len (ports ) > 1 {
445+ portString , err = cmd .log .Question (& survey.QuestionOptions {
446+ Question : "Which port is your application listening on?" ,
447+ DefaultValue : strconv .Itoa (ports [0 ]),
448+ })
449+ if err != nil {
450+ return err
451+ }
452+
453+ if portString == "" {
454+ portString = strconv .Itoa (ports [0 ])
455+ }
395456 }
396457 }
397458 }
@@ -722,7 +783,7 @@ func (cmd *InitCmd) render(f factory.Factory, config *latest.Config) (string, er
722783 err := loader .Save (renderPath , config )
723784 defer os .Remove (renderPath )
724785 if err != nil {
725- return "" , err
786+ return "" , errors . Wrap ( err , "temp render.yaml" )
726787 }
727788
728789 // Use the render command to render it.
@@ -741,8 +802,7 @@ func (cmd *InitCmd) render(f factory.Factory, config *latest.Config) (string, er
741802 }
742803 err = renderCmd .RunDefault (f )
743804 if err != nil {
744- f .GetLog ().Debugf ("error rendering chart: %v" , err )
745- return "" , nil
805+ return "" , errors .Wrap (err , "devspace render" )
746806 }
747807
748808 return writer .String (), nil
0 commit comments