docker-composer/composer.py

37 lines
1.1 KiB
Python
Raw Normal View History

2022-12-13 08:20:23 -06:00
import os
2022-12-15 15:24:19 -06:00
from docker_wrapper import Docker
2022-12-13 08:20:23 -06:00
2022-12-13 19:43:37 -06:00
# Read config file and make variables
config = open('docker-composer.conf', 'rt')
2022-12-13 08:20:23 -06:00
working_dir = os.getcwd()
compose_path = config.readline()
compose_path = compose_path[compose_path.find('=')+1:].strip()
if compose_path[-1:] != '/':
compose_path += '/'
2022-12-16 21:07:00 -06:00
if compose_path[0] != '/':
2022-12-14 13:56:42 -06:00
compose_path = f'{working_dir}/{compose_path}'
2022-12-13 08:20:23 -06:00
exclude_containers = config.readline()
2022-12-13 19:43:37 -06:00
exclude_containers = [container.strip() for container \
in exclude_containers[exclude_containers.find('=')+1:].split(',')]
2022-12-13 08:20:23 -06:00
compose_dirs = []
for dir in os.listdir(compose_path):
2023-01-03 09:50:31 -06:00
if os.path.isdir(compose_path + dir) and dir not in exclude_containers and dir[0] != '.':
2022-12-13 19:43:37 -06:00
compose_dirs.append(compose_path + dir + '/')
2022-12-15 15:24:19 -06:00
containers = []
2022-12-13 08:20:23 -06:00
for dir in compose_dirs:
container = dir[:-1]
container = container[container.rfind('/')+1:]
containers.append(container)
2022-12-13 19:43:37 -06:00
2022-12-15 15:24:19 -06:00
# COMPOSE!
for i in range(len(compose_dirs)):
dir = compose_dirs[i]
container = containers[i]
2022-12-24 14:27:16 -06:00
print(f'COMPOSING {container}...')
2022-12-15 17:39:41 -06:00
Docker.compose(dir)
2022-12-24 14:27:16 -06:00
print('DONE!')