Skip to content

Commit ebaa015

Browse files
committed
refactor: remove names on devspace print
1 parent 9fe8a4c commit ebaa015

7 files changed

Lines changed: 93 additions & 43 deletions

File tree

cmd/init.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ func (cmd *InitCmd) Run(f factory.Factory) error {
159159
} else {
160160
err = cmd.initDevspace(f, configLoader)
161161
}
162-
163162
if err != nil {
164-
panic(err)
163+
return err
165164
}
166165

167166
cmd.log.WriteString(logrus.InfoLevel, "\n")
@@ -434,7 +433,7 @@ func (cmd *InitCmd) initDevspace(f factory.Factory, configLoader loader.ConfigLo
434433

435434
config.Commands["migrate-db"] = &latest.CommandConfig{
436435
Command: `echo 'This is a cross-platform, shared command that can be used to codify any kind of dev task.'
437-
echo 'Anyone using this project can invoke it via "devspace run migrate-db"'`,
436+
echo 'Anyone using this project can invoke it via "devspace run migrate-db"'`,
438437
}
439438
}
440439

@@ -453,8 +452,7 @@ start_dev ` + imageName + ` # 3. Start dev mode "` + imageNa
453452
config.Pipelines["deploy"] = &latest.Pipeline{
454453
Run: `run_dependency_pipelines --all # 1. Deploy any projects this project needs (see "dependencies")
455454
build_images --all -t $(git describe --always) # 2. Build, tag (git commit hash) and push all images (see "images")
456-
create_deployments --all \ # 3. Deploy Helm charts and manifests specfied as "deployments"
457-
--set updateImageTags=true # + make sure to update all image tags to the one from step 2`,
455+
create_deployments --all # 3. Deploy Helm charts and manifests specfied as "deployments"`,
458456
}
459457

460458
// Save config

cmd/print.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"github.com/loft-sh/devspace/pkg/devspace/config"
7+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
78
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
89
"github.com/loft-sh/devspace/pkg/devspace/dependency"
910
"github.com/loft-sh/devspace/pkg/devspace/dependency/types"
@@ -27,8 +28,9 @@ import (
2728
type PrintCmd struct {
2829
*flags.GlobalFlags
2930

30-
Out io.Writer
31-
SkipInfo bool
31+
Out io.Writer
32+
StripNames bool
33+
SkipInfo bool
3234

3335
Dependency string
3436
}
@@ -37,6 +39,7 @@ type PrintCmd struct {
3739
func NewPrintCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command {
3840
cmd := &PrintCmd{
3941
GlobalFlags: globalFlags,
42+
StripNames: true,
4043
Out: os.Stdout,
4144
}
4245

@@ -117,7 +120,7 @@ func (cmd *PrintCmd) Run(f factory.Factory) error {
117120
ctx = ctx.AsDependency(dep)
118121
}
119122

120-
bsConfig, err := yaml.Marshal(ctx.Config().Config())
123+
bsConfig, err := marshalConfig(ctx.Config().Config(), cmd.StripNames)
121124
if err != nil {
122125
return err
123126
}
@@ -141,6 +144,41 @@ func (cmd *PrintCmd) Run(f factory.Factory) error {
141144
return nil
142145
}
143146

147+
func marshalConfig(config *latest.Config, stripNames bool) ([]byte, error) {
148+
// remove the auto generated names
149+
if stripNames {
150+
for k := range config.Images {
151+
config.Images[k].Name = ""
152+
}
153+
for k := range config.Deployments {
154+
config.Deployments[k].Name = ""
155+
}
156+
for k := range config.Dependencies {
157+
config.Dependencies[k].Name = ""
158+
}
159+
for k := range config.Pipelines {
160+
config.Pipelines[k].Name = ""
161+
}
162+
for k := range config.Dev {
163+
config.Dev[k].Name = ""
164+
for c := range config.Dev[k].Containers {
165+
config.Dev[k].Containers[c].Container = ""
166+
}
167+
}
168+
for k := range config.Vars {
169+
config.Vars[k].Name = ""
170+
}
171+
for k := range config.PullSecrets {
172+
config.PullSecrets[k].Name = ""
173+
}
174+
for k := range config.Commands {
175+
config.Commands[k].Name = ""
176+
}
177+
}
178+
179+
return yaml.Marshal(config)
180+
}
181+
144182
func printExtraInfo(config config.Config, dependencies []types.Dependency, log logger.Logger) error {
145183
log.WriteString(logrus.InfoLevel, "\n-------------------\n\nVars:\n")
146184

cmd/run_pipeline.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type RunPipelineCmd struct {
6464
// used for testing to allow interruption
6565
Ctx context.Context
6666
RenderWriter io.Writer
67-
log log.Logger
67+
Log log.Logger
6868
}
6969

7070
func (cmd *RunPipelineCmd) AddPipelineFlags(f factory.Factory, command *cobra.Command, pipeline *latest.Pipeline) {
@@ -227,16 +227,16 @@ func (cmd *RunPipelineCmd) Run(cobraCmd *cobra.Command, args []string, f factory
227227
cmd.Pipeline = args[0]
228228
}
229229

230-
if cmd.log == nil {
231-
cmd.log = f.GetLog()
230+
if cmd.Log == nil {
231+
cmd.Log = f.GetLog()
232232
}
233233
if cmd.Silent {
234-
cmd.log.SetLevel(logrus.FatalLevel)
234+
cmd.Log.SetLevel(logrus.FatalLevel)
235235
}
236236

237237
// Print upgrade message if new version available
238238
if !cmd.Render {
239-
upgrade.PrintUpgradeMessage(cmd.log)
239+
upgrade.PrintUpgradeMessage(cmd.Log)
240240
} else if cmd.RenderWriter == nil {
241241
cmd.RenderWriter = os.Stdout
242242
}
@@ -256,7 +256,7 @@ func (cmd *RunPipelineCmd) Run(cobraCmd *cobra.Command, args []string, f factory
256256
cmd.Ctx = values.WithFlags(cmd.Ctx, cobraCmd.Flags())
257257
}
258258
options := cmd.BuildOptions(cmd.ToConfigOptions())
259-
ctx, err := initialize(cmd.Ctx, f, false, options, cmd.log)
259+
ctx, err := initialize(cmd.Ctx, f, false, options, cmd.Log)
260260
if err != nil {
261261
return err
262262
}

e2e/tests/init/init.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package init
33
import (
44
"bytes"
55
"fmt"
6+
"github.com/loft-sh/devspace/pkg/util/log"
7+
"github.com/sirupsen/logrus"
68
"os"
79
"path/filepath"
810
"strings"
@@ -125,19 +127,15 @@ var _ = DevSpaceDescribe("init", func() {
125127
framework.ExpectNoError(err)
126128
defer framework.ExpectDeleteNamespace(kubeClient, ns)
127129

128-
done := make(chan error)
129-
go func() {
130-
devCmd := &cmd.RunPipelineCmd{
131-
GlobalFlags: &flags.GlobalFlags{
132-
NoWarn: true,
133-
Namespace: ns,
134-
},
135-
Pipeline: "dev",
136-
}
137-
done <- devCmd.RunDefault(f)
138-
}()
139-
140-
err = <-done
130+
devCmd := &cmd.RunPipelineCmd{
131+
GlobalFlags: &flags.GlobalFlags{
132+
NoWarn: true,
133+
Namespace: ns,
134+
},
135+
Pipeline: "dev",
136+
Log: log.GetInstance().WithLevel(logrus.DebugLevel),
137+
}
138+
err = devCmd.RunDefault(f)
141139
framework.ExpectNoError(err)
142140
})
143141

pkg/devspace/config/versions/adjust.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func adjustConfig(config *latest.Config) error {
3232
newObjs := map[string]*latest.Image{}
3333
for k, v := range config.Images {
3434
if v != nil {
35+
v.Name = k
3536
image, tag, err := dockerfile.GetStrippedDockerImageName(v.Image)
3637
if err != nil {
3738
return errors.Errorf("error parsing images.%s.image: '%s': %v", k, v.Image, err)

pkg/devspace/config/versions/latest/schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ type RequireCommand struct {
232232

233233
// Image defines the image specification
234234
type Image struct {
235+
// Name of the image, will be filled automatically
236+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
237+
235238
// Image is the complete image name including registry and repository
236239
// for example myregistry.com/mynamespace/myimage
237240
Image string `yaml:"image" json:"image"`

pkg/devspace/configure/image.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ func (m *manager) AddImage(imageName, image, projectNamespace, dockerfile string
7575
} else {
7676
if buildMethod != skip && buildMethod != rootLevelDockerfile {
7777
imageConfig.Dockerfile, err = m.log.Question(&survey.QuestionOptions{
78-
Question: "Please enter the path to this Dockerfile",
78+
Question: "Please enter the path to this Dockerfile: (Enter to skip)",
7979
ValidationFunc: func(value string) error {
80+
if value == "" {
81+
return nil
82+
}
83+
8084
stat, err := os.Stat(value)
8185
if err == nil && !stat.IsDir() {
8286
return nil
@@ -88,24 +92,28 @@ func (m *manager) AddImage(imageName, image, projectNamespace, dockerfile string
8892
return err
8993
}
9094

91-
imageConfig.Context, err = m.log.Question(&survey.QuestionOptions{
92-
Question: "What is the build context for building this image?",
93-
DefaultValue: path.Dir(imageConfig.Dockerfile) + "/",
94-
ValidationFunc: func(value string) error {
95-
stat, err := os.Stat(value)
96-
if err != nil && !stat.IsDir() {
97-
return errors.New("Context path does not exist or is not a directory")
98-
}
99-
return nil
100-
},
101-
})
102-
if err != nil {
103-
return err
95+
if imageConfig.Dockerfile != "" {
96+
imageConfig.Context, err = m.log.Question(&survey.QuestionOptions{
97+
Question: "What is the build context for building this image?",
98+
DefaultValue: path.Dir(imageConfig.Dockerfile) + "/",
99+
ValidationFunc: func(value string) error {
100+
stat, err := os.Stat(value)
101+
if err != nil && !stat.IsDir() {
102+
return errors.New("Context path does not exist or is not a directory")
103+
}
104+
return nil
105+
},
106+
})
107+
if err != nil {
108+
return err
109+
}
110+
} else {
111+
buildMethod = skip
104112
}
105113
}
106114
}
107115

108-
if image == "" {
116+
if image == "" && buildMethod != skip {
109117
// Ignore error as context may not be a Space
110118
kubeContext, err := m.factory.NewKubeConfigLoader().GetCurrentContext()
111119
if err != nil {
@@ -200,8 +208,12 @@ func (m *manager) AddImage(imageName, image, projectNamespace, dockerfile string
200208
}
201209
}
202210

203-
m.config.Images[imageName] = imageConfig
211+
if buildMethod == skip {
212+
imageConfig.Image = "username/app"
213+
imageConfig.Dockerfile = "./Dockerfile"
214+
}
204215

216+
m.config.Images[imageName] = imageConfig
205217
return nil
206218
}
207219

0 commit comments

Comments
 (0)