|
7 | 7 | "strings" |
8 | 8 |
|
9 | 9 | "github.com/loft-sh/devspace/pkg/devspace/build/builder" |
10 | | - "github.com/loft-sh/devspace/pkg/devspace/build/builder/buildkit" |
11 | | - "github.com/loft-sh/devspace/pkg/devspace/build/builder/docker" |
12 | 10 | "github.com/loft-sh/devspace/pkg/devspace/build/registry" |
13 | 11 | "github.com/loft-sh/devspace/pkg/devspace/build/types" |
14 | 12 | "github.com/loft-sh/devspace/pkg/devspace/config/constants" |
@@ -151,38 +149,34 @@ func (c *controller) Build(ctx devspacecontext.Context, images []string, options |
151 | 149 | imageCache.ImageName = imageName |
152 | 150 | imageCache.LocalRegistryImageName = "" |
153 | 151 |
|
154 | | - if registry.UseLocalRegistry(kubeClient, conf, options.SkipPush) && !registry.HasPushPermission(imageConf) { |
155 | | - if SupportsLocalRegistry(builder) { |
156 | | - // Not able to deploy a local registry without a valid kube context |
157 | | - if kubeClient == nil { |
158 | | - return fmt.Errorf("unable to push image %s and a valid kube context is not available", imageConf.Image) |
159 | | - } |
| 152 | + if registry.UseLocalRegistry(kubeClient, conf, imageConf, builder, options.SkipPush) && !registry.HasPushPermission(imageConf) { |
| 153 | + // Not able to deploy a local registry without a valid kube context |
| 154 | + if kubeClient == nil { |
| 155 | + return fmt.Errorf("unable to push image %s and a valid kube context is not available", imageConf.Image) |
| 156 | + } |
160 | 157 |
|
161 | | - registryOptions := registry.NewDefaultOptions(). |
162 | | - WithNamespace(kubeClient.Namespace()). |
163 | | - WithLocalRegistryConfig(conf.LocalRegistry) |
| 158 | + registryOptions := registry.NewDefaultOptions(). |
| 159 | + WithNamespace(kubeClient.Namespace()). |
| 160 | + WithLocalRegistryConfig(conf.LocalRegistry) |
164 | 161 |
|
165 | | - // Create and start a local registry if one isn't already running |
166 | | - localRegistry, err := registry.GetOrCreateLocalRegistry(ctx, registryOptions) |
167 | | - if err != nil { |
168 | | - return errors.Wrap(err, "get or create local registry") |
169 | | - } |
| 162 | + // Create and start a local registry if one isn't already running |
| 163 | + localRegistry, err := registry.GetOrCreateLocalRegistry(ctx, registryOptions) |
| 164 | + if err != nil { |
| 165 | + return errors.Wrap(err, "get or create local registry") |
| 166 | + } |
170 | 167 |
|
171 | | - // Update cache for local registry use |
172 | | - imageCache.LocalRegistryImageName, err = localRegistry.RewriteImage(imageName) |
173 | | - if err != nil { |
174 | | - return errors.Wrap(err, "rewrite image") |
175 | | - } |
176 | | - ctx.Config().LocalCache().SetImageCache(imageConfigName, imageCache) |
| 168 | + // Update cache for local registry use |
| 169 | + imageCache.LocalRegistryImageName, err = localRegistry.RewriteImage(imageName) |
| 170 | + if err != nil { |
| 171 | + return errors.Wrap(err, "rewrite image") |
| 172 | + } |
| 173 | + ctx.Config().LocalCache().SetImageCache(imageConfigName, imageCache) |
177 | 174 |
|
178 | | - // Reset the builder for local registry usage |
179 | | - // TODO: refactor so this isn't necessary! |
180 | | - builder, err = c.createBuilder(ctx, imageConfigName, imageConf, imageTags, options) |
181 | | - if err != nil { |
182 | | - return errors.Wrap(err, "create builder") |
183 | | - } |
184 | | - } else { |
185 | | - ctx.Log().Warnf("unable to push image %s and only docker and buildkit builds support using a local registry", imageConf.Image) |
| 175 | + // Reset the builder for local registry usage |
| 176 | + // TODO: refactor so this isn't necessary! |
| 177 | + builder, err = c.createBuilder(ctx, imageConfigName, imageConf, imageTags, options) |
| 178 | + if err != nil { |
| 179 | + return errors.Wrap(err, "create builder") |
186 | 180 | } |
187 | 181 | } |
188 | 182 |
|
@@ -430,14 +424,3 @@ func (c *controller) waitForBuild(ctx devspacecontext.Context, errChan <-chan er |
430 | 424 |
|
431 | 425 | return nil |
432 | 426 | } |
433 | | - |
434 | | -func SupportsLocalRegistry(builder builder.Interface) bool { |
435 | | - switch builder.(type) { |
436 | | - case *buildkit.Builder: |
437 | | - return true |
438 | | - case *docker.Builder: |
439 | | - return true |
440 | | - default: |
441 | | - return false |
442 | | - } |
443 | | -} |
0 commit comments