Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/jsonnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ instructions on [the releases page](https://github.com/bazelbuild/rules_jsonnet/
<pre>
load("@rules_jsonnet//jsonnet:docs.bzl", "jsonnet_library")

jsonnet_library(<a href="#jsonnet_library-name">name</a>, <a href="#jsonnet_library-deps">deps</a>, <a href="#jsonnet_library-srcs">srcs</a>, <a href="#jsonnet_library-data">data</a>, <a href="#jsonnet_library-imports">imports</a>)
jsonnet_library(<a href="#jsonnet_library-name">name</a>, <a href="#jsonnet_library-deps">deps</a>, <a href="#jsonnet_library-srcs">srcs</a>, <a href="#jsonnet_library-data">data</a>, <a href="#jsonnet_library-ext_code">ext_code</a>, <a href="#jsonnet_library-ext_code_envs">ext_code_envs</a>, <a href="#jsonnet_library-ext_code_files">ext_code_files</a>, <a href="#jsonnet_library-ext_code_libraries">ext_code_libraries</a>,
<a href="#jsonnet_library-ext_str_envs">ext_str_envs</a>, <a href="#jsonnet_library-ext_str_files">ext_str_files</a>, <a href="#jsonnet_library-ext_strs">ext_strs</a>, <a href="#jsonnet_library-imports">imports</a>)
</pre>

Creates a logical set of Jsonnet files.
Expand Down Expand Up @@ -61,6 +62,13 @@ Example:
| <a id="jsonnet_library-deps"></a>deps | List of targets that are required by the `srcs` Jsonnet files. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="jsonnet_library-srcs"></a>srcs | List of `.jsonnet` files that comprises this Jsonnet library | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="jsonnet_library-data"></a>data | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="jsonnet_library-ext_code"></a>ext_code | Include code from the dict value via extvar. Variable name matches the key | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="jsonnet_library-ext_code_envs"></a>ext_code_envs | Include code from an environment variable via extvar. Variable name matches the environment variable name | List of strings | optional | `[]` |
| <a id="jsonnet_library-ext_code_files"></a>ext_code_files | Include code from a file from dict key via extvar. Variable name matches the value | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` |
| <a id="jsonnet_library-ext_code_libraries"></a>ext_code_libraries | Include jsonnet_library as an extvar with the key value | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` |
| <a id="jsonnet_library-ext_str_envs"></a>ext_str_envs | Include string from an environment variable via extvar. Variable name matches the environment variable name | List of strings | optional | `[]` |
| <a id="jsonnet_library-ext_str_files"></a>ext_str_files | Include string from a file from dict key via extvar. Variable name matches the value | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` |
| <a id="jsonnet_library-ext_strs"></a>ext_strs | Include string from the dict value via extvar. Variable name matches the key | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="jsonnet_library-imports"></a>imports | List of import `-J` flags to be passed to the `jsonnet` compiler. | List of strings | optional | `[]` |


Expand Down
49 changes: 46 additions & 3 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,23 @@ jsonnet_to_json_test(
jsonnet_library(
name = "code_library_lib",
srcs = ["code_library.libsonnet"],
deps = [":workflow"]
deps = [":workflow"],
)

jsonnet_to_json_test(
name = "extvar_code_library_test",
size = "small",
src = "extvar_code_library.jsonnet",
ext_code_libraries = { ":code_library_lib": "codefile" },
ext_code_libraries = {":code_library_lib": "codefile"},
golden = "extvar_files_library_golden.json",
)

jsonnet_to_json_test(
name = "tla_code_library_test",
size = "small",
src = "tla_code_library.jsonnet",
tla_code_libraries = { ":code_library_lib": "tla_code" },
golden = "tla_code_library_golden.json",
tla_code_libraries = {":code_library_lib": "tla_code"},
)

jsonnet_to_json_test(
Expand Down Expand Up @@ -336,3 +336,46 @@ jsonnet_to_json(
"multiple_outs_nested_asymmetric/file.json",
],
)

jsonnet_library(
name = "extvar-lib",
srcs = [
"extvar.libsonnet",
],
ext_code_envs = ["MYJSONNET"],
ext_code_libraries = {
":code_library_lib": "ext_lib",
},
ext_str_envs = ["MYTEST"],
ext_str_files = {
":test_str_files": "str_files",
},
ext_strs = {
"non_stamp": "non_stamp",
"mydefine": "$(mydefine)",
"k8s": "{STABLE_K8S_CLUSTER}",
},
)

jsonnet_to_json_test(
name = "extvar-lib-test",
src = "extvar-library.jsonnet",
golden = "extvar-library.json",
deps = [
":extvar-lib",
],
)

jsonnet_to_json(
name = "extvar-lib-json",
src = "extvar-library.jsonnet",
outs = ["ext-lib.json"],
ext_code_envs = ["MYJSONNET"],
ext_str_envs = ["MYTEST"],
ext_strs = {
"non_stamp": "non_stamp",
},
deps = [
":extvar-lib",
],
)
13 changes: 13 additions & 0 deletions examples/extvar-library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"code_env": {
"code": "some code"
},
"library": {
"workflow": { }
},
"k8s": "{STABLE_K8S_CLUSTER}",
"mydefine": "",
"non_stamp": "non_stamp",
"str_env": "test",
"str_files": "this is great\n"
}
1 change: 1 addition & 0 deletions examples/extvar-library.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'extvar.libsonnet'
9 changes: 9 additions & 0 deletions examples/extvar.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
non_stamp: std.extVar('non_stamp'),
mydefine: std.extVar('mydefine'),
k8s: std.extVar('k8s'),
str_files: std.extVar('str_files'),
code_env: std.extVar('MYJSONNET'),
str_env: std.extVar('MYTEST'),
library: std.extVar('ext_lib'),
}
Loading