-
My company uses configuration from properties files, for Java applications/services, that goes something like this: Read default values from Get a system property "profile". It contains a main profile name, followed by optional modifier names. Read values from exactly one main profile file, specified by the name above. For example, Read values from any modifier files specified. For example, Finally, read values from The files read later overwrite properties defined by earlier files. How could I structure something like this in Pkl? I currently have a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
One way to do this is to structure everything in as a mixin. A mixin is a way to have a multiple inheritance model in Pkl. Here's a gist to demonstrate this: https://gist.github.com/bioball/8fcc848cffdf11fcbce68e420647aa1e. This example uses external properties to control what profiles and modifiers to include. Use
This example will also import On the Java side, you can similarly set external properties when building your evaluator. public AppConfig loadAppConfig() {
try (var evaluator = ConfigEvaluatorBuilder.preconfigured().addExternalProperty("profile", "dev").build()) {
return evaluator.evaluate(ModuleSource.modulePath("/path/to/AppConfig.pkl")).as(AppConfig.class);
}
} Note: this is just one of the many valid options for managing complexity in configuration. Another option is via the single-inheritance "app/env/cluster" model. Under this model, you would define different folder nesting levels, where each nesting level represents one type of concern. For a demonstration of the single-inheritance model, take a look at our advanced kubernetes example. |
Beta Was this translation helpful? Give feedback.
One way to do this is to structure everything in as a mixin. A mixin is a way to have a multiple inheritance model in Pkl.
Here's a gist to demonstrate this: https://gist.github.com/bioball/8fcc848cffdf11fcbce68e420647aa1e. This example uses external properties to control what profiles and modifiers to include.
Use
pkl eval AppConfig.pkl
to get rendered results. Use external properties to determine what to include. For example:This example will also import
../local/config.pkl
, but only if that file exists.On the Java side, you can similarly set external properties when building your evaluator.