@@ -3,14 +3,14 @@ package cmd
33import (
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
@@ -128,8 +128,8 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
128128 createChart := cmd .flags .overwrite
129129
130130 if ! cmd .flags .overwrite {
131- _ , dockerfileNotFound := os .Stat (cmd .chartGenerator . Path + "/Dockerfile" )
132- _ , chartDirNotFound := os .Stat (cmd .chartGenerator . Path + "/chart" )
131+ _ , dockerfileNotFound := os .Stat (cmd .workdir + "/Dockerfile" )
132+ _ , chartDirNotFound := os .Stat (cmd .workdir + "/chart" )
133133
134134 if dockerfileNotFound == nil || chartDirNotFound == nil {
135135 overwriteAnswer := stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
@@ -144,18 +144,25 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
144144 }
145145
146146 if createChart {
147- cmd .determineAppConfig ()
148-
149- cmd .config . Image . Name = cmd . config . DevSpace . Release . Name
147+ cmd .initChartGenerator ()
148+ cmd . determineLanguage ()
149+ cmd .createChart ()
150150 }
151151
152152 if cmd .flags .reconfigure || ! configExists {
153- cmd .reconfigure ()
154- }
153+ cmd .configureKubernetes ()
154+ cmd . configureDevSpace ()
155155
156- if createChart {
157- cmd .determineLanguage ()
158- 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+ }
159166 }
160167}
161168
@@ -176,16 +183,16 @@ func (cmd *InitCmd) initChartGenerator() {
176183 }
177184}
178185
179- func (cmd * InitCmd ) determineAppConfig () {
180- _ , chartDirNotFound := os .Stat (cmd .chartGenerator . Path + "/chart" )
186+ func (cmd * InitCmd ) configureDevSpace () {
187+ _ , chartDirNotFound := os .Stat (cmd .workdir + "/chart" )
181188
182189 if chartDirNotFound == nil {
183190 /*TODO
184191 existingChartYaml := map[interface{}]interface{}{}
185192 existingChartValuesYaml := map[interface{}]interface{}{}
186193
187- yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path +"/chart/Chart.yaml", existingChartYaml)
188- 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)
189196
190197 cmd.config.Release.Name = existingChartYaml["name"].(string)
191198
@@ -206,6 +213,12 @@ func (cmd *InitCmd) determineAppConfig() {
206213 ValidationRegexPattern : v1 .Kubernetes .RegexPatterns .Name ,
207214 })
208215
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+
209222 // cmd.appConfig.Container.Ports, _ = strconv.Atoi(stdinutil.GetFromStdin(&stdinutil.GetFromStdin_params{
210223 // Question: "Which port(s) does your application listen on? (separated by spaces)",
211224 // DefaultValue: strconv.Itoa(cmd.appConfig.Container.Port),
@@ -265,6 +278,19 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
265278 return
266279 }
267280 }
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+ }
268294
269295 syncConfig := append (* cmd .config .DevSpace .Sync , & v1.SyncConfig {
270296 ContainerPath : configutil .String ("/app" ),
@@ -273,21 +299,15 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
273299 LabelSelector : & map [string ]* string {
274300 "release" : cmd .config .DevSpace .Release .Name ,
275301 },
302+ UploadExcludePaths : & uploadExcludePaths ,
276303 })
277304 cmd .config .DevSpace .Sync = & syncConfig
278305}
279306
280- func (cmd * InitCmd ) reconfigure () {
281- clusterConfig := cmd .overwriteConfig .Cluster
307+ func (cmd * InitCmd ) configureTiller () {
282308 tillerConfig := cmd .config .Services .Tiller
283309 tillerRelease := tillerConfig .Release
284310
285- cmd .config .DevSpace .Release .Namespace = stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
286- Question : "Which Kubernetes namespace should your application run in?" ,
287- DefaultValue : * cmd .config .DevSpace .Release .Namespace ,
288- ValidationRegexPattern : v1 .Kubernetes .RegexPatterns .Name ,
289- })
290-
291311 if tillerRelease .Namespace == nil {
292312 tillerRelease .Namespace = cmd .config .DevSpace .Release .Namespace
293313 }
@@ -296,6 +316,10 @@ func (cmd *InitCmd) reconfigure() {
296316 DefaultValue : * tillerRelease .Namespace ,
297317 ValidationRegexPattern : v1 .Kubernetes .RegexPatterns .Name ,
298318 })
319+ }
320+
321+ func (cmd * InitCmd ) configureKubernetes () {
322+ clusterConfig := cmd .config .Cluster
299323 useKubeConfig := false
300324 homeDir , homeErr := homedir .Dir ()
301325
@@ -346,16 +370,9 @@ func (cmd *InitCmd) reconfigure() {
346370 InputTerminationString : "-----END RSA PRIVATE KEY-----" ,
347371 })
348372 }
349- cmd .reconfigureRegistry ()
350-
351- err := configutil .SaveConfig ()
352-
353- if err != nil {
354- log .With (err ).Fatalf ("Config error: %s" , err .Error ())
355- }
356373}
357374
358- func (cmd * InitCmd ) reconfigureRegistry () {
375+ func (cmd * InitCmd ) configureRegistry () {
359376 registryConfig := cmd .config .Services .Registry
360377
361378 enableAutomaticBuilds := stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
@@ -475,18 +492,18 @@ func (cmd *InitCmd) determineLanguage() {
475492 if len (cmd .chartGenerator .Language ) == 0 {
476493 log .StartWait ("Detecting programming language" )
477494
478- cmd .chartGenerator .Language , _ = cmd .chartGenerator .GetLanguage ()
479495 supportedLanguages , err := cmd .chartGenerator .GetSupportedLanguages ()
480496
497+ if err != nil {
498+ log .Fatalf ("Unable to get supported languages: %s" , err .Error ())
499+ }
500+ cmd .chartGenerator .Language , _ = cmd .chartGenerator .GetLanguage ()
501+
481502 if cmd .chartGenerator .Language == "" {
482503 cmd .chartGenerator .Language = "none"
483504 }
484505 log .StopWait ()
485506
486- if err != nil {
487- log .Fatalf ("Unable to get supported languages: %s" , err .Error ())
488- }
489-
490507 cmd .chartGenerator .Language = * stdinutil .GetFromStdin (& stdinutil.GetFromStdinParams {
491508 Question : "What is the major programming language of your project?\n Supported languages: " + strings .Join (supportedLanguages , ", " ),
492509 DefaultValue : cmd .chartGenerator .Language ,
@@ -502,14 +519,13 @@ func (cmd *InitCmd) createChart() {
502519 log .Fatalf ("Error while creating Helm chart and Dockerfile: %s" , err .Error ())
503520 }
504521
522+ /*TODO
505523 createdChartYaml := map[interface{}]interface{}{}
506524 createdChartValuesYaml := map[interface{}]interface{}{}
507525
508526 yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path+"/chart/Chart.yaml", &createdChartYaml)
509527 yamlutil.ReadYamlFromFile(cmd.chartGenerator.Path+"/chart/values.yaml", &createdChartValuesYaml)
510528
511- createdChartYaml ["name" ] = cmd .config .DevSpace .Release .Name
512- /*TODO
513529 containerValues, chartHasContainerValues := createdChartValuesYaml["container"].(map[interface{}]interface{})
514530
515531 if !chartHasContainerValues && containerValues != nil {
@@ -524,7 +540,7 @@ func (cmd *InitCmd) createChart() {
524540 externalValues["domain"] = cmd.appConfig.External.Domain
525541 createdChartValuesYaml["external"] = externalValues
526542 }
527- */
528543 yamlutil.WriteYamlToFile(createdChartYaml, cmd.chartGenerator.Path+"/chart/Chart.yaml")
529544 yamlutil.WriteYamlToFile(createdChartValuesYaml, cmd.chartGenerator.Path+"/chart/values.yaml")
545+ */
530546}
0 commit comments