Skip to content

bake: Resource interpolation doesn't get attributes merged #2173

@xietianxi

Description

@xietianxi

Contributing guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

HCL resource interpolation gets attributes overridden by the last configuration, instead of the merged actual value.

Expected behaviour

Resource interpolation get all labels of target "test".

{
  "group": {
    "default": {
      "targets": [
        "test"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "labels": {
        "bar": "baz",
        "foo": "bar"
      }
    },
    "test": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "labels": {
        "bar": "baz",
        "foo": "bar"
      }
    }
  }
}

Actual behaviour

Resource interpolation only get labels in docker-bake.override.hcl.

{
  "group": {
    "default": {
      "targets": [
        "test"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "labels": {
        "bar": "baz"
      }
    },
    "test": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "labels": {
        "bar": "baz",
        "foo": "bar"
      }
    }
  }
}

Buildx version

github.com/docker/buildx v0.12.0-desktop.2 c5a13b51c1ae9358eb691e9a21c955590e26d0a0

Docker info

No response

Builders list

NAME/NODE     DRIVER/ENDPOINT STATUS  BUILDKIT             PLATFORMS
default *     docker                                       
  default     default         running v0.11.7+d3e6c1360f6e linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
desktop-linux                 error                        

Cannot load builder desktop-linux: protocol not available

Configuration

docker buildx bake --print default test

# docker-bake.hcl
target "default" {
    labels = target.test.labels

}

target "test" {
    labels = {
        "foo": "bar"
    }
}
# docker-bake.override.hcl
target "test" {
    labels = {
        "bar": "baz"
    }
}

Build logs

No response

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions