Finished composer.py
This commit is contained in:
parent
bc61c8ddda
commit
ca6f89aedf
3 changed files with 28 additions and 35 deletions
37
composer.py
37
composer.py
|
@ -1,12 +1,11 @@
|
||||||
import os
|
import os
|
||||||
|
from subprocess import getoutput
|
||||||
|
|
||||||
sudo_needed = True
|
debug = True
|
||||||
if os.system('whoami') != 'root' && sudo_needed:
|
|
||||||
print('Please rerun as root so I can access docker')
|
|
||||||
|
|
||||||
config = open('.config', 'rt')
|
# Read config file and make variables
|
||||||
|
config = open('docker-composer.conf', 'rt')
|
||||||
working_dir = os.getcwd()
|
working_dir = os.getcwd()
|
||||||
print(working_dir)
|
|
||||||
|
|
||||||
compose_path = config.readline()
|
compose_path = config.readline()
|
||||||
compose_path = compose_path[compose_path.find('=')+1:].strip()
|
compose_path = compose_path[compose_path.find('=')+1:].strip()
|
||||||
|
@ -14,14 +13,32 @@ if compose_path[-1:] != '/':
|
||||||
compose_path += '/'
|
compose_path += '/'
|
||||||
|
|
||||||
exclude_containers = config.readline()
|
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 = []
|
compose_dirs = []
|
||||||
for dir in os.listdir(compose_path):
|
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 + '/')
|
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!
|
# COMPOSE!
|
||||||
for dir in compose_dirs:
|
for dir in compose_dirs:
|
||||||
os.chdir(dir)
|
container_name = dir[:-1]
|
||||||
os.system('docker compose lorem ipsum idk')
|
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)
|
||||||
|
|
|
@ -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
|
exclude-containers=hello,there,random-person
|
|
@ -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
|
|
Loading…
Reference in a new issue