Sync progress
This commit is contained in:
parent
795aa23c89
commit
4474ba5e29
3 changed files with 29 additions and 35 deletions
36
composer.py
36
composer.py
|
@ -1,7 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from subprocess import getoutput
|
from subprocess import getoutput
|
||||||
|
from docker_wrapper import Docker
|
||||||
debug = True
|
|
||||||
|
|
||||||
# Read config file and make variables
|
# Read config file and make variables
|
||||||
config = open('docker-composer.conf', 'rt')
|
config = open('docker-composer.conf', 'rt')
|
||||||
|
@ -23,23 +22,20 @@ for dir in os.listdir(compose_path):
|
||||||
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
|
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
|
||||||
compose_dirs.append(compose_path + dir + '/')
|
compose_dirs.append(compose_path + dir + '/')
|
||||||
|
|
||||||
# Print debug info
|
containers = []
|
||||||
if debug:
|
for dir in compose_dirs:
|
||||||
print('Working directory: ' + working_dir)
|
containers.append()
|
||||||
print('Compose path: ' + compose_path)
|
|
||||||
print('Exclude containers: ' + str(exclude_containers))
|
|
||||||
print('Compose directories: ' + str(compose_dirs))
|
|
||||||
|
|
||||||
# COMPOSE!
|
# COMPOSE!
|
||||||
for dir in compose_dirs:
|
for i in range(len(compose_dirs)):
|
||||||
container_name = dir[:-1][dir[:-1].rfind('/')+1:]
|
dir = compose_dirs[i]
|
||||||
if debug:
|
container = containers[i]
|
||||||
print('Compose dir: ' + dir)
|
status = Docker.stop(container) # Assigned to vars so I can see
|
||||||
print('Container name: ' + container_name)
|
if status != 0:
|
||||||
getoutput(f'docker stop {container_name}')
|
print(f'Error in stopping {container}, skipping...')
|
||||||
getoutput(f'docker rm {container_name}')
|
status = Docker.rm(container)
|
||||||
|
if status != 0:
|
||||||
os.chdir(dir)
|
print(f'Error in removing {container}, skipping...')
|
||||||
output = getoutput('docker compose up -d')
|
status = Docker.compose(dir)
|
||||||
if debug:
|
if status != 0:
|
||||||
print(output)
|
print(f'Error in composing {container}, skipping...')
|
||||||
|
|
|
@ -117,7 +117,7 @@ class Docker:
|
||||||
"""
|
"""
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir(dir)
|
os.chdir(dir)
|
||||||
status = getstatusoutput('docker ps')
|
status = getstatusoutput('docker compose up -d')
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import os
|
import os
|
||||||
from subprocess import getoutput
|
from docker_wrapper import Docker
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ for dir in os.listdir(compose_path):
|
||||||
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
|
if os.path.isdir(compose_path + dir) and dir not in exclude_containers:
|
||||||
compose_dirs.append(compose_path + dir + '/')
|
compose_dirs.append(compose_path + dir + '/')
|
||||||
|
|
||||||
|
containers = [dir[:-1][dir[:-1].rfind('/')+1:] for dir in compose_dirs]
|
||||||
|
|
||||||
|
|
||||||
# Print debug info
|
# Print debug info
|
||||||
if debug:
|
if debug:
|
||||||
print('Working directory: ' + working_dir)
|
print('Working directory: ' + working_dir)
|
||||||
|
@ -32,28 +35,23 @@ if debug:
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
containers = [dir[:-1][dir[:-1].rfind('/')+1:] for dir in compose_dirs]
|
|
||||||
# Menu
|
# Menu
|
||||||
print('What Docker container would you like to (re-)compose?')
|
print('What Docker container would you like to (re-)compose?')
|
||||||
print('(q) - quit')
|
|
||||||
for i in range(len(containers)):
|
for i in range(len(containers)):
|
||||||
print(f'({i}) - {containers[i]}')
|
print(f' {i} - {containers[i]}')
|
||||||
|
print(' q - quit')
|
||||||
|
|
||||||
to_compose_i = input()
|
to_compose_i = input()
|
||||||
if to_compose_i == 'q':
|
if to_compose_i == 'q':
|
||||||
exit(0)
|
exit(0)
|
||||||
to_compose_i = int(to_compose_i)
|
to_compose_i = int(to_compose_i)
|
||||||
|
|
||||||
# COMPOSE!
|
# COMPOSE!
|
||||||
container_name = containers[to_compose_i]
|
container = containers[to_compose_i]
|
||||||
if debug:
|
container_dir = compose_dirs[to_compose_i]
|
||||||
print('Container name: ' + container_name)
|
Docker.stop(container)
|
||||||
getoutput(f'docker stop {container_name}')
|
Docker.rm(container)
|
||||||
getoutput(f'docker rm {container_name}')
|
Docker.compose(container_dir)
|
||||||
|
|
||||||
os.chdir(compose_dirs[to_compose_i])
|
|
||||||
output = getoutput('docker compose up -d')
|
|
||||||
if debug:
|
|
||||||
print(output)
|
|
||||||
|
|
||||||
print('\nWould you like to (re-)compose another container? (y/N)')
|
print('\nWould you like to (re-)compose another container? (y/N)')
|
||||||
running = True if input() == 'y' else False
|
running = True if input() == 'y' else False
|
||||||
|
|
Loading…
Reference in a new issue