buildx icon indicating copy to clipboard operation
buildx copied to clipboard

bake: load override

Open crazy-max opened this issue 1 year ago • 0 comments

follow-up https://github.com/docker/buildx/pull/2330

The --load case is not properly handled in v0.13 and previous v0.12 as it doesn't append but overrides the outputs:

target "foo" {
  output = [ "type=local,dest=out" ]
}

target "bar" {
}
$ docker buildx bake --load --print foo bar
{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    }
  }
}

With this change it will append only if there is a compatible output already (image, registry) or empty:

{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=local,dest=out"
      ]
    }
  }
}

For example with:

target "foo" {
  output = [ "type=image" ]
}

target "bar" {
}

It would result in:

{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=image"
        "type=docker"
      ]
    }
  }
}

Same has been done for push override so we are consistent. See new tests suite for more info.

crazy-max avatar Mar 13 '24 11:03 crazy-max