|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import configparser |
| 3 | +import secrets |
| 4 | + |
| 5 | +compose_template = open('docker-compose.yml.in', 'r').read() |
| 6 | + |
| 7 | +config = configparser.ConfigParser() |
| 8 | +config.read('.config') |
| 9 | + |
| 10 | +modified_compose = compose_template.replace('REPLACE_WITH_EXTERNAL_HOST', config['MANDATORY']['SETTING_EXTERNAL_HOST']) |
| 11 | +modified_compose = modified_compose.replace('REPLACE_WITH_ADMIN_EMAIL', config['MANDATORY']['SETTING_ZULIP_ADMINISTRATOR']) |
| 12 | + |
| 13 | +if config['SECRETS']['POSTGRES_PASSWORD'] == 'REPLACE_WITH_SECURE_POSTGRES_PASSWORD': |
| 14 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_POSTGRES_PASSWORD', secrets.token_hex(32)) |
| 15 | +else: |
| 16 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_POSTGRES_PASSWORD', config['SECRETS']['POSTGRES_PASSWORD']) |
| 17 | + |
| 18 | +if config['SECRETS']['MEMCACHED_PASSWORD'] == 'REPLACE_WITH_SECURE_MEMCACHED_PASSWORD': |
| 19 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_MEMCACHED_PASSWORD', secrets.token_hex(32)) |
| 20 | +else: |
| 21 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_MEMCACHED_PASSWORD', config['SECRETS']['MEMCACHED_PASSWORD']) |
| 22 | + |
| 23 | +if config['SECRETS']['RABBITMQ_DEFAULT_PASS'] == 'REPLACE_WITH_SECURE_RABBITMQ_PASSWORD': |
| 24 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_RABBITMQ_PASSWORD', secrets.token_hex(32)) |
| 25 | +else: |
| 26 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_RABBITMQ_PASSWORD', config['SECRETS']['RABBITMQ_DEFAULT_PASS']) |
| 27 | + |
| 28 | +if config['SECRETS']['REDIS_PASSWORD'] == 'REPLACE_WITH_SECURE_REDIS_PASSWORD': |
| 29 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_REDIS_PASSWORD', secrets.token_hex(32)) |
| 30 | +else: |
| 31 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_REDIS_PASSWORD', config['SECRETS']['REDIS_PASSWORD']) |
| 32 | + |
| 33 | +if config['SECRETS']['SECRETS_secret_key'] == 'REPLACE_WITH_SECURE_SECRET_KEY': |
| 34 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_SECRET_KEY', ''.join(secrets.choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50))) |
| 35 | +else: |
| 36 | + modified_compose = modified_compose.replace('REPLACE_WITH_SECURE_SECRET_KEY', config['SECRETS']['SECRETS_secret_key']) |
| 37 | + |
| 38 | +open('docker-compose.yml', 'w').write(modified_compose) |
0 commit comments