rules_jsonnet
rules_jsonnet copied to clipboard
Document "data" attribute of jsonnet_library rule
It would be useful for jsonnet_library targets to be able to read data from non-Jsonnet files.
@calder Do you mean via std.extVar or another way?
In the Jsonnet tutorial here it says that importstr is for verbatim UTF-8 text. When constructing e.g. a ConfigMap it is often useful to import arbitrary file types, such as .toml, .yaml, .txt and so on.
One place that comes to mind is my configuration of Traefik, where I have a configuration file traefik.toml. Currently, if I want this in a separate file rather than in-line, I have to incorrectly change the extension to .jsonnet.
local config = importstr "traefik-config.jsonnet"; // Should be traefik-config.toml
{
apiVersion: "v1",
kind: "ConfigMap",
metadata: {
name: "traefik-config",
labels: {
app: "traefik",
},
},
data: {
"traefik.toml": config,
},
}
Although, I'm not sure why I didn't realize this has been supported since Nov 2016.. https://github.com/bazelbuild/rules_jsonnet/commit/4ef65ef89335fca9d105515053af083f8bd54965
Ahh cool, I was not even aware of that, we have been using std.extVar and ext-str-file to get to exactly the same result. But the importstr does seem a little bit nicer.
@calder perhaps this issue can be closed?
Nice! Still needs documentation in README though.
@calder In that case could you change this issue to something like Document "data" attribute in jsonnet_library rule?