buildx icon indicating copy to clipboard operation
buildx copied to clipboard

Invalid bake target syntax still builds

Open crazy-max opened this issue 9 months ago • 2 comments

I made a typo when writing a bake definition that contains an invalid targets field for target:

target "app" {
  dockerfile = "app.Dockerfile"
}

target "db" {
  dockerfile = "db.Dockerfile"
}

target "foo" {
  targets = ["app", "db"]
}

What's wrong is the bake definition still looks valid:

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

foo should be a group here:

target "app" {
  dockerfile = "app.Dockerfile"
}

target "db" {
  dockerfile = "db.Dockerfile"
}

group "foo" {
  targets = ["app", "db"]
}
$ docker buildx bake foo --print
{
  "group": {
    "default": {
      "targets": [
        "foo"
      ]
    },
    "foo": {
      "targets": [
        "app",
        "db"
      ]
    }
  },
  "target": {
    "app": {
      "context": ".",
      "dockerfile": "app.Dockerfile"
    },
    "db": {
      "context": ".",
      "dockerfile": "db.Dockerfile"
    }
  }
}

We should validate this.

crazy-max avatar Apr 29 '24 09:04 crazy-max

I started to work on it by evaluating contexts and adding strict schema validation for group and target block but there might be breaking changes if we introduce such validation. I move this one out of v0.15.0 milestone for now.

crazy-max avatar May 31 '24 15:05 crazy-max

As discussed print a warning in the meantime.

crazy-max avatar Sep 03 '24 16:09 crazy-max

@crazy-max can you create a new issue with a proposal how to address this while working nicely with composable attributes?

thompson-shaun avatar Jan 09 '25 16:01 thompson-shaun