Finished composer.py

This commit is contained in:
askiiart 2022-12-13 19:43:37 -06:00
parent bc61c8ddda
commit ca6f89aedf
3 changed files with 28 additions and 35 deletions

View file

@ -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):
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:
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)
os.system('docker compose lorem ipsum idk')
output = getoutput('docker compose up -d')
if debug:
print(output)

View file

@ -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

View file

@ -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