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

--skip-build uses cached image tag in generated.yaml #1810

Closed rvignesh89 closed 2 years ago

rvignesh89 commented 2 years ago

What happened? In a project devspace configuration which has an image build section and also a replaceImage config, if we use devspace dev a docker build is performed and the image is tagged with a random value. This value then seems to be stored in .devspace/generated.yaml like below.

# .devspace/generated.yaml
varsEncrypted: true
profiles:
  "":
    images:
      test-project:
        imageName: test-project-image-name
        tag: YZdjOtm
    lastContext:
      namespace: test-project
      context: minikube
# devspace.yaml
version: v1beta10

images:
  test-project:
    image: test-project-image-name
    build:
      custom:
        command: ./docker-build.sh

dev:
  sync:
    - containerName: main
      labelSelector:
        role: app-server
      localSubPath: ./src
      containerPath: /app/src
  replacePods:
  - containerName: main
    labelSelector:
      role: app-server
    replaceImage: test-project-image-name-builder:latest
    patches:
    - op: remove
      path: spec.containers[0].securityContext
    - op: replace
      path: spec.containers[0].args
      value:
        - "sbt"
        - "set reStart / mainClass := Some(\"io.rvignesh.test-project\");~reStart"

The next time if I run devspace dev --skip-build the replaced pod uses the image tag YZdjOtm that was generated from the previous dev run, instead of using the replaceImage configuration in the dev section.

What did you expect to happen instead? If I use devspace dev --skip-build I expect devspace to honor the replaceImage in dev.replacePods section.

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

  1. Create a devspace config with image build section and replaceImage configurations
  2. Run devspace dev which should build a new image and use it in the replaced pod
  3. Reset using devspace reset pods
  4. Run devspace dev --skip-build which should use the configuration in the replaceImage but instead it's using the tag from the previous build.

Local Environment:

Kubernetes Cluster:

Anything else we need to know?

/kind bug

FabianKramm commented 2 years ago

@rvignesh89 thanks for creating this issue! Could you provide a short example devspace.yaml so that we can reproduce this issue?

rvignesh89 commented 2 years ago

Updated the issue description.

FabianKramm commented 2 years ago

@rvignesh89 thanks for the update! This works as intended as devspace always prefers the self-built tags configured in images.*.tags. You can use the following configuration which should work:

version: v1beta10

images:
  test-project:
    image: test-project-image-name
    build:
      custom:
        command: ./docker-build.sh

dev:
  sync:
    - containerName: main
      labelSelector:
        role: app-server
      localSubPath: ./src
      containerPath: /app/src
  replacePods:
  - containerName: main
    labelSelector:
      role: app-server
    replaceImage: image(test-project-image-name):latest
    patches:
    - op: remove
      path: spec.containers[0].securityContext
    - op: replace
      path: spec.containers[0].args
      value:
        - "sbt"
        - "set reStart / mainClass := Some(\"io.rvignesh.test-project\");~reStart"