@@ -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"
@@ -92,6 +94,30 @@ func (c *controller) Build(ctx devspacecontext.Context, images []string, options
9294 tags := map [string ][]string {}
9395
9496 for imageConfigName , imageConf := range conf .Images {
97+ // create image pull secret if possible
98+ if ctx .KubeClient () != nil && (imageConf .CreatePullSecret == nil || * imageConf .CreatePullSecret ) {
99+ registryURL , err := pullsecrets .GetRegistryFromImageName (imageConf .Image )
100+ if err != nil {
101+ return err
102+ }
103+
104+ dockerClient , err := dockerclient .NewClient (ctx .Context (), ctx .Log ())
105+ if err == nil {
106+ if imageConf .Kaniko != nil && imageConf .Kaniko .Namespace != "" && ctx .KubeClient ().Namespace () != imageConf .Kaniko .Namespace {
107+ err = pullsecrets .NewClient ().EnsurePullSecret (ctx , dockerClient , imageConf .Kaniko .Namespace , registryURL )
108+ if err != nil {
109+ ctx .Log ().Errorf ("error ensuring pull secret for registry %s: %v" , registryURL , err )
110+ }
111+ }
112+
113+ err = pullsecrets .NewClient ().EnsurePullSecret (ctx , dockerClient , ctx .KubeClient ().Namespace (), registryURL )
114+ if err != nil {
115+ ctx .Log ().Errorf ("error ensuring pull secret for registry %s: %v" , registryURL , err )
116+ }
117+ }
118+ }
119+
120+ // get image name and skip if we shouldn't build
95121 imageName := imageConf .Image
96122 if len (images ) > 0 && ! stringutil .Contains (images , imageConfigName ) {
97123 continue
0 commit comments