8000 Add variable typing to reference docs by rrjjvv · Pull Request #3189 · docker/buildx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add variable typing to reference docs #3189

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

Merged
merged 1 commit into from
May 21, 2025

Conversation

rrjjvv
Copy link
Contributor
@rrjjvv rrjjvv commented May 19, 2025

This documents the variable typing introduced in #3167.

@crazy-max crazy-max added this to the v0.24.0 milestone May 19, 2025
}
```
```console
$ VALS_JSON=$(jo -a hello with,comma 'with"quote') docker buildx bake
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the canonical form to make it more explicit?

Suggested change
$ VALS_JSON=$(jo -a hello with,comma 'with"quote') docker buildx bake
$ VALS_JSON='["hello","with,comma","withquote"]' docker buildx bake

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if I did something like

$ cat data.json
["hello","with,comma","with\"quote"]
$ VALS_JSON=$(< data.json) docker buildx bake

In the previous section for CSV I had suggested that CSV was (generally) better for interactive use, while JSON better for machine use. And also, that JSON was the answer for unusual data. I know jo may not be as familiar to readers as jq, so not immediately clear what I was trying to convey.

If I have that data coming from a file, that's a little more in the spirit of why this processing mode exists. Whether this file came from an API, generated from another tool, etc. doesn't really matter.

If you still prefer it the way you suggested, that's fine. But usually one wouldn't handcraft JSON like that, which is why I avoided it as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while JSON better for machine use

Oh ok makes sense then we can keep it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still moved to the file approach. It slipped past me when I originally wrote it and when I was sanity checking yesterday, but I think jo can only output objects and arrays; anyone running the other example that you called out would find that it fails...


# These are all equivalent
$ FOO_JSON_JSON='"bar"' docker buildx bake <...>
$ FOO_JSON_JSON=$(jo -a bar) docker buildx bake <...>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
$ FOO_JSON_JSON=$(jo -a bar) docker buildx bake <...>
$ FOO_JSON_JSON='["bar"]' docker buildx bake <...>

@rrjjvv
Copy link
Contributor Author
rrjjvv commented May 20, 2025

Even though this is a reference doc, it seemed like the amount of documentation devoted to it should be proportional to the anticipated frequency of use and its importance to building stuff. That resulted in total omission of some things (like the any type), trying to pack many multiple concepts/illustrations into some examples, and not showing real execution outputs like is done elsewhere. Let me know if that was a bad assumption or if I made the wrong compromises.

Questions/issues that have come up between the initial implementation and these docs:

  1. I don't remember seeing it officially documented, but I stumbled on a feature where --set had the capability to append values (via +=). It would be a logical feature for these new overrides as well. Do you see that as a "wait and see if anybody asks"?
  2. The issue of typed variables with no override and no default values, previously unconsidered but brought up in bake: default variable to null if not defined #2530 (comment). Personally, this feels like a bug (due to oversight). Should the docs call out this (probably) non-intuitive behavior? Should it be 'fixed'? Or left as undefined behavior (probably not a good idea).
  3. That discussion led to whether wondering if null makes sense as an override value. There are neither tests nor docs around whether that's supported or what the behavior is. So very similar questions... should it defined? Explicitly documented? Fixed (if applicable)?

@rrjjvv rrjjvv marked this pull request as ready for review May 20, 2025 04:32
@crazy-max
Copy link
Member
crazy-max commented May 20, 2025

Even though this is a reference doc, it seemed like the amount of documentation devoted to it should be proportional to the anticipated frequency of use and its importance to building stuff. That resulted in total omission of some things (like the any type), trying to pack many multiple concepts/illustrations into some examples, and not showing real execution outputs like is done elsewhere. Let me know if that was a bad assumption or if I made the wrong compromises.

I think current changes you made in reference docs are good. If we want more specific use cases that are out of scope for reference docs, we can define them in https://github.com/docker/docs/blob/main/content/manuals/build/bake/variables.md

1. I don't remember seeing it officially documented, but I stumbled on a feature where --set had the capability to append values (via +=). It would be a logical feature for these new overrides as well. Do you see that as a "wait and see if anybody asks"?

As --set is a bake flag it's defined in the cli reference docs: https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md#set

2. The issue of typed variables with no override and no default values, previously unconsidered but brought up in #2530 (comment). Personally, this feels like a bug (due to oversight). Should the docs call out this (probably) non-intuitive behavior? Should it be 'fixed'? Or left as undefined behavior (probably not a good idea).

3. That discussion led to whether wondering if null makes sense as an override value. There are neither tests nor docs around whether that's supported or what the behavior is. So very similar questions... should it defined? Explicitly documented? Fixed (if applicable)?

Yes agree this feels like a bug. As discussed offline with @tonistiigi, we can have a either a quick patch if possible or just document that default value should be always set when a type is defined if you feel it needs more thoughts.

@rrjjvv
Copy link
Contributor Author
rrjjvv commented May 20, 2025

we can have a either a quick patch if possible

Here's my proposal:

  1. In all cases where typing is specified, default = null, and no override is provided, the value is null. This is mostly current behavior, with one exception.
  2. In all cases where typing is specified, and neither a default nor override is provided, the value is null. Using a zero-value might be more intuitive and convenient, but null is probably more correct and is a simple implementation. I'm fine either way, but this is what I currently have.
  3. Leave the behavior of the any type as undefined, or even disallowed.

The current exception for (1) is the any type. Currently, type = any; default = null yields an empty string. That's because the type of something that was not defined is exactly the same as one defined as any, but the compatibility issue makes "not defined" return the empty string. I've added that distinction, which allows (1) to be strengthened. Might be clearer with this snippet:

// before
typeSpecified = !varType.Equals(cty.DynamicPseudoType)
// after
typeSpecified = !varType.Equals(cty.DynamicPseudoType) || hcl.ExprAsKeyword(vr.Type) == "any"

That change broke existing tests asserting the 'missing'/'any' equivalence. That's why it might make sense to simply ignore any (as I did in the docs), or actively disallow it (until there are use-cases to help guide how it should behave). While I can see value in using any to type function arguments, it's hard to imagine being used for standard variables.

Based on previous comments, I'm guessing you'll be good with (1) and (3), and at least not disagree with (2), so I'll proactively proceed to create a separate PR (but obviously let me know if you disagree or have other proposals).

I'll sidestep the "null as an override" question for the time being; if it even makes sense, and if it doesn't behave as expected, I'd think that would be a simple bug/request; the issue around (2) is much bigger than that.

I created #3198 for this.

This documents the variable typing introduced in docker#3167.

Signed-off-by: Roberto Villarreal <rrjjvv@yahoo.com>
@rrjjvv rrjjvv force-pushed the var-typing-docs branch from 5d82023 to cfeca91 Compare May 20, 2025 19:49
@crazy-max crazy-max merged commit dfad6e0 into docker:master May 21, 2025
40 checks passed
@rrjjvv rrjjvv deleted the var-typing-docs branch May 21, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0