Repository navigation
loader: allow custom path - #2378
Conversation
Currently our definition loader always uses the embedded data filesystem exposed by `dataFS()`. It is possible to switch what `dataFS()` returns with an experimental environment flag. We want to make loading of definitions a little bit less experimental by allowing a definition path to be set by calling code; instead of the library reading the environment. A hurdle was that `distro.ParseID` loaded the definitions directly. In this commit I introduce a new `Loader` type that embeds an `fs.FS`, `ParseID` becomes a method on this `Loader`. Where necessary old constructors that do not take a loader will automatically call the new WithLoader variants by passing the `BuiltinLoader` (which gives the same behavior). This will allow us to pass custom paths in `image-builder` and `osbuild-composer` through (for example) a `--force-defs-path` and the potential to start shipping our definitions in a subpackage that installs into `/usr` which would allow for much easier downstream patching *and* other distributions shipping their own custom definition packages. Signed-off-by: Simon de Vlieger <[email protected]>
thozza
left a comment
There was a problem hiding this comment.
Thanks for this kick-off PR.
While the change does what it claims to do, I wonder what is the long term plan here? I think that a fully forced override of distro definitions is a feature that has a use case of its own (i.e. build systems). That said, I still think that the deleted code comment claiming that we want to have search paths is something that we should not just abandon. I think that a hierarchical override, like we allow for repo configs, is a really useful feature. It would allow selectively override just specific distro or image type, while allowing us to keep the fallback to the built-in definitions.
| func ClearLoader(d *DistroYAML) { | ||
| d.loader = nil | ||
| } |
There was a problem hiding this comment.
This could have been simply
func (d *DistroYAML) ClearLoader() {
d.loader = nil
}There was a problem hiding this comment.
Mmm yes, not a big issue; I think I only have a use case for it in the testcases to make it easier to compare the structs and then my brain got tangled up and it ended up like this 🙂
| // XXX: this is a short term measure, pass a set of | ||
| // searchPaths down the stack instead |
There was a problem hiding this comment.
I actually think that this would be a much nicer idea, than a fully forced override.
The long term plan is as of yet to be defined. This change doesn't preclude the potential of having multiple search paths ( I assume in the future we will have |
|
FWIW I like the idea of search paths, but don't like trying to merge things. I think it'll make things overly complex, and make it difficult for users to reason about the results. It's more clear if you just override the defaults with the content of the new path. |
Previously it was possible to pass a custom definition directory through the use of `IMAGE_BUILDER_EXPERIMENTAL` options. In `images` 0.269.0 I landed a PR [1] that allows us setting the definition path in code. This commit implements that, plus test cases, to pass custom definitions. We keep the argument hidden as we still consider it to be experimental until we flesh out certain things but this *will* allow us to source our default image definitions from disk instead of the embedded filesystem in the near future (a follow up) so consider this the lead-up to that. The argument follows the same naming as others, `force` means to entirely wipe and override the built-ins. In the future there will likely be an `extra` equivalent to extend, or override pre-existing definitions in the same way we do for repositories. We might enable this for build systems in their respective plugins at some point as well. [1]: osbuild#2378 Signed-off-by: Simon de Vlieger <[email protected]>
Previously it was possible to pass a custom definition directory through the use of `IMAGE_BUILDER_EXPERIMENTAL` options. In `images` 0.269.0 I landed a PR [1] that allows us setting the definition path in code. This commit implements that, plus test cases, to pass custom definitions. We keep the argument hidden as we still consider it to be experimental until we flesh out certain things but this *will* allow us to source our default image definitions from disk instead of the embedded filesystem in the near future (a follow up) so consider this the lead-up to that. The argument follows the same naming as others, `force` means to entirely wipe and override the built-ins. In the future there will likely be an `extra` equivalent to extend, or override pre-existing definitions in the same way we do for repositories. We might enable this for build systems in their respective plugins at some point as well. [1]: osbuild#2378 Signed-off-by: Simon de Vlieger <[email protected]>
Previously it was possible to pass a custom definition directory through the use of `IMAGE_BUILDER_EXPERIMENTAL` options. In `images` 0.269.0 I landed a PR [1] that allows us setting the definition path in code. This commit implements that, plus test cases, to pass custom definitions. We keep the argument hidden as we still consider it to be experimental until we flesh out certain things but this *will* allow us to source our default image definitions from disk instead of the embedded filesystem in the near future (a follow up) so consider this the lead-up to that. The argument follows the same naming as others, `force` means to entirely wipe and override the built-ins. In the future there will likely be an `extra` equivalent to extend, or override pre-existing definitions in the same way we do for repositories. We might enable this for build systems in their respective plugins at some point as well. [1]: osbuild#2378 Signed-off-by: Simon de Vlieger <[email protected]>
Currently our definition loader always uses the embedded data filesystem exposed by
dataFS(). It is possible to switch whatdataFS()returns with an experimental environment flag.We want to make loading of definitions a little bit less experimental by allowing a definition path to be set by calling code; instead of the library reading the environment.
A hurdle was that
distro.ParseIDloaded the definitions directly.In this commit I introduce a new
Loadertype that embeds anfs.FS,ParseIDbecomes a method on thisLoader. Where necessary old constructors that do not take a loader will automatically call the new WithLoader variants by passing theBuiltinLoader(which gives the same behavior).This will allow us to pass custom paths in
image-builderandosbuild-composerthrough (for example) a--force-defs-pathand the potential to start shipping our definitions in a subpackage that installs into/usrwhich would allow for much easier downstream patching and other distributions shipping their own custom definition packages.