{"id":20731931,"url":"https://github.com/EthVM/docker-templates","last_synced_at":"2025-05-11T01:31:29.702Z","repository":{"id":64304122,"uuid":"201341006","full_name":"EthVM/docker-templates","owner":"EthVM","description":"render Docker Compose / Stack file templates with the power of go templates","archived":false,"fork":false,"pushed_at":"2022-01-31T22:59:13.000Z","size":219,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-17T05:17:20.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EthVM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-08T21:36:00.000Z","updated_at":"2020-09-01T16:45:19.000Z","dependencies_parsed_at":"2023-01-15T10:15:26.202Z","dependency_job_id":null,"html_url":"https://github.com/EthVM/docker-templates","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthVM%2Fdocker-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthVM%2Fdocker-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthVM%2Fdocker-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthVM%2Fdocker-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EthVM","download_url":"https://codeload.github.com/EthVM/docker-templates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253504526,"owners_count":21918825,"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":[],"created_at":"2024-11-17T05:16:55.713Z","updated_at":"2025-05-11T01:31:29.369Z","avatar_url":"https://github.com/EthVM.png","language":"Go","funding_links":[],"categories":["Docker"],"sub_categories":["Phaser"],"readme":"docker-templates ![version v0.1.0](https://img.shields.io/badge/version-v0.1.0-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)\n================\n\nUtility oriented to render Docker Compose / Stack files with the power of [go templates]() (and heavily inspired by [dockerize](https://github.com/EthVM/docker-templates) and [docker compose templer](https://github.com/Aisbergg/python-docker-compose-templer)).\n\n**Problem**: Docker Compose / Stack files are very static in nature as you only can use YAML to define them. That's a bummer because you can't add conditionals, neither iterations, scoped blocks...The only way to customise the files are [using environment variables substitution](https://docs.docker.com/compose/environment-variables/) the rest is forbidden.\n\n**Solution**: Use `docker-templates`!\n\n## Roadmap\n\nFor now, the initial version is rather limited in scope and features with bugs included! For now it fits properly the bill for the intention we are using it on [EthVM](https://github.com/EthVM/ethvm). But here's a list of next features:\n\n- [ ] Watch for files dynamically and auto-render files.\n- [ ] Add test suite to verify correctness (and also to be a good citizen).\n- [ ] More complex use cases for rendering partial templates inside other templates.\n\n## Installation\n\nDownload the latest version in your container:\n\n* [linux/amd64](https://github.com/EthVM/docker-templates/releases/download/v0.1.0/docker-templates-linux-amd64-v0.1.0.tar.gz)\n* [alpine/amd64](https://github.com/EthVM/docker-templates/releases/download/v0.1.0/docker-templates-alpine-linux-amd64-v0.1.0.tar.gz)\n* [darwin/amd64](https://github.com/EthVM/docker-templates/releases/download/v0.1.0/docker-templates-darwin-amd64-v0.1.0.tar.gz)\n\n### Docker Base Image\n\nThe `ethvm/docker-templates` image is a base image based on `alpine linux`. `docker-templates` is installed in the `$PATH` and can be used directly.\n\n```\nFROM ethvm/docker-templates\n...\nENTRYPOINT docker-templates ...\n```\n\n### Ubuntu Images\n\n``` Dockerfile\nRUN apt-get update \u0026\u0026 apt-get install -y wget\n\nENV DOCKER_TEMPLATES_VERSION v0.1.0\nRUN wget https://github.com/EthVM/docker-templates/releases/download/$DOCKER_TEMPLATES_VERSION/docker-templates-linux-amd64-$DOCKER_TEMPLATES_VERSION.tar.gz \\\n    \u0026\u0026 tar -C /usr/local/bin -xzvf docker-templates-linux-amd64-$DOCKER_TEMPLATES_VERSION.tar.gz \\\n    \u0026\u0026 rm docker-templates-linux-amd64-$DOCKER_TEMPLATES_VERSION.tar.gz\n```\n\n### For Alpine Images:\n\n``` Dockerfile\nRUN apk add --no-cache openssl\n\nENV DOCKER_TEMPLATES_VERSION v0.1.0\nRUN wget https://github.com/EthVM/docker-templates/releases/download/$DOCKER_TEMPLATES_VERSION/docker-templates-alpine-linux-amd64-$DOCKER_TEMPLATES_VERSION.tar.gz \\\n    \u0026\u0026 tar -C /usr/local/bin -xzvf docker-templates-alpine-linux-amd64-$DOCKER_TEMPLATES_VERSION.tar.gz \\\n    \u0026\u0026 rm docker-templates-alpine-linux-amd64-$DOCKER_TEMPLATES_VERSION.tar.gz\n```\n\n## Usage\n\n### Command line arguments\n\n```text\nNAME:\n   docker-templates - render Docker Compose / Stack file templates with the power of go templates\n\nUSAGE:\n   docker-templates [global options] command [command options] [arguments...]\n\nVERSION:\n   0.1.0\n\nCOMMANDS:\n   render   renders the specified definition file(s)\n   help, h  shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --stdout           forces output to be written to stdout\n   --delims value     template tag delimiters. Default \"{{\":\"}}\" (default: \"{{:}}\")\n   --log-level value  log level to emit to the screen (default: 4)\n   --help, -h         show help\n   --version, -v      print the version\n```\n\n### Definition File\n\nThe definition file defines what to do. It lists template and the variables to be used for rendering and says where to put the resulting file. The definition file syntax is as follows:\n\n```toml\n\n# Example definition file\n\n[vars]\n\n    # and/or define them here (higher priority)\n    [vars.global]\n    network_enabled = true\n    network_name = \"net\"\n    network_subnet = \"172.25.0.0/16\"\n\n    # You can include other global variables (lower priority)\n    include = [\n      \"vars/global.toml\"\n    ]\n\n\n[[templates]]\nsrc  = \"templates/stack.yml.tpl\"\ndest = \"out/stack-1.yml\"\ninclude_vars = [ \"vars/local.toml\" ]\n[templates.local_vars]\nmariadb_version = \"10.2.21\"\nmariadb_volume_enabled = true\n\n[[templates]]\nsrc  = \"templates/stack.yml.tpl\"\ndest = \"out/stack-2.yml\"\ninclude_vars = []\n[templates.local_vars]\nmariadb_version = \"11\"\nmariadb_volume_enabled = false\n```\n\nAnd one example of external vars:\n\n```toml\n[vars]\nthis_is_another_var = 'var'\n```\n\nThe different sources of variables are merged together in the following order:\n\n1. global `vars`\n2. global `include`\n3. template `include_vars`\n4. template `vars`\n\n### Templates\n\nTemplates use Golang [text/template](http://golang.org/pkg/text/template/) and the files are rendered with them. Only the definition file and vars files are written in TOML, but the output of the rendered templates can be anything (be YAML or other format). You can access environment variables within a template with `.Env` like `dockerize` or those defined in the definition file with plain `.` (like `.some_global_var`).\n\n```\n{{ .Env.PATH }} is my path\n```\n\nThere are a few built in functions as well (that have been stolen from `dockerize`):\n\n  * `default $var $default` - Returns a default value for one that does not exist. `{{ default .Env.VERSION \"0.1.2\" }}`\n  * `contains $map $key` - Returns true if a string is within another string\n  * `exists $path` - Determines if a file path exists or not. `{{ exists \"/etc/default/myapp\" }}`\n  * `split $string $sep` - Splits a string into an array using a separator string. Alias for [`strings.Split`][go.string.Split]. `{{ split .Env.PATH \":\" }}`\n  * `replace $string $old $new $count` - Replaces all occurrences of a string within another string. Alias for [`strings.Replace`][go.string.Replace]. `{{ replace .Env.PATH \":\" }}`\n  * `parseUrl $url` - Parses a URL into it's [protocol, scheme, host, etc. parts][go.url.URL]. Alias for [`url.Parse`][go.url.Parse]\n  * `atoi $value` - Parses a string $value into an int. `{{ if (gt (atoi .Env.NUM_THREADS) 1) }}`\n  * `add $arg1 $arg` - Performs integer addition. `{{ add (atoi .Env.SHARD_NUM) -1 }}`\n  * `isTrue $value` - Parses a string $value to a boolean value. `{{ if isTrue .Env.ENABLED }}`\n  * `lower $value` - Lowercase a string.\n  * `upper $value` - Uppercase a string.\n  * `jsonQuery $json $query` - Returns the result of a selection query against a json document.\n  * `loop` - Create for loops.\n\n## Differences\n\n`docker-templates` is pretty similar to `python-docker-compose-templer` so why to create another similar program? Mainly for this reasons:\n\n* I wanted to have a simpler binary that I can add easily to my docker files, without having to install Python in them.\n* I like Go :')\n\nAnd what about `dockerize`?\n\n* `dockerize` is meant to be used mainly with `.Env` variables, but whenever you have a more complex use cases, sometimes falls sort.\n\n## Acknowledgements\n\nMany thanks to jwilder and [Aisbergg](https://github.com/Aisbergg) for creating [dockerize](https://github.com/EthVM/docker-templates) and [python-docker-compose-templer](https://github.com/Aisbergg/python-docker-compose-templer) respectively, from which this project draws 99% inspiration!\n\n## License\n\n*docker-templates* is released under the MIT License. See [LICENSE.txt](LICENSE.txt) for more information.\n\n[go.string.Split]: https://golang.org/pkg/strings/#Split\n[go.string.Replace]: https://golang.org/pkg/strings/#Replace\n[go.url.Parse]: https://golang.org/pkg/net/url/#Parse\n[go.url.URL]: https://golang.org/pkg/net/url/#URL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEthVM%2Fdocker-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEthVM%2Fdocker-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEthVM%2Fdocker-templates/lists"}