Skip to content

Commit

Permalink
fix docker host for the different environemnts
Browse files Browse the repository at this point in the history
  • Loading branch information
baszoetekouw committed Dec 22, 2023
1 parent 551ccc0 commit 88e3cf1
Showing 1 changed file with 55 additions and 23 deletions.
78 changes: 55 additions & 23 deletions docker/docker-compose.yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,63 @@
# --ci: this generates a docker-compose.yml file for CI
# --container: this generates a docker-compose.yml file for SCZ
parser = argparse.ArgumentParser(description='Generate a docker-compose.yml file for SCZ or CI')
parser.add_argument('--ci', action='store_true', help='generate a docker-compose.yml file for CI')
parser.add_argument('--container', action='store_true', help='generate a docker-compose.yml file for SCZ')
group = parser.add_mutually_exclusive_group()
group.add_argument('--ci', action='store_true', help='generate a docker-compose.yml file for CI')
group.add_argument('--container', action='store_true', help='generate a docker-compose.yml file for SCZ')
args = parser.parse_args()

# these are the Docker containers that need to be spun up
hosts = {
ip_lookup = {
'ldap1': 20,
'ldap2': 21,
'meta': 23,
'lb': 24,
'client': 25,
'sandbox1': 26,
'sbs': 27,
'db': 28,
'bhr': 29,
'test': 30,
'docker': 31,
'redis': 98,
'mail': 99,
}

# the old non-containerized setup needs more hosts
if not args.container:
hosts.update({
'ldap1': 20,
'ldap2': 21,
'meta': 23,
'sandbox1': 26,
'sbs': 27,
'db': 28,
})
if args.ci and args.container:
raise ValueError("Cannot generate a docker-compose.yml file for both CI and SCZ")
elif args.ci and not args.container:
hosts = ['db', 'redis', 'sbs', 'test']
elif not args.ci and args.container:
hosts = ['bhr', 'client', 'mail', 'lb', 'docker']
else: # classic, non-ci, non-containerized setup
hosts = ['bhr', 'client', 'lb', 'redis', 'mail', 'sandbox1', 'db', 'sbs', 'ldap1', 'ldap2', 'meta']

hosts_ip = {h: ip_lookup[h] for h in hosts}

# these are the Docker containers that need to be spun up
hosts = {
'bhr': 29,
'docker': 31,
}

# the old non-containerized setup needs more hosts
if args.ci:
hosts.update({
'test': 30,
})
else:
hosts.update({
'lb': 24,
'client': 25,
})
if not args.container:
hosts.update({
'ldap1': 20,
'ldap2': 21,
'meta': 23,
'sandbox1': 26,
'sbs': 27,
'db': 28,
})

# these are the hostnames of virtual hosts on the load balancer
logical_hosts = [
Expand Down Expand Up @@ -139,19 +169,21 @@ def create_compose() -> Dict[str, Any]:
'driver_opts': {"com.docker.network.bridge.name": "br-sram"}
}
}
compose['services'] = {h: host_config(ip, h) for h, ip in hosts.items()}

# Add redis host on .98
if not args.container:
compose['services']['redis'] = redis_config(98, 'redis')

# Add mail test host on .99
if not args.ci:
compose['services']['mail'] = mail_config(99, 'mail')
compose['services'] = dict()
for h, ip in hosts_ip.items():
if h=='mail':
compose['services'][h] = mail_config(ip, h)
elif h=='redis':
compose['services'][h] = redis_config(ip, h)
else:
compose['services'][h] = host_config(ip, h)

if args.container:
# Add volume for docker '/var/lib/docker'
compose.setdefault('volumes', {})['docker_volume'] = {'driver': 'local'}
compose['services']['docker'].setdefault('volumes', []).append('docker_volume:/var/lib/docker')

# Add mail test host on .99
return compose


Expand Down

0 comments on commit 88e3cf1

Please sign in to comment.