Skip to content

Commit 3b50e51

Browse files
author
Pamy Carme
authored
Merge pull request #1 from ScienceLogic/feature-add-behavior-to-merge-compose-files
feat: render jinja2 templates and merge docker-compose files
2 parents f36caf1 + 65b6959 commit 3b50e51

30 files changed

Lines changed: 762 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,

.github/workflows/build.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: build
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
test:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
python-version: [3.7, 3.8, 3.9]
15+
os: [ubuntu-18.04]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install dependencies
27+
run: |
28+
pip install -r requirements.txt
29+
pip install -r requirements_dev.txt
30+
- name: Run tests
31+
run: tox
32+
33+
release:
34+
name: Release
35+
runs-on: ubuntu-latest
36+
needs: [ test ]
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v2
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Setup Node.js
44+
uses: actions/setup-node@v2
45+
with:
46+
node-version: '16'
47+
48+
- name: Setup
49+
run: npm install -g semantic-release @semantic-release/github @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/git @semantic-release/release-notes-generator semantic-release-pypi
50+
51+
- name: Set up python
52+
uses: actions/setup-python@v2
53+
with:
54+
python-version: 3.8
55+
56+
- name: Install setuptools
57+
run: python -m pip install --upgrade setuptools wheel twine
58+
59+
- name: Release
60+
env:
61+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
63+
run: npx semantic-release

.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

.releaserc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"branches": "main",
3+
"plugins": [
4+
"@semantic-release/release-notes-generator",
5+
"semantic-release-pypi",
6+
"@semantic-release/github",
7+
[
8+
"@semantic-release/changelog",
9+
{
10+
"changelogFile": "CHANGELOG.md",
11+
"changelogTitle": "# Semantic Versioning Changelog"
12+
}
13+
],
14+
[
15+
"@semantic-release/git",
16+
{
17+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
18+
"assets": ["CHANGELOG.md", "setup.py", "setup.cfg"]
19+
}
20+
]
21+
]
22+
}

CHANGELOG.md

Whitespace-only changes.

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: 30 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, but at the end
13+
it does a final verification to let users know whether this is a valid
14+
docker-compose for deploying a stack or not, as docker-compose doesn't validate that.
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
61-
62-
6364

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

6768
```shell
6869
$ stackconfig --help
@@ -83,22 +84,32 @@ 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()
103105

104106
```
107+
108+
Not Exactly What You Want?
109+
----------------------------
110+
111+
Options that may be a good fit for you:
112+
113+
- https://github.com/sinzlab/jinja-compose
114+
- https://github.com/Aisbergg/python-docker-compose-templer
115+
- https://github.com/docker/compose

0 commit comments

Comments
 (0)