Skip to content

Commit 3a5086d

Browse files
author
Carme, Pamy
committed
feature: add behavior to render jinja2 templates and merge docker-compose files
- be able to render jinja2 templates - merge compose files using docker-compose - validate docker-compose trying to deploy a stack - remove invalid docker-compose stack options Signed-off-by: Carme, Pamy <pamy.carme@sciencelogic.com>
1 parent f36caf1 commit 3a5086d

25 files changed

Lines changed: 601 additions & 19 deletions

.bumpversion.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[bumpversion]
2+
current_version = '0.1.0'
3+
commit = True
4+
tag = True
5+
6+
[bumpversion:file:setup.py]

.flake8

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[flake8]
2+
# Recommend matching the black line length (default 88),
3+
# rather than using the flake8 default of 79:
4+
max-line-length = 88
5+
extend-ignore =
6+
# See https://github.com/PyCQA/pycodestyle/issues/373
7+
E203,

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
*.py[cod]
2+
3+
# C extensions
4+
*.so
5+
6+
# pycharm
7+
.idea/
8+
.idea
9+
10+
# Packages
11+
*.egg
12+
*.egg-info
13+
build
14+
eggs
15+
parts
16+
bin
17+
var
18+
sdist
19+
develop-eggs
20+
.installed.cfg
21+
lib
22+
lib64
23+
24+
# Installer logs
25+
pip-log.txt
26+
27+
# Unit test / coverage reports
28+
.coverage
29+
.tox
30+
nosetests.xml
31+
32+
# Complexity
33+
output/*.html
34+
output/*/index.html
35+
36+
# Sphinx
37+
docs/_build
38+
39+
# Cookiecutter
40+
output/
41+
42+
# venv
43+
env
44+
45+
dist/
46+
build/
47+
cov_report.xml
48+
junit_report.xml

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
default_stages: [commit, push]
2+
fail_fast: true
3+
repos:
4+
- repo: https://github.com/ambv/black
5+
rev: stable
6+
hooks:
7+
- id: black
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v2.1.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v2.1.0
14+
hooks:
15+
- id: flake8
16+
- repo: https://github.com/szebenyib/pre-commit-pytest
17+
rev: master
18+
hooks:
19+
- id: pytest

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 ScienceLogic, Inc
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
4+
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.md
2+
include requirements.txt

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ author: ScienceLogic
77
Overview
88
--------
99

10-
Merge and compile jinja2 template compose files
10+
Render, merge and validate docker_compose files for deploying a stack.
1111

12-
Installation / Usage
13-
--------------------
12+
This library is using docker-compose merging process,
13+
and at the end it does a final verification to let users know whether this is a valid
14+
docker-compose for deploying a stack
15+
16+
Additionally, this library will compile valid yaml jinja2 templates, so they can
17+
be merged along with the other docker-compose files.
18+
19+
Installation
20+
------------
1421

1522
To install use pip:
1623

@@ -54,15 +61,9 @@ git push origin release-n.n.0
5461
or
5562
git push origin hotfix-x.x.n
5663
```
57-
Contributing
58-
------------
59-
60-
TBD
6164

62-
63-
64-
Example
65-
-------
65+
Usage example as cli tool
66+
-------------------------
6667

6768
```shell
6869
$ stackconfig --help
@@ -83,20 +84,21 @@ Options:
8384
```
8485

8586
```
86-
$ stackconfig -f docker-compose.yml -f docker-compose-verrideyml -t docker-compose-valid-template.yml.j2 -d data_file.yml --version 3.8 -o docker-compose.yml
87+
$ stackconfig -f docker-compose.yml -f compose-override.yml -t docker-compose-template.yml.j2 -d data_file.yml --version 3.8 -o docker-compose-final.yml
8788
```
8889

89-
Example using python code
90-
-------------------------
90+
Usage example using Python
91+
--------------------------
9192
```python
92-
from stackconfig.stackconfig import StackConfigCompose, render_jijnja2_compose
93+
from stackconfig.stackconfig import StackConfigCompose
94+
from stackconfig.utils.jinja2_utils import render_jijnja2_compose
9395

9496
jinja_env = {}
9597
yml_compiled_files = render_jijnja2_compose(['/tmp/docker-compose.yml.j2',
96-
'/tmp/docker-compose-override-yml.j2'],
97-
data_file='/tmp/data_file.yml',
98-
data_dict=jinja_env)
99-
# valid docker-compose files can be append, as all of them
98+
'/tmp/docker-compose-override-yml.j2'],
99+
data_file='/tmp/data_file.yml',
100+
data_dict=jinja_env)
101+
# valid docker-compose files can be appended, all of them are going to be merged using the docker-compose library
100102
yml_compiled_files.append("/tmp/docker-copmose-override2.yml")
101103
stack_config = StackConfigCompose(yml_compiled_files, '/tmp/docker-compose-output.yml')
102104
stack_config.merge_stack_compose()

requirements.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Click
2+
docker-compose==1.29.2
3+
pyyaml>=5.4.1
4+
MarkupSafe
5+
jinja2

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Click
2+
docker-compose==1.29.2
3+
pyyaml>=5.4.1
4+
MarkupSafe
5+
jinja2

requirements_dev.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pytest
2+
pytest-cov
3+
tox
4+
black
5+
flake8
6+
bumpversion
7+
pre-commit
8+
sphinx
9+
sphinx_rtd_theme
10+
pip-tools

0 commit comments

Comments
 (0)