@@ -2,6 +2,8 @@ package build
22
33import (
44 "fmt"
5+ dockerclient "github.com/loft-sh/devspace/pkg/devspace/docker"
6+ "github.com/loft-sh/devspace/pkg/devspace/pullsecrets"
57 "strings"
68
79 "github.com/loft-sh/devspace/pkg/devspace/build/builder"
@@ -93,6 +95,30 @@ func (c *controller) Build(ctx devspacecontext.Context, images []string, options
9395 tags := map [string ][]string {}
9496
9597 for imageConfigName , imageConf := range conf .Images {
98+ // create image pull secret if possible
99+ if ctx .KubeClient () != nil && (imageConf .CreatePullSecret == nil || * imageConf .CreatePullSecret ) {
100+ registryURL , err := pullsecrets .GetRegistryFromImageName (imageConf .Image )
101+ if err != nil {
102+ return err
103+ }
104+
105+ dockerClient , err := dockerclient .NewClient (ctx .Context (), ctx .Log ())
106+ if err == nil {
107+ if imageConf .Kaniko != nil && imageConf .Kaniko .Namespace != "" && ctx .KubeClient ().Namespace () != imageConf .Kaniko .Namespace {
108+ err = pullsecrets .NewClient ().EnsurePullSecret (ctx , dockerClient , imageConf .Kaniko .Namespace , registryURL )
109+ if err != nil {
110+ ctx .Log ().Errorf ("error ensuring pull secret for registry %s: %v" , registryURL , err )
111+ }
112+ }
113+
114+ err = pullsecrets .NewClient ().EnsurePullSecret (ctx , dockerClient , ctx .KubeClient ().Namespace (), registryURL )
115+ if err != nil {
116+ ctx .Log ().Errorf ("error ensuring pull secret for registry %s: %v" , registryURL , err )
117+ }
118+ }
119+ }
120+
121+ // get image name and skip if we shouldn't build
96122 imageName := imageConf .Image
97123 if len (images ) > 0 && ! stringutil .Contains (images , imageConfigName ) {
98124 continue
0 commit comments