Open tnaroska opened 2 years ago
possibly similar to https://github.com/docker/buildx/issues/445
I would be interested by the same functionality
I'd be interested too
I believe this feature is essential for making Bake HCL more readable and maintainable. As you can see here, the lack of this feature makes the configuration file twice as large and requires a lot of duplication. If you also count the duplicated dockerfile
property, the file is three times larger than it would be otherwise.
With the way the HCL code is currently structured, it might not be that hard to add a new current
property or similar that maps to the current block being evaluated (the refactor to allow targets
and groups
fields has done most of the heavily lifting I think).
I think the desired syntax would probably be a new top-level field called current
(targets.current
would be nice, but then what if there's a target
called current
). I'd rather that than target
, since then it would work the same in group
s and any other future block types.
any updates? what's blocking this? what can I do to help push this further? I'm really interested in this, as it can reduce a lot of duplication especially for the cache-to/from and tags fields
@tonistiigi @crazy-max @jedevc @thaJeztah
@colinhemmings
targets.current
to get the current name seems like a fine approach.
We don't have this prioritized atm, but if anyone from the community can make a PR, then let us know.
This may be difficult to do without a substantial change in some of the fields. The main problem is that the HCL expression expansion happens before the inherits attribute is evaluated to merge the contexts.
It might be possible for us to evaluate the inherits earlier and I can look into that. At the same time, the use case seems to relate similarly to the matrix attribute.
Changing the order of expression expansion and inherits would break cases like:
variable "FOO" {
}
target "main" {
inherits = [FOO]
}
or inherits = functioncall()
etc.
I have a bake hcl file defining multiple targets which share some common configuration (e.g. build-args, target platform, secrets, ...). To minimize duplication I have moved these into an abstract
_base
target and use theinherits
attribute to import the shared values into each leaf traget.This works great in general but fails for attributes like
cache-from
,tags
which require their unique values for each lead target as shown in the example below.The ask is to have a special hcl variable or function to reference the current target's name (think of $@ in a makefile). The same file could then be rewritten:
Environment: