{ "info": { "author": "Andre Lehmann", "author_email": "aisberg@posteo.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", "Operating System :: POSIX", "Programming Language :: Python :: 3 :: Only", "Topic :: System :: Systems Administration", "Topic :: Utilities" ], "description": "# Docker Compose Templer\n\nThis is a little Python3 utility that adds more dynamism to [Docker Compose or Docker Stack files](https://docs.docker.com/compose/compose-file/) by utilizing the [Jinja2 template engine](http://jinja.pocoo.org/).\n\nDocker Compose (DC) files are quite static in nature. It is possible to use [variable substitution](https://docs.docker.com/compose/compose-file/#variable-substitution) to run slightly different container configurations based on a single DC file. This, however, doesn't allow complex variations in networks, volumes, etc. and proper code reuse. Therefore I decided to create this Python program to introduce Jinja2 templating to DC files. A _definition file_ says where to find the templates, what variables to use and where to put the rendered files.\n\nThe documentation on the Jinja2 syntax can be found [here](http://jinja.pocoo.org/docs/dev/templates/).\n\n**Features:**\n\n* templating using Jinja2\n* using YAML syntax for definition and variable files\n* monitoring of file changes and automatic rendering of templates (especially useful during development)\n* using some [extra Jinja filters](#extra-jinja2-filters) (comply with Ansible filters)\n\n**Table of contents:**\n\n* [Installation](#installation)\n* [Usage](#usage)\n * [Command line arguments](#command-line-arguments)\n * [Definition File](#definition-file)\n * [Templates](#templates)\n * [Examples](#examples)\n* [Extra Jinja2 Filters](#extra-jinja2-filters)\n* [Todo](#todo)\n* [License](#license)\n\n---\n\n## Installation\n\nInstall directly from Github:\n\n```sh\npip install git+https://github.com/Aisbergg/python-docker-compose-templer@v1.1.0\n```\n\nInstall from PyPi:\n\n```sh\npip install docker-compose-templer\n```\n\nIf you like to use the optinal _auto render_ function then you have to install the [Pyinotify](https://github.com/seb-m/pyinotify) package as well:\n\n```sh\npip install pyinotify\n```\n\n## Usage\n\n### Command line arguments\n\n```text\nusage: docker-compose-templer [-a] [-f] [-h] [-v] [--version]\n definition_file [definition_file ...]\n\nRender Docker Compose file templates with the power of Jinja2\n\npositional arguments:\n definition_file File that defines what to do.\n\noptional arguments:\n -a, --auto-render Monitor file changes and render templates automatically\n -f, --force Overwrite existing files\n -h, --help Show this help message and exit\n -v, --verbose Enable verbose mode\n --version Print the program version and quit\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```yaml\n# (optional) define global variables to be used in all templates - can contain Jinja syntax\nvars:\n some_global_var: foo\n another_global_var: \"{{some_global_var}}bar\" # will render to 'foobar'\n\n# (optional) load global variables from YAML file(s) (order matters) - can contain Jinja syntax\ninclude_vars:\n - path/to/file_1.yml\n - path/to/file_2.yml\n\n# template definitions\ntemplates:\n # first template\n - src: templates/my_template.yml.j2 # source file as Jinja2 template (Jinja syntax can be used on path)\n dest: stacks/s1/my_instance.yml # path for resulting file (Jinja syntax can be used on path)\n include_vars: variables/s1.yml # (optional) include local variables from YAML file(s)\n vars: # (optional) local variables for this template\n some_local_var: abc\n\n # second template\n - src: templates/my_template.yml.j2\n dest: stacks/s2/my_instance.yml\n vars:\n some_local_var: xyz\n```\n\nThe variables can itself contain Jinja syntax, you only have to make sure the variables are defined prior usage. The different sources of variables are merged together in the following order:\n\n1. global `include_vars`\n2. global `vars`\n3. template `include_vars`\n4. template `vars`\n\n### Templates\n\nThe templates are rendered with Jinja2 using the global and local variables defined in the definition file. Any Jinja2 specific syntax can be used.\n\nIn addition to the [extra filters](#extra-jinja2-filters) the variable `omit` can be used in the templates. This concept is borrowed from Ansible and the purpose is to omit options from the DC file where a variable is not defined. In the following example the env variable `VAR2` will be omitted from the template if `my_var` was not defined in the definition file:\n\n```yaml\nservices:\n foo:\n environment:\n - \"VAR1=abc\"\n - \"VAR2={{ my_var|default(omit) }}\"\n ...\n```\n\nBecause of the omit functionality the renderer only renders YAML files, generic file types do not work.\n\n### Examples\n\nExamples can be found in the [`examples`](examples) directory. There are three stacks defined, one global stack and two user stacks. The user stacks define a _Nextloud_ and _Redis_ service. Both stacks depend on the global one, meaning those share a global _MariaDB_ and a reverse proxy. To run this example execute the following command inside the `examples/` directory: `docker-compose-templer -f stack-global.yml stack-user1.yml stack-user2.yml`\n\n## Extra Jinja2 Filters\n\nIn addition to the [Jinja built-in filters](http://jinja.pocoo.org/docs/latest/templates/#builtin-filters) the following extra filters are implemented. The filter are based on the filter in Ansible:\n\nFilter | Description\n-------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n`mandatory(msg)` | If the variable is undefined an error with a message `msg` will be thrown.\n`regex_escape()` | Escape special characters to safely use a string in a regex search.\n`regex_findall(pattern, ignorecase=False, multiline=False)` | Find all occurrences of regex matches.\n`regex_replace(pattern, replacement, ignorecase=False, multiline=False)` | Perform a regex search and replace operation.\n`regex_search(pattern, groups, ignorecase=False, multiline=False)` | Search with regex. If one or more match `groups` are specified the search result will be a list containing only those group matches. The groups are specified either by their position (e.g. `\\1`) or by their name (e.g. foo: `\\gfoo`).\n`regex_contains(pattern, ignorecase=False, multiline=False)` | Yields `true` if the string contains the given regex pattern.\n`to_bool(default_value=None)` | Converts a string to a bool value. The `default_value` will be used if the string cannot be converted.\n`to_yaml(indent=2, [...])` | Converts a value to YAML.\n`to_json([...])` | Converts a value to JSON.\n`to_nice_json(indent=2, [...])` | Converts a value to human readable JSON.\n\n## Todo\n\n* Add `pre_render` and `post_render` options\n* Write more tests\n\n## License\n\n_Docker Compose Templer_ is released under the LGPL v3 License. See [LICENSE.txt](LICENSE.txt) for more information.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Aisbergg/python-docker-compose-templer", "keywords": "Jinja2 templating command-line CLI \"Docker-Compose\"", "license": "LGPL", "maintainer": "", "maintainer_email": "", "name": "Docker-Compose-Templer", "package_url": "https://pypi.org/project/Docker-Compose-Templer/", "platform": "POSIX", "project_url": "https://pypi.org/project/Docker-Compose-Templer/", "project_urls": { "Bug Reports": "https://github.com/Aisbergg/python-docker-compose-templer/issues", "Homepage": "https://github.com/Aisbergg/python-docker-compose-templer", "Source": "https://github.com/Aisbergg/python-docker-compose-templer" }, "release_url": "https://pypi.org/project/Docker-Compose-Templer/1.1.0.post2/", "requires_dist": null, "requires_python": "", "summary": "Render Docker Compose file templates with the power of Jinja2", "version": "1.1.0.post2" }, "last_serial": 5108483, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "502aefe8ff93df3ce8e312d1cba0aca7", "sha256": "93a1b4ff363f088f343b3ca325b73bf1ac60894c8427dcc45f1cda86ab7b3fc2" }, "downloads": -1, "filename": "Docker_Compose_Templer-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "502aefe8ff93df3ce8e312d1cba0aca7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14153, "upload_time": "2018-09-21T17:31:36", "url": "https://files.pythonhosted.org/packages/83/8b/9a1637452aec584aed53683b50a0204923eed36041cdd22d3e4cb1265651/Docker_Compose_Templer-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "20b939179cb587dd7a18c8d6790dd14e", "sha256": "e01be1e6feeaa159435fe365e1bb5a463ca39384443630db599f679983c26eed" }, "downloads": -1, "filename": "Docker Compose Templer-1.0.1.tar.gz", "has_sig": false, "md5_digest": "20b939179cb587dd7a18c8d6790dd14e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13562, "upload_time": "2018-09-21T17:31:13", "url": "https://files.pythonhosted.org/packages/95/3d/26eac2507b828ec95c7d8e1cfb8d32940d629aa0b6282b995f677b5a69a5/Docker%20Compose%20Templer-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "7aa878a615afef4289dc8271a5559552", "sha256": "e4a4cba4d8e7a5ad10f2d6d2cea72af36cbe8d5d145fcbdd830810d46af8947d" }, "downloads": -1, "filename": "Docker_Compose_Templer-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7aa878a615afef4289dc8271a5559552", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17178, "upload_time": "2018-11-10T10:45:19", "url": "https://files.pythonhosted.org/packages/13/7d/676f49321ad4eefa8883f001998491fb4d63cf981f3775715b1404299766/Docker_Compose_Templer-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "eb614998faa24de8f946a04abae4188a", "sha256": "ab0087f6dadfb5cfba06d2681acea0e1bf784972168eff5084b6229a83bc2b8d" }, "downloads": -1, "filename": "Docker Compose Templer-1.0.2.tar.gz", "has_sig": false, "md5_digest": "eb614998faa24de8f946a04abae4188a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13739, "upload_time": "2018-11-10T10:45:03", "url": "https://files.pythonhosted.org/packages/ec/e8/c8aed8447e62586ee7231f5a86a9be8c8a71b6d3ddab53065be1dd45b353/Docker%20Compose%20Templer-1.0.2.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "0384b858e686ab6184cf550359c8ba5a", "sha256": "121a6eceffb236e6dd5d45b9f40a3a78fa4d6bd949bd7ba83d5e06cbde1862c2" }, "downloads": -1, "filename": "Docker_Compose_Templer-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0384b858e686ab6184cf550359c8ba5a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21585, "upload_time": "2019-04-06T22:05:51", "url": "https://files.pythonhosted.org/packages/02/f8/68de82618da8d3b39e3d370788e0a30bd6f49905b1b9671b624e33a8c7a7/Docker_Compose_Templer-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0436a69e8b0ddf135122c76e1561e0ad", "sha256": "dee64cc1f1a949d8a70b82543f13fb6bd2c7d0007c2b8e963ebea8ab0d36009a" }, "downloads": -1, "filename": "Docker Compose Templer-1.1.0.tar.gz", "has_sig": false, "md5_digest": "0436a69e8b0ddf135122c76e1561e0ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14646, "upload_time": "2019-04-06T22:05:34", "url": "https://files.pythonhosted.org/packages/9c/c2/196c244ac043043144051a6c95fef047b9a2230a29e54439026c8e870650/Docker%20Compose%20Templer-1.1.0.tar.gz" } ], "1.1.0.post1": [ { "comment_text": "", "digests": { "md5": "0bda5787df3b50633a65b0852dee9038", "sha256": "362e0454fa491c30f29db05b3cbc7573073d8ad05cfa6665fbc9b4d75d29f953" }, "downloads": -1, "filename": "Docker_Compose_Templer-1.1.0.post1-py3-none-any.whl", "has_sig": false, "md5_digest": "0bda5787df3b50633a65b0852dee9038", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21522, "upload_time": "2019-04-06T22:31:39", "url": "https://files.pythonhosted.org/packages/f8/ed/09210a370dacb36996cfcd07a9abd461c535f15bb0720371255d1cb08b84/Docker_Compose_Templer-1.1.0.post1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e24a66799a4e795bdacda5a047afd3dd", "sha256": "53614134cad829cf2977ff6804d94a51f77e66e4ad5c2bfcc67ab570284727c6" }, "downloads": -1, "filename": "Docker Compose Templer-1.1.0.post1.tar.gz", "has_sig": false, "md5_digest": "e24a66799a4e795bdacda5a047afd3dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14497, "upload_time": "2019-04-06T22:31:24", "url": "https://files.pythonhosted.org/packages/45/a6/001ae54b7757eb4bbda69eef83f1d83ac1e313c63e14bb32bab181e671ce/Docker%20Compose%20Templer-1.1.0.post1.tar.gz" } ], "1.1.0.post2": [ { "comment_text": "", "digests": { "md5": "5837afb6dee3086f20c8be4a80558f32", "sha256": "97323eeaee25f557ca4febe806e8f7256a897ac9f2165e9886362283f7875dde" }, "downloads": -1, "filename": "Docker_Compose_Templer-1.1.0.post2-py3-none-any.whl", "has_sig": false, "md5_digest": "5837afb6dee3086f20c8be4a80558f32", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21517, "upload_time": "2019-04-06T22:36:17", "url": "https://files.pythonhosted.org/packages/17/2c/2ce5ba498e69f38a5f5c3eed74c67e4b12fdc8f03cc6c5ed477ff7e9835f/Docker_Compose_Templer-1.1.0.post2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "01a34234fc28b8a33f569edf93d8196e", "sha256": "34f4f0b7ce5ad3367f5ec7d6bed57e0f75bed61fc1cedb1f44742cf7830ba678" }, "downloads": -1, "filename": "Docker Compose Templer-1.1.0.post2.tar.gz", "has_sig": false, "md5_digest": "01a34234fc28b8a33f569edf93d8196e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14496, "upload_time": "2019-04-06T22:36:01", "url": "https://files.pythonhosted.org/packages/49/0b/91835661ced9c45ffc1a5a08935b2e0f8546ab008b0204c5d869fc84bead/Docker%20Compose%20Templer-1.1.0.post2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5837afb6dee3086f20c8be4a80558f32", "sha256": "97323eeaee25f557ca4febe806e8f7256a897ac9f2165e9886362283f7875dde" }, "downloads": -1, "filename": "Docker_Compose_Templer-1.1.0.post2-py3-none-any.whl", "has_sig": false, "md5_digest": "5837afb6dee3086f20c8be4a80558f32", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21517, "upload_time": "2019-04-06T22:36:17", "url": "https://files.pythonhosted.org/packages/17/2c/2ce5ba498e69f38a5f5c3eed74c67e4b12fdc8f03cc6c5ed477ff7e9835f/Docker_Compose_Templer-1.1.0.post2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "01a34234fc28b8a33f569edf93d8196e", "sha256": "34f4f0b7ce5ad3367f5ec7d6bed57e0f75bed61fc1cedb1f44742cf7830ba678" }, "downloads": -1, "filename": "Docker Compose Templer-1.1.0.post2.tar.gz", "has_sig": false, "md5_digest": "01a34234fc28b8a33f569edf93d8196e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14496, "upload_time": "2019-04-06T22:36:01", "url": "https://files.pythonhosted.org/packages/49/0b/91835661ced9c45ffc1a5a08935b2e0f8546ab008b0204c5d869fc84bead/Docker%20Compose%20Templer-1.1.0.post2.tar.gz" } ] }