Open amartani opened 3 months ago
I think there are cases where access to variables and directives would be useful from JSON format. If you want raw strings then these can be escaped with %%
or $$
.
It does look that atm when using --print
with an escaped value we would print the "%{bar}"
directly. That does not look correct as I think the output of --print
should be usable as input. I think we should escape the output of --print
(unless we want to make loading raw json vs JSON-with-templates configurable somehow).
Contributing guidelines
I've found a bug and checked that ...
Description
When using
docker bake
with a JSON docker bake config, strings are being parsed as if they were HCL strings (applying HCL string template interpolation / directives).Expected behaviour
Expected the JSON file to be parsed as a JSON file, such that strings on it are not further processed as HCL templates. In the example below, I expect the image to be build and labeled with the
foo
label getting the literal value%{bar}
.Actual behaviour
On the example below, parsing the docker-bake.json fails, as it tries to parse as HCL template.
Buildx version
github.com/docker/buildx v0.13.0 0de5f1c
Docker info
Builders list
Configuration
docker-bake.json
Build logs
Additional info
We use the json format of
docker bake
as we prefer to programmatically generate JSON instead of manually editing HCL. I expect that this would be the most common case for using JSON.When generating JSON config programmatically, applying HCL string templates is both undesired (we would prefer to do any manipulation on the input before generating the JSON) and also dangerous (it can end up violating validations that we perform before generating the JSON file).
If the current behavior is working as intended, it should at least be documented as such, as the behavior is surprising when programmatically generating raw JSON objects.