Skip to content

Commit afd503b

Browse files
author
Lukas Gentele
committed
small fixes for gitignore and console output
1 parent cf1b557 commit afd503b

File tree

5 files changed

+49
-52
lines changed

5 files changed

+49
-52
lines changed

cmd/init.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/spf13/cobra"
2626
)
2727

28-
const configGitignore = "\n\n# Exclude .devspace generated files\n.devspace/"
28+
const configGitignore = "\n\n# Exclude .devspace generated files\n.devspace/\n"
2929

3030
const (
3131
// Cluster options
@@ -88,7 +88,8 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
8888
// Check if config already exists
8989
configExists := configutil.ConfigExists()
9090
if configExists && cmd.Reconfigure == false {
91-
log.Info("Config devspace.yaml already exists. If you want to recreate the config please run `devspace init --reconfigure`")
91+
log.Info("Config already exists. If you want to recreate the config please run `devspace init --reconfigure`")
92+
log.Infof("If you want to continue with the existing config, run:\n- `%s` to develop application\n- `%s` to deploy application", ansi.Color("devspace dev", "white+b"), ansi.Color("devspace deploy", "white+b"))
9293
os.Exit(0)
9394
}
9495

@@ -230,14 +231,23 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
230231
if os.IsNotExist(err) {
231232
fsutil.WriteToFile([]byte(configGitignore), ".gitignore")
232233
} else {
233-
gitignore, err := os.OpenFile(".gitignore", os.O_APPEND|os.O_WRONLY, 0600)
234+
gitignoreContent, err := ioutil.ReadFile(".gitignore")
234235
if err != nil {
235-
log.Warnf("Error writing to .gitignore: %v", err)
236+
log.Warnf("Error reading .gitignore: %v", err)
236237
} else {
237-
defer gitignore.Close()
238+
gitignoreRegexp := regexp.MustCompile("(?ms)(^|[^!]).devspace/(\\n|$)")
238239

239-
if _, err = gitignore.WriteString(configGitignore); err != nil {
240-
log.Warnf("Error writing to .gitignore: %v", err)
240+
if gitignoreRegexp.MatchString(string(gitignoreContent)) == false {
241+
gitignore, err := os.OpenFile(".gitignore", os.O_APPEND|os.O_WRONLY, 0600)
242+
if err != nil {
243+
log.Warnf("Error writing to .gitignore: %v", err)
244+
} else {
245+
defer gitignore.Close()
246+
247+
if _, err = gitignore.WriteString(configGitignore); err != nil {
248+
log.Warnf("Error writing to .gitignore: %v", err)
249+
}
250+
}
241251
}
242252
}
243253
}

pkg/devspace/cloud/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (p *Provider) ConnectCluster(options *ConnectClusterOptions) error {
7575
// Check what kube context to use
7676
if options.KubeContext == "" {
7777
// Get kube context to use
78-
config, err = kubectl.GetClientConfigBySelect(false)
78+
config, err = kubectl.GetClientConfigBySelect(false, true)
7979
if err != nil {
8080
return errors.Wrap(err, "new kubectl client")
8181
}
@@ -533,7 +533,7 @@ func (p *Provider) ResetKey(clusterName string) error {
533533
}
534534

535535
// Get kube context to use
536-
config, err := kubectl.GetClientConfigBySelect(false)
536+
config, err := kubectl.GetClientConfigBySelect(false, false)
537537
if err != nil {
538538
return errors.Wrap(err, "new kubectl client")
539539
}

pkg/devspace/configure/image.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,13 @@ func GetImageConfigFromDockerfile(config *latest.Config, dockerfile, context str
8484
}
8585

8686
// Check if docker is installed
87-
for {
88-
_, err = client.Ping(contextpkg.Background())
89-
if err != nil {
90-
// Check if docker cli is installed
91-
runErr := exec.Command("docker").Run()
92-
if runErr == nil {
93-
useKaniko = survey.Question(&survey.QuestionOptions{
94-
Question: "Docker seems to be installed but is not running: " + err.Error() + " \nShould we build with kaniko instead?",
95-
DefaultValue: "no",
96-
Options: []string{"yes", "no"},
97-
}) == "yes"
98-
99-
if useKaniko == false {
100-
continue
101-
}
102-
}
103-
104-
// We use kaniko
105-
useKaniko = true
106-
107-
// Set default build engine to kaniko, if no docker is installed
108-
retImageConfig.Build = &latest.BuildConfig{
109-
Kaniko: &latest.KanikoConfig{
110-
Cache: ptr.Bool(true),
111-
},
112-
}
87+
_, err = client.Ping(contextpkg.Background())
88+
if err != nil {
89+
// Check if docker cli is installed
90+
runErr := exec.Command("docker").Run()
91+
if runErr == nil {
92+
log.Warn("Docker daemon not running. Start Docker daemon to build images with Docker instead of using the kaniko fallback.")
11393
}
114-
115-
break
11694
}
11795

11896
// If not kaniko get docker hub credentials

pkg/devspace/kubectl/client.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func GetClientConfigFromKubectl() (*rest.Config, error) {
6363
}
6464

6565
// GetClientConfigBySelect let's the user select a kube context to use
66-
func GetClientConfigBySelect(allowPrivate bool) (*rest.Config, error) {
66+
func GetClientConfigBySelect(allowPrivate bool, switchContext bool) (*rest.Config, error) {
6767
kubeConfig, err := kubeconfig.ReadKubeConfig(clientcmd.RecommendedHomeFile)
6868
if err != nil {
6969
return nil, err
@@ -104,6 +104,15 @@ func GetClientConfigBySelect(allowPrivate bool) (*rest.Config, error) {
104104
}
105105
}
106106

107+
if switchContext {
108+
kubeConfig.CurrentContext = kubeContext
109+
110+
err = kubeconfig.WriteKubeConfig(kubeConfig, clientcmd.RecommendedHomeFile)
111+
if err != nil {
112+
return nil, errors.Wrap(err, "write kube config")
113+
}
114+
}
115+
107116
return GetClientConfigFromContext(kubeContext)
108117
}
109118

pkg/util/log/loading_text.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,7 @@ func (l *loadingText) getLoadingChar() string {
5151
var loadingChar string
5252
var max int
5353

54-
if runtime.GOOS == "windows" {
55-
switch l.loadingRune {
56-
case 0:
57-
loadingChar = "|"
58-
case 1:
59-
loadingChar = "/"
60-
case 2:
61-
loadingChar = "-"
62-
case 3:
63-
loadingChar = "\\"
64-
}
65-
66-
max = 3
67-
} else {
54+
if runtime.GOOS == "darwin" {
6855
switch l.loadingRune {
6956
case 0:
7057
loadingChar = "⠋"
@@ -89,6 +76,19 @@ func (l *loadingText) getLoadingChar() string {
8976
}
9077

9178
max = 9
79+
} else {
80+
switch l.loadingRune {
81+
case 0:
82+
loadingChar = "|"
83+
case 1:
84+
loadingChar = "/"
85+
case 2:
86+
loadingChar = "-"
87+
case 3:
88+
loadingChar = "\\"
89+
}
90+
91+
max = 3
9292
}
9393

9494
l.loadingRune++

0 commit comments

Comments
 (0)