Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cdcc6a
commit 33275ff
Showing
12 changed files
with
242 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,5 @@ docs/_build/ | |
|
||
# PyBuilder | ||
target/ | ||
|
||
readme.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include readme.rst | ||
include readme.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
rm -r | ||
rm -r build | ||
rm -r dist | ||
pandoc --from=markdown --to=rst README.md --output=readme.rst | ||
python setup.py bdist_wheel --universal | ||
python setup.py sdist | ||
# twine upload dist/* | ||
# open https://pypi.python.org/pypi/ERAlchemy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from draw_compose import cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import argparse | ||
|
||
template = \ | ||
""" | ||
digraph {{ | ||
graph [rankdir=LR]; | ||
node [label="\N", | ||
shape=box | ||
]; | ||
edge [color=gray50, | ||
arrowhead=normal, | ||
minlen=2, | ||
]; | ||
{nodes} | ||
{links} | ||
}} | ||
""" | ||
|
||
|
||
def format_dest(dest_name): | ||
if ":" in dest_name: | ||
return dest_name.split(":")[0] | ||
return dest_name | ||
|
||
|
||
def iter_links(config_file): | ||
""" | ||
:param config_file: Docker compose config file. | ||
:yields: the tuples (container-source_name (str), link-destination (str)) | ||
""" | ||
for container_name, config in config_file.config.iteritems(): | ||
if 'links' in config.keys(): | ||
for link in config['links']: | ||
yield container_name, link | ||
|
||
|
||
def format_links(config_file): | ||
""" | ||
:param config_file: Docker compose config file. | ||
:return: str, the links formatted in dot format. | ||
example output: | ||
"web" -> "app" | ||
"app" -> "db" | ||
""" | ||
return "\n".join('"{}" -> "{}"'.format(s, format_dest(d)) for s, d in iter_links(config_file)) | ||
|
||
|
||
def format_nodes(config_file): | ||
""" | ||
:param config_file: Docker compose config file. | ||
:return: str, the nodes formatted in dot format. | ||
example output: | ||
"web" | ||
"db" | ||
"app" | ||
""" | ||
return '\n'.join('"{}";'.format(container_name) for container_name in config_file.config.keys()) | ||
|
||
|
||
def format_dot(yml_path): | ||
""" | ||
:param yml_path: str, path of the docker-compose yml to draw. | ||
:return: str, formatted dot template describing the graph. | ||
""" | ||
from compose.config.config import ConfigFile | ||
config_file = ConfigFile.from_filename(yml_path) | ||
return template.format( | ||
nodes=format_nodes(config_file), | ||
links=format_links(config_file) | ||
) | ||
|
||
|
||
def dot_to_graph(dot, output_path): | ||
""" | ||
Render by calling graphviz the figure on the output path. | ||
:param dot: str with the | ||
:param output_path: | ||
:return: | ||
""" | ||
from pygraphviz import AGraph | ||
graph = AGraph().from_string(dot) | ||
graph.draw(path=output_path, prog='dot') | ||
|
||
|
||
def get_parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-i', '--input', help='Path of the docker-compose yml.', default='docker-compose.yml') | ||
parser.add_argument('-o', '--output', help='Path of the result image.') | ||
return parser | ||
|
||
|
||
def cli(): | ||
parser = get_parser() | ||
args = parser.parse_args() | ||
dot = format_dot(args.input) | ||
dot_to_graph(dot, args.output) | ||
|
||
if __name__ == '__main__': | ||
cli() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
db: | ||
image: postgres | ||
env_file: | ||
- .env | ||
rabbit: | ||
image: rabbitmq | ||
env_file: | ||
- .env | ||
app: | ||
image: axabt/afds | ||
command: gunicorn manage:app -b 0.0.0.0:8000 | ||
env_file: | ||
- .env | ||
volumes: | ||
- ./data:/afds/data | ||
links: | ||
- db | ||
- rabbit | ||
worker: | ||
image: axabt/afds | ||
command: su normal_user -c "celery -A web.tasks worker" | ||
env_file: | ||
- .env | ||
links: | ||
- rabbit | ||
- db | ||
web: | ||
image: nginx:latest | ||
volumes: | ||
- ./ops/config.nginx:/etc/nginx/nginx.conf | ||
- ./web/static:/static | ||
ports: | ||
- "80:80" | ||
links: | ||
- app | ||
cron: | ||
image: axabt/afds | ||
command: python manage.py run_cron | ||
links: | ||
- db | ||
env_file: | ||
- .env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
# Draw compose | ||
|
||
Test to see to render compose files. This project needs graphviz installed. | ||
Render compose files with one command line! | ||
|
||
# Simple example | ||
This project needs graphviz installed. | ||
|
||
![Simple example](https://raw.githubusercontent.com/Alexis-benoist/draw-compose/master/simple.png?raw=true "Simple Example") | ||
## Simple example | ||
|
||
![Simple example](https://raw.githubusercontent.com/Alexis-benoist/draw-compose/master/fixtures/simple.png?raw=true "Simple Example") | ||
|
||
## Classic python example | ||
![Python classic](https://raw.githubusercontent.com/Alexis-benoist/draw-compose/master/fixtures/web_app.png?raw=true "Python web app") | ||
|
||
# Install | ||
## On OSX: | ||
Install graphviz `brew install graphviz` and draw-compose: | ||
|
||
$ pip install draw-compose | ||
|
||
# Classic python example | ||
![Python classic](https://raw.githubusercontent.com/Alexis-benoist/draw-compose/master/web_app.png?raw=true "Python web app") | ||
# Use | ||
|
||
$ pip install -r requirements.txt | ||
$ python draw.py | ||
$ open test.pdf # on OSX | ||
Renders by default `docker-compose.yml` in the current folder. | ||
|
||
$ draw-compose -o docker.png | ||
|
||
Or a specific docker file can be rendered: | ||
|
||
$ draw-compose -i -o docker-specific.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from setuptools import setup | ||
|
||
try: | ||
with open('readme.rst') as f: | ||
long_description = f.read() | ||
except IOError: | ||
with open('readme.md') as f: | ||
long_description = f.read() | ||
|
||
setup( | ||
name='draw-compose', | ||
|
||
version='0.0.1', | ||
|
||
description='Render Docker compose files', | ||
long_description=long_description, | ||
|
||
# The project's main homepage.d | ||
url='https://github.com/Alexis-benoist/draw-compose', | ||
|
||
# Author details | ||
author='Alexis Benoist', | ||
author_email='alexis.benoist@gmail.com', | ||
|
||
# Choose your license | ||
license='Apache License 2.0', | ||
|
||
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', | ||
|
||
'Intended Audience :: Developers', | ||
|
||
# that you indicate whether you support Python 2, Python 3 or both. | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
'Topic :: Scientific/Engineering :: Visualization', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
'Topic :: Database', | ||
], | ||
|
||
# What does your project relate to? | ||
keywords='docker diagram render', | ||
|
||
# You can just specify the packages manually here if your project is | ||
# simple. Or you can use find_packages(). | ||
packages=[ | ||
'draw_compose', | ||
], | ||
|
||
# List run-time dependencies here. These will be installed by pip when | ||
# your project is installed. For an analysis of "install_requires" vs pip's | ||
# requirements files see: | ||
# https://packaging.python.org/en/latest/requirements.html | ||
install_requires=[ | ||
'docker-compose', | ||
'pygraphviz' | ||
], | ||
entry_points={ | ||
'console_scripts': [ | ||
'draw-compose=draw_compose:cli', | ||
], | ||
}, | ||
) |
Binary file not shown.
Binary file not shown.