-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_docker-compose_config.py
44 lines (36 loc) · 1.54 KB
/
create_docker-compose_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
from string import Template
import server.config.settings_local as settings
db_settings = settings.DATABASES['default']
docker_db_fn = 'pg_pass_file'
docker_template_fn = 'docker-compose_template.yml'
docker_fn = docker_template_fn.replace('_template', '')
# Need to quote values if there are any special characters
d = {
'ann_dir': "{}".format(settings.ANN_FILE_DIR),
'data_dir': "{}".format(settings.DATA_DIR),
'db_dir': "{}".format(settings.DATABASE_DIR),
'db_name': "{}".format(db_settings['NAME']),
'db_pass': "{}".format(db_settings['PASSWORD']),
'db_port': "{}".format(db_settings['PORT']),
'db_user': "{}".format(db_settings['USER']),
'dock_share': "{}".format(settings.DOCKER_DIR),
}
with open(docker_template_fn, 'r') as inf, open(docker_fn, 'wt') as outf:
for line in inf:
new_line = Template(line).substitute(d)
outf.write(new_line)
# Create pg_pass_file
# settings.DOCKER_DB_HOST
with open(docker_db_fn, 'wt') as outf:
outf.write("{}:{}:{}:{}:{}".format(settings.DOCKER_DB_HOST,
d['db_port'],
d['db_name'],
d['db_user'],
d['db_pass']))
outf.write('\n')
outf.write("{}:{}:{}:{}:{}".format(settings.DOCKER_DB_HOST,
d['db_port'],
'*',
d['db_user'],
d['db_pass']))