这是indexloc提供的服务,不要输入任何密码
Skip to content

Bug: Skaffold tagger ignores Docker target when calculating image tags #9826

@736-c41-2c1-e464fc974

Description

@736-c41-2c1-e464fc974

Environment

  • Skaffold version: v2.16.0
  • OS: Linux
  • Docker version: Docker version 28.2.2, build e6534b4

Description

Skaffold generates identical image tags for different build profiles when the only difference is the Docker build target. This causes duplicate images to be built and pushed, wasting CI/CD resources and creating ambiguity about which variant is deployed.

Steps to Reproduce

  1. Create a Dockerfile with multiple targets:
    FROM alpine as base
    
    FROM base as dev
    RUN touch devbuild
    
    FROM base as prod
    RUN touch prodbuild
  2. Configure skaffold.yaml with different profiles using different targets:
    apiVersion: skaffold/v4beta11
    kind: Config
    profiles:
      - name: dev
        activation:
          - command: dev
        build:
          tagPolicy:
            inputDigest: {}
          local:
            concurrency: 0
            useBuildkit: true
            tryImportMissing: true
          artifacts:
            - image: out-image
              context: .
              docker:
                dockerfile: Dockerfile
                target: dev
      - name: prod
        activation:
          - command: prod
        build:
          tagPolicy:
            inputDigest: {}
          local:
            concurrency: 0
            useBuildkit: true
            tryImportMissing: true
          artifacts:
            - image: out-image
              context: .
              docker:
                dockerfile: Dockerfile
                target: prod
  3. Run skaffold with different profiles:
    $ skaffold build --profile dev --dry-run
    Generating tags...
     - out-image -> out-image:dd0bcd52c53d80e2a77a84d416883ce1804609153de66be26341326f945233c5
    Skipping build phase since --dry-run=true
    
    $ skaffold build --profile prod --dry-run
    Generating tags...
     - out-image -> out-image:dd0bcd52c53d80e2a77a84d416883ce1804609153de66be26341326f945233c5
    Skipping build phase since --dry-run=true

Expected Behavior

Skaffold should generate different image tags for different profiles when they use different Docker build targets, as they produce functionally different images.

Actual Behavior

Skaffold generates identical image tags for both profiles:

out-image:dd0bcd52c53d80e2a77a84d416883ce1804609153de66be26341326f945233c5

Impact

  • Ambiguity about which image variant (dev or production) is actually deployed
  • Potential for development images to be deployed in production environments
  • CI/CD pipelines build and push redundant images

Possible Solution

Modify the checksum calculation in the Skaffold tagger to include the Docker target as part of the input when generating image tags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions