devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.37k stars 361 forks source link

Local Registry: Always rebuilding images #2442

Closed timo-klarshift closed 1 year ago

timo-klarshift commented 1 year ago

What happened?

Rebuild image localhost:30089/username/app because it was not found in the local registry

What did you expect to happen instead?

Images only rebuild when there is an actual change which would create a new image

How can we reproduce the bug? (as minimally and precisely as possible)

version: v2beta1
name: devspace-issue-xyz
images:
  app:
    image: username/app
    dockerfile: ./Dockerfile

deployments:
  app:
    helm:
      chart:
        name: component-chart
        repo: https://charts.devspace.sh
      values:
        containers:
          - image: username/app
        service:
          ports:
            - port: 5999

Then do devspace dev or devspace deploy

You see that the image is rebuild every time.

The same happens if you choose buildKit: {}

Local Environment:

clientVersion:
  buildDate: "2022-11-10T22:18:49Z"
  compiler: gc
  gitCommit: 872a965c6c6526caa949f0c6ac028ef7aff3fb78
  gitTreeState: archive
  gitVersion: v1.25.4
  goVersion: go1.19.3
  major: "1"
  minor: "25"
  platform: linux/amd64
kustomizeVersion: v4.5.7
serverVersion:
  buildDate: "2022-11-18T18:17:40Z"
  compiler: gc
  gitCommit: 0dc63334c0db3e7b99244427615e091909fc486e
  gitTreeState: clean
  gitVersion: v1.25.4+k3s1
  goVersion: go1.19.3
  major: "1"
  minor: "25"
  platform: linux/amd64

Anything else we need to know?

I will provide a fix :)

timo-klarshift commented 1 year ago

It looks like the following would fix it

diff --git a/pkg/devspace/build/builder/buildkit/buildkit.go b/pkg/devspace/build/builder/buildkit/buildkit.go
index b87d0b8f0..d5e12acf0 100644
--- a/pkg/devspace/build/builder/buildkit/buildkit.go
+++ b/pkg/devspace/build/builder/buildkit/buildkit.go
@@ -68,7 +68,7 @@ func (b *Builder) Build(ctx devspacecontext.Context) error {
 func (b *Builder) ShouldRebuild(ctx devspacecontext.Context, forceRebuild bool) (bool, error) {
        // Check if image is present in local registry
        imageCache, _ := ctx.Config().LocalCache().GetImageCache(b.helper.ImageConfigName)
-       imageName := imageCache.ResolveImage()
+       imageName := imageCache.ResolveImage() + ":" + imageCache.Tag

        if imageCache.IsLocalRegistryImage() {
                found, err := registry.IsImageAvailableRemotely(ctx.Context(), imageName)
diff --git a/pkg/devspace/build/builder/docker/docker.go b/pkg/devspace/build/builder/docker/docker.go
index 0da1f3237..173b42698 100644
--- a/pkg/devspace/build/builder/docker/docker.go
+++ b/pkg/devspace/build/builder/docker/docker.go
@@ -75,7 +75,7 @@ func (b *Builder) Build(ctx devspacecontext.Context) error {
 func (b *Builder) ShouldRebuild(ctx devspacecontext.Context, forceRebuild bool) (bool, error) {
        // Check if image is present in local registry
        imageCache, _ := ctx.Config().LocalCache().GetImageCache(b.helper.ImageConfigName)
-       imageName := imageCache.ResolveImage()
+       imageName := imageCache.ResolveImage() + ":" + imageCache.Tag

        if imageCache.IsLocalRegistryImage() {
                found, err := registry.IsImageAvailableRemotely(ctx.Context(), imageName)
lizardruss commented 1 year ago

@timo-klarshift Thanks! Good catch. I'll create a PR for this momentarily unless you would like to.

timo-klarshift commented 1 year ago

@lizardruss So we had some little overlap here. I provided a Pull Request. Not sure if its too late for mine

lizardruss commented 1 year ago

@timo-klarshift Not at all. I'll close mine.

ADustyOldMuffin commented 1 year ago

This still is not fixed, I cannot get Devspace to not attempt to push to the local registry without the variable set in each devspace.yaml file. Even with this flag it will still attempt to push to localhost and fail on some images.