rules_jsonnet icon indicating copy to clipboard operation
rules_jsonnet copied to clipboard

Document "data" attribute of jsonnet_library rule

Open calder opened this issue 7 years ago • 7 comments
trafficstars

It would be useful for jsonnet_library targets to be able to read data from non-Jsonnet files.

calder avatar Jun 25 '18 23:06 calder

@calder Do you mean via std.extVar or another way?

Globegitter avatar Aug 28 '18 13:08 Globegitter

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,
  },
}

mtsgrd avatar Aug 30 '18 10:08 mtsgrd

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

mtsgrd avatar Aug 30 '18 10:08 mtsgrd

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.

Globegitter avatar Aug 30 '18 10:08 Globegitter

@calder perhaps this issue can be closed?

mtsgrd avatar Sep 13 '18 10:09 mtsgrd

Nice! Still needs documentation in README though.

calder avatar Sep 13 '18 13:09 calder

@calder In that case could you change this issue to something like Document "data" attribute in jsonnet_library rule?

samschlegel avatar Nov 14 '18 20:11 samschlegel