|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "os" |
5 | 4 | "os/exec" |
6 | 5 | "strings" |
7 | 6 |
|
@@ -31,11 +30,8 @@ import ( |
31 | 30 |
|
32 | 31 | // UpCmd is a struct that defines a command call for "up" |
33 | 32 | type UpCmd struct { |
34 | | - flags *UpCmdFlags |
35 | | - kubectl *kubernetes.Clientset |
36 | | - workdir string |
37 | | - pod *k8sv1.Pod |
38 | | - container *k8sv1.Container |
| 33 | + flags *UpCmdFlags |
| 34 | + kubectl *kubernetes.Clientset |
39 | 35 | } |
40 | 36 |
|
41 | 37 | // UpCmdFlags are the flags available for the up-command |
@@ -102,13 +98,8 @@ Starts and connects your DevSpace: |
102 | 98 | // Run executes the command logic |
103 | 99 | func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) { |
104 | 100 | log.StartFileLogging() |
| 101 | + var err error |
105 | 102 |
|
106 | | - workdir, err := os.Getwd() |
107 | | - if err != nil { |
108 | | - log.Fatalf("Unable to determine current workdir: %s", err.Error()) |
109 | | - } |
110 | | - |
111 | | - cmd.workdir = workdir |
112 | 103 | configExists, _ := configutil.ConfigExists() |
113 | 104 | if !configExists { |
114 | 105 | initCmd := &InitCmd{ |
@@ -164,59 +155,7 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) { |
164 | 155 | }() |
165 | 156 | } |
166 | 157 |
|
167 | | - services.StartTerminal(cmd.kubectl, cmd.flags.container, args) |
168 | | -} |
169 | | - |
170 | | -func (cmd *UpCmd) buildAndDeploy() { |
171 | | - config := configutil.GetConfig() |
172 | | - |
173 | | - // Load config |
174 | | - generatedConfig, err := generated.LoadConfig() |
175 | | - if err != nil { |
176 | | - log.Fatalf("Error loading generated.yaml: %v", err) |
177 | | - } |
178 | | - |
179 | | - // Build image if necessary |
180 | | - mustRedeploy := cmd.buildImages(generatedConfig) |
181 | | - |
182 | | - // Deploy all defined deployments |
183 | | - if config.DevSpace.Deployments != nil { |
184 | | - for _, deployConfig := range *config.DevSpace.Deployments { |
185 | | - var deployClient deploy.Interface |
186 | | - |
187 | | - if deployConfig.Kubectl != nil { |
188 | | - log.StartWait("Deploying " + *deployConfig.Name + " with kubectl") |
189 | | - |
190 | | - deployClient, err = deployKubectl.New(cmd.kubectl, deployConfig, log.GetInstance()) |
191 | | - if err != nil { |
192 | | - log.Fatalf("Error deploying devspace: deployment %s error: %v", *deployConfig.Name, err) |
193 | | - } |
194 | | - } else if deployConfig.Helm != nil { |
195 | | - log.StartWait("Deploying " + *deployConfig.Name + " with helm") |
196 | | - |
197 | | - deployClient, err = deployHelm.New(cmd.kubectl, deployConfig, log.GetInstance()) |
198 | | - if err != nil { |
199 | | - log.Fatalf("Error deploying devspace: deployment %s error: %v", *deployConfig.Name, err) |
200 | | - } |
201 | | - } else { |
202 | | - log.Fatalf("Error deploying devspace: deployment %s has no deployment method", *deployConfig.Name) |
203 | | - } |
204 | | - |
205 | | - err = deployClient.Deploy(generatedConfig, mustRedeploy || cmd.flags.deploy) |
206 | | - if err != nil { |
207 | | - log.Fatalf("Error deploying %s: %v", *deployConfig.Name, err) |
208 | | - } |
209 | | - |
210 | | - log.StopWait() |
211 | | - log.Donef("Successfully deployed %s", *deployConfig.Name) |
212 | | - } |
213 | | - |
214 | | - // Save Config |
215 | | - err = generated.SaveConfig(generatedConfig) |
216 | | - if err != nil { |
217 | | - log.Fatalf("Error saving config: %v", err) |
218 | | - } |
219 | | - } |
| 158 | + services.StartTerminal(cmd.kubectl, cmd.flags.container, args, log.GetInstance()) |
220 | 159 | } |
221 | 160 |
|
222 | 161 | func (cmd *UpCmd) ensureNamespace() error { |
@@ -387,6 +326,58 @@ func (cmd *UpCmd) initRegistries() { |
387 | 326 | } |
388 | 327 | } |
389 | 328 |
|
| 329 | +func (cmd *UpCmd) buildAndDeploy() { |
| 330 | + config := configutil.GetConfig() |
| 331 | + |
| 332 | + // Load config |
| 333 | + generatedConfig, err := generated.LoadConfig() |
| 334 | + if err != nil { |
| 335 | + log.Fatalf("Error loading generated.yaml: %v", err) |
| 336 | + } |
| 337 | + |
| 338 | + // Build image if necessary |
| 339 | + mustRedeploy := cmd.buildImages(generatedConfig) |
| 340 | + |
| 341 | + // Deploy all defined deployments |
| 342 | + if config.DevSpace.Deployments != nil { |
| 343 | + for _, deployConfig := range *config.DevSpace.Deployments { |
| 344 | + var deployClient deploy.Interface |
| 345 | + |
| 346 | + if deployConfig.Kubectl != nil { |
| 347 | + log.StartWait("Deploying " + *deployConfig.Name + " with kubectl") |
| 348 | + |
| 349 | + deployClient, err = deployKubectl.New(cmd.kubectl, deployConfig, log.GetInstance()) |
| 350 | + if err != nil { |
| 351 | + log.Fatalf("Error deploying devspace: deployment %s error: %v", *deployConfig.Name, err) |
| 352 | + } |
| 353 | + } else if deployConfig.Helm != nil { |
| 354 | + log.StartWait("Deploying " + *deployConfig.Name + " with helm") |
| 355 | + |
| 356 | + deployClient, err = deployHelm.New(cmd.kubectl, deployConfig, log.GetInstance()) |
| 357 | + if err != nil { |
| 358 | + log.Fatalf("Error deploying devspace: deployment %s error: %v", *deployConfig.Name, err) |
| 359 | + } |
| 360 | + } else { |
| 361 | + log.Fatalf("Error deploying devspace: deployment %s has no deployment method", *deployConfig.Name) |
| 362 | + } |
| 363 | + |
| 364 | + err = deployClient.Deploy(generatedConfig, mustRedeploy || cmd.flags.deploy) |
| 365 | + if err != nil { |
| 366 | + log.Fatalf("Error deploying %s: %v", *deployConfig.Name, err) |
| 367 | + } |
| 368 | + |
| 369 | + log.StopWait() |
| 370 | + log.Donef("Successfully deployed %s", *deployConfig.Name) |
| 371 | + } |
| 372 | + |
| 373 | + // Save Config |
| 374 | + err = generated.SaveConfig(generatedConfig) |
| 375 | + if err != nil { |
| 376 | + log.Fatalf("Error saving config: %v", err) |
| 377 | + } |
| 378 | + } |
| 379 | +} |
| 380 | + |
390 | 381 | // returns true when one of the images had to be rebuild |
391 | 382 | func (cmd *UpCmd) buildImages(generatedConfig *generated.Config) bool { |
392 | 383 | re := false |
|
0 commit comments