docker-composer/composer.py

42 lines
1.3 KiB
Python
Raw Normal View History

2022-12-13 08:20:23 -06:00
import os
2022-12-13 19:43:37 -06:00
from subprocess import getoutput
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-14 13:56:42 -06:00
if compose_path[1] != '/':
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):
2022-12-13 19:43:37 -06:00
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
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:
2022-12-15 15:24:19 -06:00
containers.append()
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]
status = Docker.stop(container) # Assigned to vars so I can see
if status != 0:
print(f'Error in stopping {container}, skipping...')
status = Docker.rm(container)
if status != 0:
print(f'Error in removing {container}, skipping...')
status = Docker.compose(dir)
if status != 0:
print(f'Error in composing {container}, skipping...')