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

Support parsing json config with hcl v2 #280

Merged
merged 4 commits into from
May 8, 2020

Conversation

vanstee
Copy link
Collaborator

@vanstee vanstee commented May 8, 2020

Providing a docker-bake.json to docker buildx bake fails to parse because we were always assuming hcl formatted config after the hcl v2 upgrade.

$ cat <<'EOF' > docker-bake.json
{
  "variable": {
    "TAG": {
      "default": "latest"
    }
  },
  "group": {
    "default": {
      "targets": ["webapp"]
    }
  },
  "target": {
    "webapp": {
      "args": {
        "buildno": "${add(123, 1)}"
      }
    }
  }
}
EOF
$ docker buildx bake -f docker-bake.json --print webapp                                                                   
bake.json:1,1-2: Argument or block definition required; An argument or block definition is required here.  

Fixed this by using the json parser based on the file suffix.

$ docker buildx bake -f docker-bake.json --print webapp                                                                   
{                                                                                                                  
   "target": {                                                                                                     
      "webapp": {                                                                                                  
         "context": ".",                                                                                           
         "dockerfile": "Dockerfile",                                                                               
         "args": {                                                                                                 
            "buildno": "124"                                                                                       
         }                                                                                                         
      }                                                                                                            
   }                                                                                                               
}

Also fixes json keys for groups and targets.

Fixes #278

@vanstee vanstee force-pushed the hcl-json-support branch 2 times, most recently from 0fbf5b6 to e5f353c Compare May 8, 2020 02:31
@tonistiigi tonistiigi added this to the v0.4.2 milestone May 8, 2020
@tonistiigi
Copy link
Member

Maybe just fallback on error instead of checking the suffix?

@tonistiigi
Copy link
Member

@vanstee Also, could you add a test for this?

@vanstee
Copy link
Collaborator Author

vanstee commented May 8, 2020

That could work, but I'm worried we'll be losing out on good error info depending on the default and fallback ordering. For instance, it would be confusing to get errors for parsing an hcl config when you missed a comma in a json config. Let me know what you think; the fallback would be pretty easy to implement.

@tonistiigi
Copy link
Member

@vanstee I guess if the file has json suffix we could just go to json directly. Otherwise, try both and fail with HCL errors. That would be similar to compose detection then https://github.com/docker/buildx/blob/master/bake/bake.go#L54-L70

@vanstee
Copy link
Collaborator Author

vanstee commented May 8, 2020

Nice I like it. Will do.

@vanstee vanstee force-pushed the hcl-json-support branch from a3a0b95 to 355261e Compare May 8, 2020 03:54
@tonistiigi tonistiigi merged commit 42448c5 into docker:master May 8, 2020
@aloysbaillet
Copy link

Hi!
I was updating our CI system to pickup the latest version of buildx but we're still using .json and I have this exact problem. I'm in no rush to upgrade, but I'd like to know if you're planning on a 4.0.2 version release with this fix?
Cheers,
Aloys

@vanstee vanstee deleted the hcl-json-support branch September 14, 2020 14:41
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 this pull request may close these issues.

bake fails to parse JSON Alpine Linux with HCL looking error
3 participants