From ca6f89aedfcc66805e02eed591e1ff4b488b2796 Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 13 Dec 2022 19:43:37 -0600 Subject: [PATCH] Finished composer.py --- composer.py | 37 +++++++++++++++++++-------- docker-composer.conf | 2 +- docker-data/pihole/docker-compose.yml | 24 ----------------- 3 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 docker-data/pihole/docker-compose.yml diff --git a/composer.py b/composer.py index cb13f96..d18b56a 100644 --- a/composer.py +++ b/composer.py @@ -1,12 +1,11 @@ import os +from subprocess import getoutput -sudo_needed = True -if os.system('whoami') != 'root' && sudo_needed: - print('Please rerun as root so I can access docker') +debug = True -config = open('.config', 'rt') +# Read config file and make variables +config = open('docker-composer.conf', 'rt') working_dir = os.getcwd() -print(working_dir) compose_path = config.readline() compose_path = compose_path[compose_path.find('=')+1:].strip() @@ -14,14 +13,32 @@ if compose_path[-1:] != '/': compose_path += '/' exclude_containers = config.readline() -exclude_containers = [container.strip() for container in exclude_containers[exclude_containers.find('=')+1:].split(',')] +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(dir): - compose_dirs.append(compose_path + dir + '/') + 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)) # COMPOSE! for dir in compose_dirs: - os.chdir(dir) - os.system('docker compose lorem ipsum idk') + container_name = dir[:-1] + container_name = container_name[container_name.rfind('/')+1:] + if debug: + print('Compose dir: ' + dir) + print('Container name: ' + container_name) + getoutput(f'docker stop {container_name}') + getoutput(f'docker rm {container_name}') + + os.chdir(dir) + output = getoutput('docker compose up -d') + if debug: + print(output) diff --git a/docker-composer.conf b/docker-composer.conf index f94051e..d4f7768 100644 --- a/docker-composer.conf +++ b/docker-composer.conf @@ -1,2 +1,2 @@ -compose-path=/home/ben/Documents/Coding/docker-composer +compose-path=/path/to/docker-container-folders/that-contain-docker-compose.yml exclude-containers=hello,there,random-person \ No newline at end of file diff --git a/docker-data/pihole/docker-compose.yml b/docker-data/pihole/docker-compose.yml deleted file mode 100644 index 3855c7d..0000000 --- a/docker-data/pihole/docker-compose.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: "3" - -# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/ -services: - pihole: - container_name: pihole - image: pihole/pihole:latest - # For DHCP it is recommended to remove these ports and instead add: network_mode: "host" - ports: - - "53:53/tcp" - - "53:53/udp" - - "67:67/udp" # Only required if you are using Pi-hole as your DHCP server - - "80:80/tcp" - environment: - TZ: 'America/Chicago' - # WEBPASSWORD: 'set a secure password here or it will be random' - # Volumes store your data between container upgrades - volumes: - - './etc-pihole:/etc/pihole' - - './etc-dnsmasq.d:/etc/dnsmasq.d' - # https://github.com/pi-hole/docker-pi-hole#note-on-capabilities - cap_add: - - NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed - restart: unless-stopped