Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge targets from multiple JSON files #756

Closed
felipecrs opened this issue Sep 1, 2021 · 3 comments · Fixed by #1025
Closed

Merge targets from multiple JSON files #756

felipecrs opened this issue Sep 1, 2021 · 3 comments · Fixed by #1025

Comments

@felipecrs
Copy link
Contributor

felipecrs commented Sep 1, 2021

The goal:

$ cat <<'EOF' > docker-bake.json
{
    "target": {
        "default": {
            "context": "."
        }
    }
}
EOF

$ cat <<'EOF' > docker-bake.override.json
{
    "target": {
        "default": {
            "tags": [
                "test123"
            ]
        }
    }
}
EOF

$ docker buildx bake -f docker-bake.json -f docker-bake.override.json --print
{
    "target": {
        "default": {
            "context": ".",
            "dockerfile": "Dockerfile",
            "tags": [
                "test123"
            ]
        }
    }
}

But instead, it fails with:

$ docker buildx bake -f docker-bake.json -f docker-bake.override.json --print
docker-bake.override.json:2
--------------------
   1 |     {
   2 | >>>     "target": {
   3 |             "default": {
   4 |                 "tags": [
--------------------
error: docker-bake.override.json:2,5-13: Duplicate argument; Argument "target" was already set at docker-bake.json:2,5-13
@tonistiigi tonistiigi changed the title Merge targets from multiple files Merge targets from multiple JSON files Sep 2, 2021
@tonistiigi
Copy link
Member

Updated title as this should work for hcl/compose already. At least there is tested https://github.com/docker/buildx/blob/master/bake/hcl_test.go#L257

@crazy-max
Copy link
Member

crazy-max commented Sep 2, 2021

@tonistiigi Yes I can confirm:

$ cat <<'EOF' > docker-bake.hcl
target "default" {
  context = "."
}
EOF

$ cat <<'EOF' > docker-bake.override.json
target "default" {
  tags = ["test123"]
}
EOF

$ docker buildx bake -f docker-bake.hcl -f docker-bake.override.hcl --print
{
  "group": {
    "default": [
      "default"
    ]
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "tags": [
        "test123"
      ]
    }
  }
}

@vrslev
Copy link

vrslev commented Nov 9, 2021

@crazy-max This doesn't work with more than two files:

docker buildx bake  -f bake1.json -f bake2.json -f ./docker-bake.hcl  --print
[+] Building 0.0s (0/0)                                                                                                                   
bake2.json:2
--------------------
   1 |     {
   2 | >>>   "target": {
   3 |         "worker": {
   4 |           "tags": ["username/app:pr-80"],
--------------------
error: bake2.json:2,3-11: Duplicate argument; Argument "target" was already set at bake1.json:2,3-11, and 1 other diagnostic(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants