{"id":15677623,"url":"https://github.com/sgreben/render","last_synced_at":"2025-05-07T01:01:47.911Z","repository":{"id":57498649,"uuid":"110182383","full_name":"sgreben/render","owner":"sgreben","description":"A flexible go-template renderer.","archived":false,"fork":false,"pushed_at":"2022-12-14T16:00:01.000Z","size":2573,"stargazers_count":14,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T04:41:27.280Z","etag":null,"topics":["envsubst","golang","json","renderer","template","yaml"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgreben.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-10T00:35:02.000Z","updated_at":"2024-12-21T13:39:13.000Z","dependencies_parsed_at":"2023-01-29T00:00:24.719Z","dependency_job_id":null,"html_url":"https://github.com/sgreben/render","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Frender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Frender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Frender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgreben%2Frender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgreben","download_url":"https://codeload.github.com/sgreben/render/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252793661,"owners_count":21805057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["envsubst","golang","json","renderer","template","yaml"],"created_at":"2024-10-03T16:10:02.159Z","updated_at":"2025-05-07T01:01:47.767Z","avatar_url":"https://github.com/sgreben.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# render\n\n[![CircleCI](https://circleci.com/gh/sgreben/render.svg?style=svg)](https://circleci.com/gh/sgreben/render) [![Docker Repository on Quay](https://quay.io/repository/sergey_grebenshchikov/render/status \"Docker Repository on Quay\")](https://quay.io/repository/sergey_grebenshchikov/render)\n\nA flexible go-template renderer.\n\n```bash\ndocker pull quay.io/sergey_grebenshchikov/render\n```\n\n```bash\ngo get -u github.com/sgreben/render/cmd/render\n```\n\n- Template definitions can be given as command-line arguments (`-template`, `-t`), or read from files (`-template-file`, `-f`, `-template-files`).\n- Variable definitions can be given as command-line arguments (`-var`), taken from the environment (`-var-env`), or read from JSON / YAML / TOML files (`-var-file`).\n\nThe template syntax is described at \u003chttps://golang.org/pkg/text/template\u003e\n\n## Examples\n\n```bash\n$ render -var foo=bar -t \"value of foo: {{ .foo }}\"\nvalue of foo: bar\n```\n\n```bash\n$ echo \"{{ .SHELL }} {{ .USER }}\" | render -var-env \"\"\n/bin/bash sgreben\n```\n\n```bash\n$ echo \"{{ .env.SHELL }} {{ .env.USER }}\" | render -var-env env=\n/bin/bash sgreben\n```\n\n```bash\n$ render -var-env \"{SHELL,USER}\" -t '{{ . | toYAML }}'\nSHELL: /bin/bash\nUSER: sgreben\n```\n\n```bash\n$ render -var-files-slurp Files=\"*.toml\" -t '{{ keys .Files }}'\n[Gopkg.toml]\n```\n\n```bash\n$ echo '{ \"foo\": { \"bar\": \"baz\" } }' | render -var-file - -t \"value of foo.bar: {{ .foo.bar }}\"\nvalue of foo.bar: baz\n```\n\n```bash\n$ render -t \"{{ __RENDER_ARGS | toJSON }}\"\n[\"render\",\"-t\",\"{{ __RENDER_ARGS | toJSON }}\"]\n```\n\nA longer example demonstrating usage of multiple templates, saving CLI flags as a reusable config, and rendering templates to disk:\n\n```bash\n$ find . -type f\n./components/containers\n./components/volumes\n./templates/pod.yml\n./vars.yml\n\n$ cat templates/pod.yml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: {{ .name }}\nspec:\n  containers: {{ template \"components/containers\" . }}\n  volumes: {{ template \"components/volumes\" . }\n\n$ cat components/containers\n{{- $volumeMounts := .volumes | map \"pick\" \"name\" \"mountPath\" -}}\n{{- .containers | map \"set\" \"volumeMounts\" $volumeMounts | toJSON -}}\n\n$ cat components/volumes\n{{ .volumes | map \"omit\" \"mountPath\" | toJSON }}\n\n$ cat vars.yml\nname: my-pod\ncontainers:\n- name: nginx\n  image: nginx:latest\n- name: busybox\n  image: busybox\nvolumes:\n- name: data\n  mountPath: /data\n  emptyDir: {}\n- name: config\n  mountPath: /config\n  configMap:\n    name: my-configmap\n\n# Generate a config file for render\n$ render -var-file vars.yml -template-files 'components/*' -template-files 'templates/*' -set-template-excludes 'components/*' -o rendered -print-config \u003e config.json\n\n$ cat config.json\n{\n  \"TemplateOutExclude\": \"components/*\",\n  \"TemplateOutPath\": \"rendered\",\n  \"TemplateLeftDelim\": \"{{\",\n  \"TemplateRightDelim\": \"}}\",\n  \"TemplateSources\": [\n    {\n      \"Name\": \"components/*\",\n      \"FromFileGlob\": {\n        \"Glob\": \"components/*\"\n      }\n    },\n    {\n      \"Name\": \"templates/*\",\n      \"FromFileGlob\": {\n        \"Glob\": \"templates/*\"\n      }\n    }\n  ],\n  \"VarsSources\": [\n    {\n      \"FromFile\": {\n        \"Path\": \"vars.yml\"\n      }\n    }\n  ]\n}\n\n# Render the templates using the config file\n$ render -config config.json\n\n$ find . -type f\n./components/containers\n./components/volumes\n./config.json\n./rendered/templates/pod.yml # this is new\n./templates/pod.yml\n./vars.yml\n\n$ cat rendered/templates/pod.yml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: my-pod\nspec:\n  containers: [{\"image\":\"nginx:latest\",\"name\":\"nginx\",\"volumeMounts\":[{\"mountPath\":\"/data\",\"name\":\"data\"},{\"mountPath\":\"/config\",\"name\":\"config\"}]},{\"image\":\"busybox\",\"name\":\"busybox\",\"volumeMounts\":[{\"mountPath\":\"/data\",\"name\":\"data\"},{\"mountPath\":\"/config\",\"name\":\"config\"}]}]\n  volumes: [{\"emptyDir\":{},\"name\":\"data\"},{\"configMap\":{\"name\":\"my-configmap\"},\"name\":\"config\"}]\n```\n\n## Tips\n\n- Variable definitions are applied in the order in which they are given on the command line / in the config file. Later definitions of the same variable override its earlier definitions.\n- Templates are loaded and rendered in the order in which they are given on the command line / in the config file. If templates with the same name are given, later definitions override earlier definitions.\n- If no template input flags are given, `render` defaults to reading a template from `stdin`.\n- If no template output flags are given, `render` defaults to rendering templates to `stdout`.\n\n## Template functions\n\nAdditionally to the functions listed at \u003chttps://golang.org/pkg/text/template/#hdr-Functions\u003e, and the functions provided by the [Sprig library](https://godoc.org/github.com/Masterminds/sprig) (except `env` and `expandenv`), the following functions are defined:\n\n- `toCSV`\n- `fromCSV`\n- `toJSON`\n- `fromJSON`\n- `toYAML`\n- `fromYAML`\n- `toTOML`\n- `fromTOML`\n- `map`\n    ```go-template\n    pipeline | map \"functionName\" arg0 arg1 ...\n    ```\n\n    produces the list\n\n    ```go-template\n    {\n      functionName(pipeline[0], arg0, arg1, ...),\n      functionName(pipeline[1], arg0, arg1, ...),\n      functionName(pipeline[2], arg0, arg1, ...),\n      ...\n    }\n    ```\n- `mapFlip` -- same as `map`, except `pipeline[i]` is provided as the *last* argument to `functionName`, not as the first.\n- `filter`\n    ```go-template\n    pipeline | filter \"functionName\" arg0 arg1 ...\n    ```\n    produces the list of all `pipeline[i]` for which `functionName(pipeline[i], arg0, arg1, ...)` returns `true`\n- `filterFlip` -- same as `filter`, except `pipeline[i]` is provided as the *last* argument to `functionName`, not as the first.\n- `__RENDER_ARGS`\n- `__RENDER_CONFIG`\n\nTo obtain a list of all defined functions, run `render -print-funcs`.\n\n## Build\n\n- Binary\n\n    ```bash\n    dep ensure\n    make bin/render\n    ```\n\n- Docker image\n\n    ```bash\n    make build\n    ```\n\n## Usage\n\n```text\nUsage of render:\n  -config value\n    \tpath to a config file\n  -f value\n    \t(short for -template-file)\n  -o string\n    \t(short for -set-output-dir)\n  -print-config\n    \tprint config to stdout and exit\n  -print-funcs\n    \tprint available functions and their types to stdout and exit\n  -print-templates\n    \tprint rendered templates to stdout\n  -print-vars\n    \tprint variables to stdout and exit\n  -set-config-output-file string\n    \tpath to write the configuration to\n  -set-left-delim string\n    \tleft template delimiter (default \"{{\")\n  -set-output-dir string\n    \tpath to write rendered templates to\n  -set-right-delim string\n    \tright template delimiter (default \"}}\")\n  -set-separator string\n    \tseparator template to print between templates when printing templates to stdout\n  -set-template-excludes string\n    \texclude templates matching the given glob pattern from being output\n  -set-vars-output-file string\n    \tpath to write variable values to\n  -t value\n    \t(short for -template)\n  -template value\n    \tload a template passed as a parameter ([\u003ctemplate-name\u003e=]\u003ctemplate\u003e)\n  -template-file value\n    \tload a template from a file (or stdin, if - is given) ([\u003ctemplate-name\u003e=]\u003cpath\u003e)\n  -template-files value\n    \tload templates from a set of files matching the given pattern (\u003cglob\u003e)\n  -var value\n    \ta single variable definition (\u003cvariable\u003e=\u003cvalue\u003e)\n  -var-env value\n    \tload variables matching the given glob pattern from the environment ([\u003ckey\u003e=]\u003cglob\u003e)\n  -var-file value\n    \tload variable values from a file (or stdin, if - is given) ([\u003ckey\u003e=]\u003cpath\u003e)\n  -var-file-slurp value\n    \tset a single variable to a file's contents (or stdin, if - is given) (\u003cvariable\u003e=\u003cpath\u003e)\n  -var-files-slurp value\n    \tload all files matching the given glob pattern as variables (\u003ckey\u003e=\u003cglob\u003e)\n  -version\n    \tprint version and exit\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgreben%2Frender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgreben%2Frender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgreben%2Frender/lists"}