Skip to content

Commit 693c503

Browse files
author
Lukas Gentele
authored
Merge pull request #168 from covexo/issue-164
Issue 164
2 parents 255a964 + 28b7836 commit 693c503

2 files changed

Lines changed: 57 additions & 42 deletions

File tree

cmd/init.go

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package cmd
33
import (
44
"io/ioutil"
55
"os"
6+
"path/filepath"
67
"strconv"
78
"strings"
89

910
"github.com/covexo/devspace/pkg/devspace/config/configutil"
1011
"github.com/covexo/devspace/pkg/devspace/generator"
1112
"github.com/covexo/devspace/pkg/util/log"
1213
"github.com/covexo/devspace/pkg/util/randutil"
13-
"github.com/covexo/devspace/pkg/util/yamlutil"
1414
"github.com/imdario/mergo"
1515
homedir "github.com/mitchellh/go-homedir"
1616

@@ -124,13 +124,12 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
124124
User: &v1.User{},
125125
},
126126
})
127-
cmd.initChartGenerator()
128127

129128
createChart := cmd.flags.overwrite
130129

131130
if !cmd.flags.overwrite {
132-
_, dockerfileNotFound := os.Stat(cmd.chartGenerator.Path + "/Dockerfile")
133-
_, chartDirNotFound := os.Stat(cmd.chartGenerator.Path + "/chart")
131+
_, dockerfileNotFound := os.Stat(cmd.workdir + "/Dockerfile")
132+
_, chartDirNotFound := os.Stat(cmd.workdir + "/chart")
134133

135134
if dockerfileNotFound == nil || chartDirNotFound == nil {
136135
overwriteAnswer := stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
@@ -145,18 +144,25 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
145144
}
146145

147146
if createChart {
148-
cmd.determineAppConfig()
149-
150-
cmd.config.Image.Name = cmd.config.DevSpace.Release.Name
147+
cmd.initChartGenerator()
148+
cmd.determineLanguage()
149+
cmd.createChart()
151150
}
152151

153152
if cmd.flags.reconfigure || !configExists {
154-
cmd.reconfigure()
155-
}
153+
cmd.configureKubernetes()
154+
cmd.configureDevSpace()
156155

157-
if createChart {
158-
cmd.determineLanguage()
159-
cmd.createChart()
156+
cmd.config.Image.Name = cmd.config.DevSpace.Release.Name
157+
158+
cmd.configureTiller()
159+
cmd.configureRegistry()
160+
161+
err := configutil.SaveConfig()
162+
163+
if err != nil {
164+
log.With(err).Fatalf("Config error: %s", err.Error())
165+
}
160166
}
161167
}
162168

@@ -177,16 +183,16 @@ func (cmd *InitCmd) initChartGenerator() {
177183
}
178184
}
179185

180-
func (cmd *InitCmd) determineAppConfig() {
181-
_, chartDirNotFound := os.Stat(cmd.chartGenerator.Path + "/chart")
186+
func (cmd *InitCmd) configureDevSpace() {
187+
_, chartDirNotFound := os.Stat(cmd.workdir + "/chart")
182188

183189
if chartDirNotFound == nil {
184190
/*TODO
185191
existingChartYaml := map[interface{}]interface{}{}
186192
existingChartValuesYaml := map[interface{}]interface{}{}
187193
188-
yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path+"/chart/Chart.yaml", existingChartYaml)
189-
yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path+"/chart/values.yaml", existingChartValuesYaml)
194+
yamlutil.ReadYamlFromFile(cmd.workdir+"/chart/Chart.yaml", existingChartYaml)
195+
yamlutil.ReadYamlFromFile(cmd.workdir+"/chart/values.yaml", existingChartValuesYaml)
190196
191197
cmd.config.Release.Name = existingChartYaml["name"].(string)
192198
@@ -207,6 +213,12 @@ func (cmd *InitCmd) determineAppConfig() {
207213
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
208214
})
209215

216+
cmd.config.DevSpace.Release.Namespace = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
217+
Question: "Which Kubernetes namespace should your application run in?",
218+
DefaultValue: *cmd.config.DevSpace.Release.Namespace,
219+
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
220+
})
221+
210222
// cmd.appConfig.Container.Ports, _ = strconv.Atoi(stdinutil.GetFromStdin(&stdinutil.GetFromStdin_params{
211223
// Question: "Which port(s) does your application listen on? (separated by spaces)",
212224
// DefaultValue: strconv.Itoa(cmd.appConfig.Container.Port),
@@ -266,6 +278,19 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
266278
return
267279
}
268280
}
281+
dockerignoreFile := filepath.Join(cmd.workdir, ".dockerignore")
282+
dockerignore, err := ioutil.ReadFile(dockerignoreFile)
283+
uploadExcludePaths := []string{}
284+
285+
if err == nil {
286+
dockerignoreRules := strings.Split(string(dockerignore), "\n")
287+
288+
for _, ignoreRule := range dockerignoreRules {
289+
if len(ignoreRule) > 0 {
290+
uploadExcludePaths = append(uploadExcludePaths, ignoreRule)
291+
}
292+
}
293+
}
269294

270295
syncConfig := append(*cmd.config.DevSpace.Sync, &v1.SyncConfig{
271296
ContainerPath: configutil.String("/app"),
@@ -274,21 +299,15 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
274299
LabelSelector: &map[string]*string{
275300
"release": cmd.config.DevSpace.Release.Name,
276301
},
302+
UploadExcludePaths: &uploadExcludePaths,
277303
})
278304
cmd.config.DevSpace.Sync = &syncConfig
279305
}
280306

281-
func (cmd *InitCmd) reconfigure() {
282-
clusterConfig := cmd.config.Cluster
307+
func (cmd *InitCmd) configureTiller() {
283308
tillerConfig := cmd.config.Services.Tiller
284309
tillerRelease := tillerConfig.Release
285310

286-
cmd.config.DevSpace.Release.Namespace = stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
287-
Question: "Which Kubernetes namespace should your application run in?",
288-
DefaultValue: *cmd.config.DevSpace.Release.Namespace,
289-
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
290-
})
291-
292311
if tillerRelease.Namespace == nil {
293312
tillerRelease.Namespace = cmd.config.DevSpace.Release.Namespace
294313
}
@@ -297,6 +316,10 @@ func (cmd *InitCmd) reconfigure() {
297316
DefaultValue: *tillerRelease.Namespace,
298317
ValidationRegexPattern: v1.Kubernetes.RegexPatterns.Name,
299318
})
319+
}
320+
321+
func (cmd *InitCmd) configureKubernetes() {
322+
clusterConfig := cmd.config.Cluster
300323
useKubeConfig := false
301324
homeDir, homeErr := homedir.Dir()
302325

@@ -344,16 +367,9 @@ func (cmd *InitCmd) reconfigure() {
344367
InputTerminationString: "-----END RSA PRIVATE KEY-----",
345368
})
346369
}
347-
cmd.reconfigureRegistry()
348-
349-
err := configutil.SaveConfig()
350-
351-
if err != nil {
352-
log.With(err).Fatalf("Config error: %s", err.Error())
353-
}
354370
}
355371

356-
func (cmd *InitCmd) reconfigureRegistry() {
372+
func (cmd *InitCmd) configureRegistry() {
357373
overwriteConfig := configutil.GetOverwriteConfig()
358374
registryConfig := cmd.config.Services.Registry
359375

@@ -474,18 +490,18 @@ func (cmd *InitCmd) determineLanguage() {
474490
if len(cmd.chartGenerator.Language) == 0 {
475491
log.StartWait("Detecting programming language")
476492

477-
cmd.chartGenerator.Language, _ = cmd.chartGenerator.GetLanguage()
478493
supportedLanguages, err := cmd.chartGenerator.GetSupportedLanguages()
479494

495+
if err != nil {
496+
log.Fatalf("Unable to get supported languages: %s", err.Error())
497+
}
498+
cmd.chartGenerator.Language, _ = cmd.chartGenerator.GetLanguage()
499+
480500
if cmd.chartGenerator.Language == "" {
481501
cmd.chartGenerator.Language = "none"
482502
}
483503
log.StopWait()
484504

485-
if err != nil {
486-
log.Fatalf("Unable to get supported languages: %s", err.Error())
487-
}
488-
489505
cmd.chartGenerator.Language = *stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
490506
Question: "What is the major programming language of your project?\nSupported languages: " + strings.Join(supportedLanguages, ", "),
491507
DefaultValue: cmd.chartGenerator.Language,
@@ -501,14 +517,13 @@ func (cmd *InitCmd) createChart() {
501517
log.Fatalf("Error while creating Helm chart and Dockerfile: %s", err.Error())
502518
}
503519

520+
/*TODO
504521
createdChartYaml := map[interface{}]interface{}{}
505522
createdChartValuesYaml := map[interface{}]interface{}{}
506523
507524
yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path+"/chart/Chart.yaml", &createdChartYaml)
508525
yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path+"/chart/values.yaml", &createdChartValuesYaml)
509526
510-
createdChartYaml["name"] = cmd.config.DevSpace.Release.Name
511-
/*TODO
512527
containerValues, chartHasContainerValues := createdChartValuesYaml["container"].(map[interface{}]interface{})
513528
514529
if !chartHasContainerValues && containerValues != nil {
@@ -523,7 +538,7 @@ func (cmd *InitCmd) createChart() {
523538
externalValues["domain"] = cmd.appConfig.External.Domain
524539
createdChartValuesYaml["external"] = externalValues
525540
}
526-
*/
527541
yamlutil.WriteYamlToFile(createdChartYaml, cmd.chartGenerator.Path+"/chart/Chart.yaml")
528542
yamlutil.WriteYamlToFile(createdChartValuesYaml, cmd.chartGenerator.Path+"/chart/values.yaml")
543+
*/
529544
}

pkg/devspace/generator/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ func (cg *ChartGenerator) CreateChart() error {
109109
return nil
110110
}
111111

112-
// AddPackage adds a package to the ChartGenerator
112+
// AddPackage adds a package to the project's helm chart
113113
func (cg *ChartGenerator) AddPackage(pkg string) {
114114

115115
}
116116

117-
// RemovePackage removes a package from the ChartGenerator
117+
// RemovePackage removes a package to the project's helm chart
118118
func (cg *ChartGenerator) RemovePackage(pkg string) {
119119

120120
}

0 commit comments

Comments
 (0)