Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ docs/_build/
target/

.test

.spyderproject
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ optional arguments:
- To access environment variables use `{{'default'| env('VARIABLE_NAME')}}`
where `VARIABLE_NAME` is the name of your environment variable and `default`
is the default value you want it to be if the environment variable is not set.


## Sample
```
python meta-compose.py -d samples/data/testdata -t samples/template/meta-compose.yml -o samples/output/docker-compose.yml

python meta-compose.py -t samples/template/gateway.tmpl -d samples/data/gateway.json -o samples/output/gateway.properties

python meta-compose.py -t samples/template/app.tmpl -d samples/data/app.json -o samples/output/app.js

```
3 changes: 0 additions & 3 deletions meta-compose

This file was deleted.

3 changes: 3 additions & 0 deletions meta-compose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
from metacompose.cli import main
main()
2 changes: 1 addition & 1 deletion metacompose/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.4'
__version__ = '0.1.5'
1 change: 1 addition & 0 deletions metacompose/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from main import main
13 changes: 12 additions & 1 deletion metacompose/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import yaml
from jinja2 import Environment, FileSystemLoader, StrictUndefined
import argparse
from pprint import pprint

def env_override(value, key):
print "%s: %s" % ("debug",os.getenv(key, value))
#pprint (vars(env_override()))
return os.getenv(key, value)


def fileglob(pathname):
print "%s: %s" % ("debug",glob.glob(pathname))
#pprint (vars(env_override))
return glob.glob(pathname)


Expand Down Expand Up @@ -42,6 +47,7 @@ def setup_jinja(template_file_name):
jinja = Environment(loader=FileSystemLoader("."), undefined=StrictUndefined)
jinja.filters['env'] = env_override
jinja.filters['fileglob'] = fileglob

return jinja.get_template(template_file_name)

def collect_data(data_file_names):
Expand All @@ -54,18 +60,23 @@ def collect_data(data_file_names):
return data

def write_compose_file(composition, outputfile):

print "..."
with open(outputfile, "w") as fh:
fh.write(composition)
print "compose file generated"



def main():

args = parse_args()
print "args: "
print args


template = setup_jinja(args.template)
data = collect_data(["meta-compose-data.yml"] + args.datafile)
print "data: "
print data

write_compose_file(template.render(data), args.outputfile)
6 changes: 6 additions & 0 deletions samples/data/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"app": a,
"nat1": b1,
"nat2": b2,
"rt": c
}
12 changes: 12 additions & 0 deletions samples/data/gateway.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ "gateway":
{"debug": "false","host": "gw.cp.wmcloud-docker.com","port": 8081,"db": {"host": "10.21.234.42","port": "6379","database": 0,"password": "","statistic": {"host": "10.21.234.42","port": 6379,"database": 3,"password": ""
},"maxTotal": 10,"maxIdle": 10
},"statsd": {"host": "127.0.0.1","port": 8125
},"idp": {"url": "http://app.cp.wmcloud-docker.com/login.html" },"connection": {"pool": 100 },"route": {"pool": 30 },"timeout": 90,"resource": {"base": "/errorpage" },"thread": {"pool": 4096 },"phantomScript": {"path": "/opt/seo.js" },"authorization": {"endpoint": "http://10.20.131.232:9764/authorizationService/authorize" },"cloud": {"domain": ".wmcloud-docker.com" },"mq": {"host": "10.21.234.43","vhost": "/gateway","port": 5672,"username": "gateway","password": "gateway_pass"
},"cors": {"hosts": "app.cp.wmcloud-docker.com,127.0.0.1,localhost,10.21.234.41" },"api": {"authurl": "http://127.0.0.1:8080/authority" },"health": {"check": {"port": 8081,"rate": 300000,"redis": {"host": "10.21.234.42","port": 6379,"db": 5,"password": ""
},"cluster": "gateway","nodeid": 1,"window": 320000
},"status": {"green": 20,"yellow": 40
}
},"aop": {"timer": { "on": "false" } }
}
}
30 changes: 30 additions & 0 deletions samples/data/testdata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
hello : {
world : "Hello World" ,
'on': false
},
seq: [1,2,3,4,5,6],

linksList: {
"Google":{
"Web":"www.web.de",
"Apps":{
"Drive": "DriveLink",
"Dropbox": "DropboxLink"
},
"Google Main":"http://mail.google.com",
"G+":"http://plus.google.com"
},
"Social":{
"Facebook":"http://www.facebook.de",
"G+":"https://plus.google.com",
"Xing":"http://www.xing.de",
"LinkedIn":"http://www.linkedin.com",
"Tumblr":"http://www.tumblr.com"
},
"Fun":{
"Reddit":"http://www.reddit.com"
}
}

}
7 changes: 7 additions & 0 deletions samples/output/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
a: {
"nat1": b1,
"nat2": b2,
"rt": c
}
}
86 changes: 86 additions & 0 deletions samples/output/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
build:
args:
buildno: 1
user: Hello World
check: False
javaHome: C:\Program Files\Java\jdk1.8.0_65

build:
args:
- buildno=1
- user=Hello World
- javaHome=C:\Program Files\Java\jdk1.8.0_65build:
args:
buildno: 2
user: Hello World
check: False
javaHome: C:\Program Files\Java\jdk1.8.0_65

build:
args:
- buildno=2
- user=Hello World
- javaHome=C:\Program Files\Java\jdk1.8.0_65build:
args:
buildno: 3
user: Hello World
check: False
javaHome: C:\Program Files\Java\jdk1.8.0_65

build:
args:
- buildno=3
- user=Hello World
- javaHome=C:\Program Files\Java\jdk1.8.0_65build:
args:
buildno: 4
user: Hello World
check: False
javaHome: C:\Program Files\Java\jdk1.8.0_65

build:
args:
- buildno=4
- user=Hello World
- javaHome=C:\Program Files\Java\jdk1.8.0_65build:
args:
buildno: 5
user: Hello World
check: False
javaHome: C:\Program Files\Java\jdk1.8.0_65

build:
args:
- buildno=5
- user=Hello World
- javaHome=C:\Program Files\Java\jdk1.8.0_65build:
args:
buildno: 6
user: Hello World
check: False
javaHome: C:\Program Files\Java\jdk1.8.0_65

build:
args:
- buildno=6
- user=Hello World
- javaHome=C:\Program Files\Java\jdk1.8.0_65

<start>

1>Fun :
2>- Reddit : "http://www.reddit.com"
1>Google :
2>- Web : "www.web.de"
2>- Google Main : "http://mail.google.com"
2>Apps :
3>- Dropbox : "DropboxLink"
3>- Drive : "DriveLink"
2>- G+ : "http://plus.google.com"
1>Social :
2>- Tumblr : "http://www.tumblr.com"
2>- Facebook : "http://www.facebook.de"
2>- G+ : "https://plus.google.com"
2>- Xing : "http://www.xing.de"
2>- LinkedIn : "http://www.linkedin.com"
</end>
44 changes: 44 additions & 0 deletions samples/output/gateway.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
gateway.debug=false
gateway.host=gw.cp.wmcloud-docker.com
gateway.port=8081
gateway.db.host=10.21.234.42
gateway.db.port=6379
gateway.db.database=0
gateway.db.password=
gateway.db.statistic.host=10.21.234.42
gateway.db.statistic.port=6379
gateway.db.statistic.database=3
gateway.db.statistic.password=
gateway.db.maxTotal=10
gateway.db.maxIdle=10
gateway.db.maxWait=10000
gateway.statsd.host=127.0.0.1
gateway.statsd.port=8125
gateway.idp.url=http://app.cp.wmcloud-docker.com/login.html
gateway.connection.pool=100
gateway.route.pool=30
gateway.timeout=90
gateway.resource.base=/errorpage
gateway.thread.pool=4096
gateway.phantomScript.path=/opt/seo.js
gateway.authorization.endpoint=http://10.20.131.232:9764/authorizationService/authorize
gateway.cloud.domain=.wmcloud-docker.com
gateway.mq.host=10.21.234.43
gateway.mq.vhost=/gateway
gateway.mq.port=5672
gateway.mq.username=gateway
gateway.mq.password=gateway_pass
gateway.cors.hosts=app.cp.wmcloud-docker.com,127.0.0.1,localhost,10.21.234.41
gateway.api.authurl=http://127.0.0.1:8080/authority
gateway.health.check.port=8081
gateway.health.check.rate=300000
gateway.health.check.redis.host=10.21.234.42
gateway.health.check.redis.port=6379
gateway.health.check.redis.db=5
gateway.health.check.redis.password=
gateway.health.check.cluster=gateway
gateway.health.check.nodeid=1
gateway.health.check.window=320000
gateway.aop.timer.on=false
gateway.health.status.green=20
gateway.health.status.yellow=40
7 changes: 7 additions & 0 deletions samples/template/app.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
{{ app }}: {
"nat1": {{ nat1 }},
"nat2": {{ nat2 }},
"rt": {{ rt }}
}
}
44 changes: 44 additions & 0 deletions samples/template/gateway.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
gateway.debug={{gateway.debug}}
gateway.host={{gateway.host}}
gateway.port={{gateway.port}}
gateway.db.host={{gateway.db.host}}
gateway.db.port={{gateway.db.port}}
gateway.db.database={{gateway.db.database}}
gateway.db.password={{gateway.db.password}}
gateway.db.statistic.host={{gateway.db.statistic.host}}
gateway.db.statistic.port={{gateway.db.statistic.port}}
gateway.db.statistic.database={{gateway.db.statistic.database}}
gateway.db.statistic.password={{gateway.db.statistic.password}}
gateway.db.maxTotal={{gateway.db.maxTotal}}
gateway.db.maxIdle={{gateway.db.maxIdle}}
gateway.db.maxWait=10000
gateway.statsd.host={{gateway.statsd.host}}
gateway.statsd.port={{gateway.statsd.port}}
gateway.idp.url={{gateway.idp.url}}
gateway.connection.pool={{gateway.connection.pool}}
gateway.route.pool={{gateway.route.pool}}
gateway.timeout={{gateway.timeout}}
gateway.resource.base={{gateway.resource.base}}
gateway.thread.pool={{gateway.thread.pool}}
gateway.phantomScript.path={{gateway.phantomScript.path}}
gateway.authorization.endpoint={{gateway.authorization.endpoint}}
gateway.cloud.domain={{gateway.cloud.domain}}
gateway.mq.host={{gateway.mq.host}}
gateway.mq.vhost={{gateway.mq.vhost}}
gateway.mq.port={{gateway.mq.port}}
gateway.mq.username={{gateway.mq.username}}
gateway.mq.password={{gateway.mq.password}}
gateway.cors.hosts={{gateway.cors.hosts}}
gateway.api.authurl={{gateway.api.authurl}}
gateway.health.check.port={{gateway.health.check.port}}
gateway.health.check.rate={{gateway.health.check.rate}}
gateway.health.check.redis.host={{gateway.health.check.redis.host}}
gateway.health.check.redis.port={{gateway.health.check.redis.port}}
gateway.health.check.redis.db={{gateway.health.check.redis.db}}
gateway.health.check.redis.password={{gateway.health.check.redis.password}}
gateway.health.check.cluster={{gateway.health.check.cluster}}
gateway.health.check.nodeid={{gateway.health.check.nodeid}}
gateway.health.check.window={{gateway.health.check.window}}
gateway.aop.timer.on={{gateway.aop.timer.on}}
gateway.health.status.green={{gateway.health.status.green}}
gateway.health.status.yellow={{gateway.health.status.yellow}}
26 changes: 26 additions & 0 deletions samples/template/meta-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% for item in seq -%}

build:
args:
buildno: {{item}}
user: {{hello.world}}
check: {{hello.on}}
javaHome: {{'cat'| env('JAVA_HOME')}}

build:
args:
- buildno={{item}}
- user={{hello.world}}
- javaHome={{'dog'| env('JAVA_HOME')}}

{%- endfor %}

<start>
{% for key, value in linksList.items() recursive %}
{{loop.depth}}> {%- if value is string -%}
- {{key}} : "{{ value }}"
{%- else -%}
{{ key }} : {{ loop(value.items()) }}
{%- endif -%}
{% endfor %}
</end>