Skip to content

Commit 1ccfe23

Browse files
committed
fix: add init question to determine if a deployment is to be developed or deployed
1 parent 03aa35b commit 1ccfe23

3 files changed

Lines changed: 90 additions & 60 deletions

File tree

cmd/init.go

Lines changed: 77 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -334,82 +334,99 @@ func (cmd *InitCmd) initDevspace(f factory.Factory, configLoader loader.ConfigLo
334334
break
335335
}
336336

337-
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-
}
344-
345-
images, err := parseImages(manifests)
346-
if err != nil {
347-
return errors.Wrap(err, "error parsing images")
348-
}
349-
350-
imageManual := "Manually enter the image I want to work on"
351-
imageSkip := "Skip (do not add dev configuration for any images)"
352-
imageAnswer := ""
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+
}
353351

354-
if len(images) > 0 {
355-
imageAnswer, err = cmd.log.Question(&survey.QuestionOptions{
356-
Question: "Which image do you want to develop with DevSpace?",
357-
DefaultValue: images[0],
358-
Options: append(images, []string{imageManual, imageSkip}...),
359-
})
352+
image := ""
353+
if developOrDeployProject == developProject {
354+
for {
355+
if !mustAddComponentChart {
356+
manifests, err := cmd.render(f, config)
360357
if err != nil {
361-
return err
358+
return errors.Wrap(err, "error rendering deployment")
362359
}
363-
} else {
364-
imageAnswer, err = cmd.log.Question(&survey.QuestionOptions{
365-
Question: "Couldn’t find any images in your manifests/helm charts. Do you want to skip this step?",
366-
Options: []string{imageManual, imageSkip},
367-
})
360+
361+
images, err := parseImages(manifests)
368362
if err != nil {
369-
return err
363+
return errors.Wrap(err, "error parsing images")
370364
}
371-
}
372365

373-
if imageAnswer == imageSkip {
374-
break
375-
} else if imageAnswer == imageManual {
376-
imageQuestion := "What is the main container image of this project?"
366+
imageManual := "Manually enter the image I want to work on"
367+
imageSkip := "Skip (do not add dev configuration for any images)"
368+
imageAnswer := ""
377369

378-
if selectedDeploymentOption == DeployOptionHelm {
379-
imageQuestion = "What is the main container image of this project which is deployed by this Helm chart? (e.g. ecr.io/project/image)"
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+
}
380387
}
381388

382-
if selectedDeploymentOption == DeployOptionKubectl {
383-
imageQuestion = "What is the main container image of this project which is deployed by these manifests? (e.g. ecr.io/project/image)"
384-
}
389+
if imageAnswer == imageSkip {
390+
break
391+
} else if imageAnswer == imageManual {
392+
imageQuestion := "What is the main container image of this project?"
385393

386-
if selectedDeploymentOption == DeployOptionKustomize {
387-
imageQuestion = "What is the main container image of this project which is deployed by this Kustomization? (e.g. ecr.io/project/image)"
388-
}
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+
}
389401

390-
image, err = cmd.log.Question(&survey.QuestionOptions{
391-
Question: imageQuestion,
392-
ValidationMessage: "Please enter a valid container image from a Kubernetes pod (e.g. myregistry.tld/project/image)",
393-
ValidationFunc: func(name string) error {
394-
_, _, err := dockerfile.GetStrippedDockerImageName(strings.ToLower(name))
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 {
395415
return err
396-
},
397-
})
398-
if err != nil {
399-
return err
416+
}
417+
} else {
418+
image = imageAnswer
400419
}
401-
} else {
402-
image = imageAnswer
403420
}
404-
}
405421

406-
err = configureManager.AddImage(imageName, image, projectNamespace+"/"+projectName, cmd.Dockerfile)
407-
if err != nil {
408-
if err.Error() != "" {
409-
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
410429
}
411-
} else {
412-
break
413430
}
414431
}
415432

pkg/devspace/configure/deployment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (m *manager) AddKubectlDeployment(deploymentName string, isKustomization bo
8181
if isKustomization {
8282
m.config.Deployments[deploymentName].Kubectl.Kustomize = ptr.Bool(isKustomization)
8383
}
84+
m.isRemote[deploymentName] = false
8485

8586
return nil
8687
}
@@ -147,6 +148,7 @@ func (m *manager) AddHelmDeployment(deploymentName string) error {
147148
}
148149

149150
helmConfig.Chart.Name = localChartPathRel
151+
m.isRemote[deploymentName] = false
150152
} else if chartLocation == chartRepo || chartLocation == archiveURL {
151153
ChartRepoLoop:
152154
for {
@@ -249,6 +251,7 @@ func (m *manager) AddHelmDeployment(deploymentName string) error {
249251
m.localCache.SetVar(passwordVar, password)
250252
}
251253

254+
m.isRemote[deploymentName] = true
252255
break ChartRepoLoop
253256
}
254257
}
@@ -305,6 +308,7 @@ func (m *manager) AddHelmDeployment(deploymentName string) error {
305308
Events: []string{"before:deploy"},
306309
})
307310

311+
m.isRemote[deploymentName] = true
308312
break
309313
}
310314
}
@@ -360,10 +364,15 @@ func (m *manager) AddComponentDeployment(deploymentName, image string, servicePo
360364
Values: chartValues,
361365
},
362366
}
367+
m.isRemote[deploymentName] = true
363368

364369
return nil
365370
}
366371

372+
func (m *manager) IsRemoteDeployment(deploymentName string) bool {
373+
return m.isRemote[deploymentName]
374+
}
375+
367376
func chartRepoURL(url string) string {
368377
repoURL := url
369378
if !(strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://")) {

pkg/devspace/configure/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package configure
22

33
import (
44
"context"
5+
56
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
67
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
78
"github.com/loft-sh/devspace/pkg/devspace/docker"
@@ -15,6 +16,7 @@ type Manager interface {
1516
AddHelmDeployment(deploymentName string) error
1617
AddComponentDeployment(deploymentName, image string, servicePort int) error
1718
AddImage(imageName, image, projectNamespace, dockerfile string) error
19+
IsRemoteDeployment(imageName string) bool
1820
}
1921

2022
// Factory defines the factory methods needed by the configure manager to create new configuration
@@ -28,6 +30,7 @@ type manager struct {
2830
config *latest.Config
2931
localCache localcache.Cache
3032
factory Factory
33+
isRemote map[string]bool
3134
}
3235

3336
// NewManager creates a new instance of the interface Manager
@@ -37,5 +40,6 @@ func NewManager(factory Factory, config *latest.Config, localCache localcache.Ca
3740
factory: factory,
3841
config: config,
3942
localCache: localCache,
43+
isRemote: map[string]bool{},
4044
}
4145
}

0 commit comments

Comments
 (0)