docker / docker/buildx

Invalid bake target syntax still builds

Open
#2,437 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area/bake bake-ga kind/enhancement status/accepted
Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the bake validation path exercised by docker buildx bake foo --print. Reproduce the HCL with targets inside a target and compare it with the valid group syntax; done means the invalid definition is rejected while the group definition prints app and db as its targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
build-system, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.