Skip to content

Commit 23e523c

Browse files
committed
Update doku
1 parent 2e2d87b commit 23e523c

2 files changed

Lines changed: 70 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
# Changelog
22
## [Unreleased]
33
### Added
4+
5+
## 1.1.0 - 2019-04-06
6+
### Added
47
- This CHANGELOG file
8+
- Default message for `mandatory` filter
9+
10+
### Changed
11+
- Refactored code
12+
- Renamed executable to `docker-compose-templer`
13+
- Updated examples
14+
15+
### Fixed
16+
- Fixed `to_bool` filter
17+
18+
### Removed
19+
- Explicit start in YAML files
520

621
## 1.0.2 - 2018-11-10
722
### Changed

README.md

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
# Docker Compose Templer
22

3-
This little Python 3 program adds more dynamics to [Docker Compose or Docker Stack files](https://docs.docker.com/compose/compose-file/) by utilizing the [Jinja2 template engine](http://jinja.pocoo.org/).
3+
This 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/).
44

5-
Docker Compose (DC) files allow [variable substitution](https://docs.docker.com/compose/compose-file/#variable-substitution) with environment variables. This functionality offers very simple dynamics that can be used for customizing specific options of the DC file during startup. When a single DC file shall be used to create different service instances with varying environment variables, networks, volumes, etc., the simple method of variable substitution is not convenient. Therefore I decided to create this Python program to introduce templating with Jinja2 to DC files. A definition file says where to find the templates, what variables to use for rendering and where to put the resulting files.
5+
Docker 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.
66

7-
The documentation of Jinja2 can be found [here](http://jinja.pocoo.org/docs/dev/templates/).
7+
The documentation on the Jinja2 syntax can be found [here](http://jinja.pocoo.org/docs/dev/templates/).
88

99
**Features:**
1010

1111
* templating using Jinja2
12-
* using some [extra Jinja filters](#extra-jinja2-filters) (comply with Ansible filters)
13-
* monitoring of file changes and automatic rendering of templates (especially useful during development)
1412
* using YAML syntax for definition and variable files
13+
* monitoring of file changes and automatic rendering of templates (especially useful during development)
14+
* using some [extra Jinja filters](#extra-jinja2-filters) (comply with Ansible filters)
1515

1616
**Table of contents:**
17-
<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:0 orderedList:0 -->
1817

19-
- [Installation](#installation)
20-
- [Usage](#usage)
21-
- [Command line arguments](#command-line-arguments)
22-
- [Definition File](#definition-file)
23-
- [Templates](#templates)
24-
- [Examples](#examples)
25-
- [Extra Jinja2 Filters](#extra-jinja2-filters)
26-
- [License](#license)
27-
28-
<!-- /TOC -->
18+
* [Installation](#installation)
19+
* [Usage](#usage)
20+
* [Command line arguments](#command-line-arguments)
21+
* [Definition File](#definition-file)
22+
* [Templates](#templates)
23+
* [Examples](#examples)
24+
* [Extra Jinja2 Filters](#extra-jinja2-filters)
25+
* [Todo](#todo)
26+
* [License](#license)
2927

3028
---
3129

3230
## Installation
3331

3432
Install directly from Github:
35-
```
36-
pip install git+https://github.com/Aisbergg/python-docker-compose-templer@v1.0.2
33+
34+
```sh
35+
pip install git+https://github.com/Aisbergg/python-docker-compose-templer@v1.1.0
3736
```
3837

3938
Install from PyPi:
40-
```
39+
40+
```sh
4141
pip install docker-compose-templer
4242
```
4343

44+
If 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:
45+
46+
```sh
47+
pip install pyinotify
48+
```
49+
4450
## Usage
51+
4552
### Command line arguments
4653

47-
```
48-
usage: docker_compose_templer [-a] [-f] [-h] [-v] [--version]
54+
```text
55+
usage: docker-compose-templer [-a] [-f] [-h] [-v] [--version]
4956
definition_file [definition_file ...]
5057
5158
Render Docker Compose file templates with the power of Jinja2
@@ -66,24 +73,32 @@ optional arguments:
6673
The 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:
6774

6875
```yaml
69-
# define global variables to be used in all templates - can contain Jinja syntax
76+
# (optional) define global variables to be used in all templates - can contain Jinja syntax
7077
vars:
7178
some_global_var: foo
7279
another_global_var: "{{some_global_var}}bar" # will render to 'foobar'
7380

74-
# load global variables from YAML file(s) (order matters) - can contain Jinja syntax
81+
# (optional) load global variables from YAML file(s) (order matters) - can contain Jinja syntax
7582
include_vars:
7683
- path/to/file_1.yml
7784
- path/to/file_2.yml
7885

86+
# (optional) Command to execute before any template of this definition file is rendered
87+
pre_render: "echo 'Now processing definition file {file}'"
88+
89+
# (optional) Command to execute after all templates were successfully rendered
90+
post_render: "echo 'Successfully processed definition file {file}'"
91+
7992
# template definitions
8093
templates:
8194
# first template
8295
- src: templates/my_template.yml.j2 # source file as Jinja2 template (Jinja syntax can be used on path)
8396
dest: stacks/s1/my_instance.yml # path for resulting file (Jinja syntax can be used on path)
84-
include_vars: variables/s1.yml # include local variables from YAML file(s)
85-
vars: # local variables for this template
97+
include_vars: variables/s1.yml # (optional) include local variables from YAML file(s)
98+
vars: # (optional) local variables for this template
8699
some_local_var: abc
100+
pre_render: "echo 'Now creating {dest} from {src}...'" # (optional) Command to execute before rendering this template
101+
post_render: "echo 'Successfully created {dest} from {src}'" # (optional) Command to execute after rendering this template
87102

88103
# second template
89104
- src: templates/my_template.yml.j2
@@ -118,26 +133,24 @@ Because of the omit functionality the renderer only renders YAML files, generic
118133

119134
### Examples
120135

121-
Examples 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.
136+
Examples 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`
122137

123138
## Extra Jinja2 Filters
124139

125-
In addition to the [Jinja built-in filters](http://jinja.pocoo.org/docs/2.10/templates/#builtin-filters) the following extra filters are implemented. The filter are based on the filter in Ansible:
126-
127-
Filter* | Description
128-
--------|------------
129-
`mandatory(msg)` | If the variable is not defined an error with a message `msg` will be thrown.
130-
`regex_escape` | Escape special characters to safely use a string in a regex search.
131-
`regex_findall(pattern[, ignorecase, multiline])` | Find all occurrences of regex matches.<br>Default values: `ignorecase=False`, `multiline=False`
132-
`regex_replace(pattern, replacement[, ignorecase, multiline])` | Perform a regex search and replace operation.<br>Default values: `ignorecase=False`, `multiline=False`
133-
`regex_search(pattern[, groups, ignorecase, multiline])` | 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`).<br>Default values: `ignorecase=False`, `multiline=False`
134-
`regex_contains(pattern[, ignorecase, multiline])` | Yields `true` if the string contains the given regex pattern.<br>Default values: `ignorecase=False`, `multiline=False`
135-
`to_bool([default_value])` | Converts a string to a bool value. The `default_value` will be used if the string cannot be converted.
136-
`to_yaml([indent, ...])` | Converts a value to YAML.<br>Default values: `indent=2`
137-
`to_json([...])` | Converts a value to JSON.
138-
`to_nice_json([indent])` | Converts a value to human readable JSON.<br>Default values: `indent=4`
139-
140-
> \* Arguments enclosed with brackets are optional
140+
In 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:
141+
142+
Filter | Description
143+
-------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
144+
`mandatory(msg)` | If the variable is undefined an error with a message `msg` will be thrown.
145+
`regex_escape()` | Escape special characters to safely use a string in a regex search.
146+
`regex_findall(pattern, ignorecase=False, multiline=False)` | Find all occurrences of regex matches.
147+
`regex_replace(pattern, replacement, ignorecase=False, multiline=False)` | Perform a regex search and replace operation.
148+
`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`).
149+
`regex_contains(pattern, ignorecase=False, multiline=False)` | Yields `true` if the string contains the given regex pattern.
150+
`to_bool(default_value=None)` | Converts a string to a bool value. The `default_value` will be used if the string cannot be converted.
151+
`to_yaml(indent=2, [...])` | Converts a value to YAML.
152+
`to_json([...])` | Converts a value to JSON.
153+
`to_nice_json(indent=2, [...])` | Converts a value to human readable JSON.
141154

142155
## Todo
143156

0 commit comments

Comments
 (0)