docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.35k stars 453 forks source link

Invalid bake target syntax still builds #2437

Open crazy-max opened 2 months ago

crazy-max commented 2 months ago

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 commented 1 month ago

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.