Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 124 additions & 124 deletions cmd/init.go

Large diffs are not rendered by default.

122 changes: 61 additions & 61 deletions e2e/tests/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"os"
"path/filepath"
"strings"

"github.com/loft-sh/devspace/pkg/devspace/config/loader/variable"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
Expand All @@ -25,55 +25,55 @@ var _ = DevSpaceDescribe("init", func() {
if err != nil {
panic(err)
}

// create a new factory
var (
f *framework.DefaultFactory
kubeClient *kube.KubeHelper
)

ginkgo.BeforeEach(func() {
f = framework.NewDefaultFactory()

kubeClient, err = kube.NewKubeHelper()
framework.ExpectNoError(err)
})

ginkgo.It("should create devspace.yml without registry details", func() {
tempDir, err := framework.CopyToTempDir("tests/init/testdata/new")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

// set the question answer func here
f.SetAnswerFunc(func(params *survey.QuestionOptions) (string, error) {
if strings.Contains(params.Question, "How do you want to deploy this project?") {
return cmd.DeployOptionHelm, nil
}

if strings.Contains(params.Question, "If you were to push any images, which container registry would you want to push to?") {
return "Skip Registry", nil
}

if strings.Contains(params.Question, "How should DevSpace build the container image for this project?") {
return "Skip / I don't know", nil
}

return params.DefaultValue, nil
})

initCmd := &cmd.InitCmd{GlobalFlags: &flags.GlobalFlags{}}
err = initCmd.Run(f)
framework.ExpectNoError(err)

config, _, err := framework.LoadConfig(f, kubeClient.Client(), filepath.Join(tempDir, "devspace.yaml"))
framework.ExpectNoError(err)

framework.ExpectEqual(len(config.Variables()), len(variable.AlwaysResolvePredefinedVars))

ns, err := kubeClient.CreateNamespace("init")
framework.ExpectNoError(err)
defer framework.ExpectDeleteNamespace(kubeClient, ns)

done := make(chan error)
go func() {
devCmd := &cmd.RunPipelineCmd{
Expand All @@ -85,46 +85,46 @@ var _ = DevSpaceDescribe("init", func() {
}
done <- devCmd.RunDefault(f)
}()

err = <-done
framework.ExpectNoError(err)
})

ginkgo.It("should create devspace.yml without registry details and manifests deploy", func() {
tempDir, err := framework.CopyToTempDir("tests/init/testdata/new")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

// set the question answer func here
f.SetAnswerFunc(func(params *survey.QuestionOptions) (string, error) {
if strings.Contains(params.Question, "Which registry would you want to use to push images to?") {
return "Skip Registry", nil
}

if strings.Contains(params.Question, "How do you want to deploy this project?") {
return cmd.DeployOptionKubectl, nil
}

if strings.Contains(params.Question, "Please enter the paths to your Kubernetes manifests") {
return "manifests/**", nil
}

return params.DefaultValue, nil
})

initCmd := &cmd.InitCmd{GlobalFlags: &flags.GlobalFlags{}}
err = initCmd.Run(f)
framework.ExpectNoError(err)

config, _, err := framework.LoadConfig(f, kubeClient.Client(), filepath.Join(tempDir, "devspace.yaml"))
framework.ExpectNoError(err)

framework.ExpectEqual(len(config.Variables()), len(variable.AlwaysResolvePredefinedVars))

ns, err := kubeClient.CreateNamespace("init")
framework.ExpectNoError(err)
defer framework.ExpectDeleteNamespace(kubeClient, ns)

devCmd := &cmd.RunPipelineCmd{
GlobalFlags: &flags.GlobalFlags{
NoWarn: true,
Expand All @@ -136,42 +136,42 @@ var _ = DevSpaceDescribe("init", func() {
err = devCmd.RunDefault(f)
framework.ExpectNoError(err)
})

ginkgo.It("should create devspace.yml without registry details and kustomize deploy", func() {
tempDir, err := framework.CopyToTempDir("tests/init/testdata/new")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

// set the question answer func here
f.SetAnswerFunc(func(params *survey.QuestionOptions) (string, error) {
if strings.Contains(params.Question, "Which registry would you want to use to push images to?") {
return "Skip Registry", nil
}

if strings.Contains(params.Question, "How do you want to deploy this project?") {
return cmd.DeployOptionKustomize, nil
}

if strings.Contains(params.Question, "Please enter path to your Kustomization folder") {
return "./kustomization", nil
}

return params.DefaultValue, nil
})

initCmd := &cmd.InitCmd{GlobalFlags: &flags.GlobalFlags{}}
err = initCmd.Run(f)
framework.ExpectNoError(err)

config, _, err := framework.LoadConfig(f, kubeClient.Client(), filepath.Join(tempDir, "devspace.yaml"))
framework.ExpectNoError(err)

framework.ExpectEqual(len(config.Variables()), len(variable.AlwaysResolvePredefinedVars))

ns, err := kubeClient.CreateNamespace("init")
framework.ExpectNoError(err)
defer framework.ExpectDeleteNamespace(kubeClient, ns)

done := make(chan error)
go func() {
devCmd := &cmd.RunPipelineCmd{
Expand All @@ -183,50 +183,50 @@ var _ = DevSpaceDescribe("init", func() {
}
done <- devCmd.RunDefault(f)
}()

err = <-done
framework.ExpectNoError(err)
})

ginkgo.It("should create devspace.yml without registry details and local helm chart deploy", func() {
tempDir, err := framework.CopyToTempDir("tests/init/testdata/new")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

// set the question answer func here
f.SetAnswerFunc(func(params *survey.QuestionOptions) (string, error) {
if strings.Contains(params.Question, "Which registry would you want to use to push images to?") {
return "Skip Registry", nil
}

if strings.Contains(params.Question, "How do you want to deploy this project?") {
return cmd.DeployOptionHelm, nil
}

if strings.Contains(params.Question, "Which Helm chart do you want to use?") {
return `Use a local Helm chart (e.g. ./helm/chart/)`, nil
}

if strings.Contains(params.Question, "Please enter the relative path to your local Helm chart") {
return "./chart", nil
}

return params.DefaultValue, nil
})

initCmd := &cmd.InitCmd{GlobalFlags: &flags.GlobalFlags{}}
err = initCmd.Run(f)
framework.ExpectNoError(err)

config, _, err := framework.LoadConfig(f, kubeClient.Client(), filepath.Join(tempDir, "devspace.yaml"))
framework.ExpectNoError(err)

framework.ExpectEqual(len(config.Variables()), len(variable.AlwaysResolvePredefinedVars))

ns, err := kubeClient.CreateNamespace("init")
framework.ExpectNoError(err)
defer framework.ExpectDeleteNamespace(kubeClient, ns)

done := make(chan error)
go func() {
devCmd := &cmd.RunPipelineCmd{
Expand All @@ -238,42 +238,42 @@ var _ = DevSpaceDescribe("init", func() {
}
done <- devCmd.RunDefault(f)
}()

err = <-done
framework.ExpectNoError(err)
})

ginkgo.It("should create devspace.yml from docker-compose.yaml", func() {
tempDir, err := framework.CopyToTempDir("tests/init/testdata/docker-compose")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

ns, err := kubeClient.CreateNamespace("init")
framework.ExpectNoError(err)
defer func() {
err := kubeClient.DeleteNamespace(ns)
framework.ExpectNoError(err)
}()

// Answer all questions with the default
f.SetAnswerFunc(func(params *survey.QuestionOptions) (string, error) {
return params.DefaultValue, nil
})

initCmd := &cmd.InitCmd{
Reconfigure: true,
}
err = initCmd.Run(f)
framework.ExpectNoError(err)

// Created a devspace.yaml
_, _, err = framework.LoadConfig(f, kubeClient.Client(), filepath.Join(tempDir, "devspace.yaml"))
framework.ExpectNoError(err)

// Created a .gitignore
_, err = os.Stat(filepath.Join(tempDir, ".gitignore"))
framework.ExpectNoError(err)

// Print the config to verify the expected deployment
var configBuffer bytes.Buffer
printCmd := &cmd.PrintCmd{
Expand All @@ -283,18 +283,18 @@ var _ = DevSpaceDescribe("init", func() {
},
Out: &configBuffer,
}

err = printCmd.Run(f)
framework.ExpectNoError(err)

generatedConfig := &latest.Config{}
err = yaml.Unmarshal(configBuffer.Bytes(), generatedConfig)
framework.ExpectNoError(err)

// validate config
framework.ExpectEqual(len(generatedConfig.Deployments), 1)
framework.ExpectHaveKey(generatedConfig.Deployments, "db")

// ensure valid configuration by deploying the application
deployCmd := &cmd.RunPipelineCmd{
GlobalFlags: &flags.GlobalFlags{
Expand All @@ -306,7 +306,7 @@ var _ = DevSpaceDescribe("init", func() {
SkipPush: true,
}
err = deployCmd.RunDefault(f)

framework.ExpectNoError(err)
})
})
2 changes: 2 additions & 0 deletions e2e/tests/init/testdata/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: shiken

version: "3.7"
services:
db:
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/blang/semver v3.5.1+incompatible
github.com/bmatcuk/doublestar v1.1.1
github.com/compose-spec/compose-go v1.2.2
github.com/compose-spec/compose-go v1.20.0
github.com/creack/pty v1.1.18
github.com/docker/cli v24.0.0+incompatible
github.com/docker/distribution v2.8.2+incompatible
Expand Down Expand Up @@ -89,7 +89,7 @@ require (
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e // indirect
github.com/distribution/distribution/v3 v3.0.0-20221103125252-ebfa2a0ac0a9 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
Expand Down Expand Up @@ -123,7 +123,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
Expand All @@ -140,7 +140,7 @@ require (
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
Expand Down Expand Up @@ -184,6 +184,7 @@ require (
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sync v0.3.0 // indirect
Expand Down
Loading
Loading