From de91a99fb041711e83860137f73bb13dc75baddf Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Wed, 14 Dec 2022 10:48:51 -0600 Subject: [PATCH] Finish re_compose.py --- README.md | 6 ++++- basic-management.py | 0 re-compose.py | 0 re_compose.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) delete mode 100644 basic-management.py delete mode 100644 re-compose.py create mode 100644 re_compose.py diff --git a/README.md b/README.md index 06fdbd1..c70769e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is a simple program to manage docker containers. It works similarly to Umbr ## How to use - **Note:** All scrips must be run in the same directory as the `.config` file. - If you want to re-compose your containers on boot, you can run `composer.py` on boot -- If you want to re-compose your containers on demand, you can run `re-compose.py` manually +- If you want to re-compose your containers on demand, you can run `re_compose.py` manually - If you just want to do basic management, like stopping, starting, removing docker containers, etc, then use `basic-management.py`. It's essentially an interactive wrapper for the basics of docker. @@ -24,3 +24,7 @@ I'll get to this later once this program is actually usable. ## Dev Notes - Maybe later expand this to an interactive docker manager. + +## Status +- `composer.py` and `re_compose` are finished +- Haven't started on `basic_management.py` \ No newline at end of file diff --git a/basic-management.py b/basic-management.py deleted file mode 100644 index e69de29..0000000 diff --git a/re-compose.py b/re-compose.py deleted file mode 100644 index e69de29..0000000 diff --git a/re_compose.py b/re_compose.py new file mode 100644 index 0000000..020a66f --- /dev/null +++ b/re_compose.py @@ -0,0 +1,57 @@ +import os +from subprocess import getoutput + +debug = False + +# Read config file and make variables +config = open('docker-composer.conf', 'rt') +working_dir = os.getcwd() + +compose_path = config.readline() +compose_path = compose_path[compose_path.find('=')+1:].strip() +if compose_path[-1:] != '/': + compose_path += '/' + +exclude_containers = config.readline() +exclude_containers = [container.strip() for container \ +in exclude_containers[exclude_containers.find('=')+1:].split(',')] + +compose_dirs = [] +for dir in os.listdir(compose_path): + if os.path.isdir(compose_path + dir) and dir not in exclude_containers: + compose_dirs.append(compose_path + dir + '/') + +# Print debug info +if debug: + print('Working directory: ' + working_dir) + print('Compose path: ' + compose_path) + print('Exclude containers: ' + str(exclude_containers)) + print('Compose directories: ' + str(compose_dirs)) + +running = True +while running: + containers = [dir[:-1][dir[:-1].rfind('/')+1:] for dir in compose_dirs] + # Menu + print('What Docker container would you like to (re-)compose?') + print('(q) - quit') + for i in range(len(containers)): + print(f'({i}) - {containers[i]}') + to_compose_i = input() + if to_compose_i == 'q': + exit(0) + to_compose_i = int(to_compose_i) + + # COMPOSE! + container_name = containers[to_compose_i] + if debug: + print('Container name: ' + container_name) + getoutput(f'docker stop {container_name}') + getoutput(f'docker rm {container_name}') + + 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)') + running = True if input() == 'y' else False