@@ -8,6 +8,10 @@ import (
88 "strings"
99 "time"
1010
11+ "github.com/covexo/devspace/pkg/util/yamlutil"
12+
13+ "github.com/covexo/devspace/pkg/devspace/builder"
14+
1115 "github.com/docker/docker/api/types"
1216
1317 "github.com/covexo/devspace/pkg/devspace/builder/docker"
@@ -214,12 +218,21 @@ func (cmd *UpCmd) initRegistries() {
214218 }
215219
216220 for registryName , registryConf := range registryMap {
217- log .StartWait ("Creating image pull secret for registry: " + registryName )
218- err := registry .CreatePullSecret (cmd .kubectl , * config .DevSpace .Release .Namespace , registryConf )
219- log .StopWait ()
221+ if registryConf .Auth != nil && registryConf .Auth .Password != nil {
222+ username := ""
223+ password := * registryConf .Auth .Password
224+ email := "noreply@devspace-cloud.com"
220225
221- if err != nil {
222- log .Fatalf ("Failed to create pull secret for registry: %v" , err )
226+ if registryConf .Auth .Username != nil {
227+ username = * registryConf .Auth .Username
228+ }
229+ log .StartWait ("Creating image pull secret for registry: " + registryName )
230+ err := registry .CreatePullSecret (cmd .kubectl , * config .DevSpace .Release .Namespace , * registryConf .URL , username , password , email )
231+ log .StopWait ()
232+
233+ if err != nil {
234+ log .Fatalf ("Failed to create pull secret for registry: %v" , err )
235+ }
223236 }
224237 }
225238}
@@ -285,66 +298,74 @@ func (cmd *UpCmd) buildImages(buildFlagChanged bool) bool {
285298 log .Fatal (registryErr )
286299 }
287300 var buildErr error
301+ var imageBuilder builder.BuilderInterface
288302
289303 buildInfo := "Building image '%s' with engine '%s'"
290304
291- if imageConf .Build .Engine .Kaniko != nil {
292- log .Infof (buildInfo , imageName , "kaniko" )
305+ registryURL := * registryConf .URL
293306
294- imageDestination := registry .GetImageURL (imageConf , false ) + ":" + imageTag
307+ if registryURL == "hub.docker.com" {
308+ registryURL = ""
309+ }
310+ engineName := ""
295311
296- buildErr = kaniko .BuildDockerfile (cmd .kubectl , * config .DevSpace .Release .Namespace , imageDestination , registry .PullSecretName , * registryConf .Insecure )
297- } else {
298- log .Infof (buildInfo , imageName , "docker" )
312+ if imageConf .Build .Engine .Kaniko != nil {
313+ engineName = "kaniko"
314+ buildNamespace := * config .DevSpace .Release .Namespace
315+ allowInsecurePush := false
299316
300- var dockerBuilder * docker.Builder
317+ if imageConf .Build .Engine .Kaniko .Namespace != nil {
318+ buildNamespace = * imageConf .Build .Engine .Kaniko .Namespace
319+ }
301320
321+ if registryConf .Insecure != nil {
322+ allowInsecurePush = * registryConf .Insecure
323+ }
324+ imageBuilder , buildErr = kaniko .NewBuilder (registryURL , * imageConf .Name , imageTag , buildNamespace , cmd .kubectl , allowInsecurePush )
325+ } else {
326+ engineName = "docker"
302327 preferMinikube := true
303328
304329 if imageConf .Build .Engine .Docker .PreferMinikube != nil {
305330 preferMinikube = * imageConf .Build .Engine .Docker .PreferMinikube
306331 }
307- registryURL := * registryConf .URL
332+ imageBuilder , buildErr = docker .NewBuilder (registryURL , * imageConf .Name , imageTag , preferMinikube )
333+ }
334+ log .Infof (buildInfo , imageName , engineName )
335+
336+ if buildErr == nil {
337+ username := ""
338+ password := ""
308339
309- if registryURL == "hub.docker.com" {
310- registryURL = ""
340+ if registryConf .Auth != nil {
341+ if registryConf .Auth .Username != nil {
342+ username = * registryConf .Auth .Username
343+ }
344+
345+ if registryConf .Auth .Password != nil {
346+ password = * registryConf .Auth .Password
347+ }
311348 }
312- dockerBuilder , buildErr = docker .NewBuilder (registryURL , * imageConf .Name , imageTag , preferMinikube )
349+ log .StartWait ("Authenticating (" + * registryConf .URL + ")" )
350+ _ , buildErr = imageBuilder .Authenticate (username , password , len (username ) == 0 )
351+ log .StopWait ()
313352
314353 if buildErr == nil {
315- username := ""
316- password := ""
317-
318- if registryConf .Auth != nil {
319- if registryConf .Auth .Username != nil {
320- username = * registryConf .Auth .Username
321- }
354+ log .Done ("Authentication successful (" + * registryConf .URL + ")" )
355+ buildOptions := & types.ImageBuildOptions {}
322356
323- if registryConf .Auth .Password != nil {
324- password = * registryConf .Auth .Password
357+ if imageConf .Build .Options != nil {
358+ if imageConf .Build .Options .BuildArgs != nil {
359+ buildOptions .BuildArgs = * imageConf .Build .Options .BuildArgs
325360 }
326361 }
327- log .StartWait ("Authenticating (" + * registryConf .URL + ")" )
328- buildErr = dockerBuilder .Authenticate (username , password , len (username ) == 0 )
329- log .StopWait ()
362+ buildErr = imageBuilder .BuildImage (contextPath , dockerfilePath , buildOptions )
330363
331364 if buildErr == nil {
332- log .Done ("Authentication successful (" + * registryConf .URL + ")" )
333- buildOptions := & types.ImageBuildOptions {}
334-
335- if imageConf .Build .Engine .Docker .Options != nil {
336- if imageConf .Build .Engine .Docker .Options .BuildArgs != nil {
337- buildOptions .BuildArgs = * imageConf .Build .Engine .Docker .Options .BuildArgs
338- }
339- }
340- buildErr = dockerBuilder .BuildImage (contextPath , dockerfilePath , buildOptions )
365+ buildErr = imageBuilder .PushImage ()
341366
342367 if buildErr == nil {
343- buildErr = dockerBuilder .PushImage ()
344-
345- if buildErr == nil {
346- log .Info ("Image pushed to registry (" + * registryConf .URL + ")" )
347- }
368+ log .Info ("Image pushed to registry (" + * registryConf .URL + ")" )
348369 }
349370 }
350371 }
@@ -394,6 +415,10 @@ func (cmd *UpCmd) deployChart() {
394415 chartPath := "chart/"
395416
396417 values := map [interface {}]interface {}{}
418+ overwriteValues := map [interface {}]interface {}{}
419+
420+ yamlutil .ReadYamlFromFile (chartPath , values )
421+
397422 containerValues := map [string ]interface {}{}
398423
399424 for imageName , imageConf := range * config .Images {
@@ -406,9 +431,25 @@ func (cmd *UpCmd) deployChart() {
406431 }
407432 containerValues [imageName ] = container
408433 }
409- values ["containers" ] = containerValues
410434
411- appRelease , err := cmd .helm .InstallChartByPath (releaseName , releaseNamespace , chartPath , & values )
435+ pullSecrets := []string {}
436+ existingPullSecrets , pullSecretsExisting := values ["pullSecrets" ]
437+
438+ if pullSecretsExisting {
439+ pullSecrets = existingPullSecrets .([]string )
440+ }
441+
442+ for _ , registryConf := range * config .Registries {
443+ if registryConf .URL != nil {
444+ registrySecretName := registry .GetRegistryAuthSecretName (* registryConf .URL )
445+ pullSecrets = append (pullSecrets , registrySecretName )
446+ }
447+ }
448+
449+ overwriteValues ["containers" ] = containerValues
450+ overwriteValues ["pullSecrets" ] = pullSecrets
451+
452+ appRelease , err := cmd .helm .InstallChartByPath (releaseName , releaseNamespace , chartPath , & overwriteValues )
412453
413454 log .StopWait ()
414455
0 commit comments