tools: add possibility to set ports from services yaml
This commit is contained in:
parent
15bd93abd1
commit
fe9b77875a
@ -2,7 +2,7 @@ services:
|
|||||||
audiobookshelf:
|
audiobookshelf:
|
||||||
image: ghcr.io/advplyr/audiobookshelf:latest
|
image: ghcr.io/advplyr/audiobookshelf:latest
|
||||||
ports:
|
ports:
|
||||||
- 13378:80
|
- ${SVC_PORT_1}:80
|
||||||
volumes:
|
volumes:
|
||||||
- ${MEDIA_PATH}/Books/Audiobooks:/audiobooks
|
- ${MEDIA_PATH}/Books/Audiobooks:/audiobooks
|
||||||
- ${MEDIA_PATH}/Podcasts:/podcasts
|
- ${MEDIA_PATH}/Podcasts:/podcasts
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
version: "3"
|
|
||||||
services:
|
services:
|
||||||
server:
|
server:
|
||||||
image: docker.gitea.com/gitea:1.23.5
|
image: docker.gitea.com/gitea:1.23.5
|
||||||
@ -12,5 +11,5 @@ services:
|
|||||||
- /etc/timezone:/etc/timezone:ro
|
- /etc/timezone:/etc/timezone:ro
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "${SVC_PORT_1}:3000"
|
||||||
- "222:22"
|
- "${SVC_PORT_2}:22"
|
||||||
@ -8,9 +8,7 @@ services:
|
|||||||
MYSQL_PASSWORD: '${USER_PASSWORD}'
|
MYSQL_PASSWORD: '${USER_PASSWORD}'
|
||||||
MYSQL_ROOT_PASSWORD: '${ROOT_PASSWORD}'
|
MYSQL_ROOT_PASSWORD: '${ROOT_PASSWORD}'
|
||||||
ports:
|
ports:
|
||||||
- '3306:3306'
|
- '${SVC_PORT_1}:3306'
|
||||||
expose:
|
|
||||||
- '3306'
|
|
||||||
volumes:
|
volumes:
|
||||||
- my-db:/var/lib/mysql
|
- my-db:/var/lib/mysql
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@ -12,16 +12,23 @@ vm-media-100-55: &vm-media-100-55
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
- name: "audiobookshelf"
|
- name: "audiobookshelf"
|
||||||
|
ports:
|
||||||
|
- 13378
|
||||||
host:
|
host:
|
||||||
<<: *vm-media-100-55
|
<<: *vm-media-100-55
|
||||||
<<: *defaultServiceValues
|
<<: *defaultServiceValues
|
||||||
|
|
||||||
- name: "gitea"
|
- name: "gitea"
|
||||||
|
ports:
|
||||||
|
- 3000
|
||||||
|
- 222
|
||||||
host:
|
host:
|
||||||
<<: *vm-tools-100-65
|
<<: *vm-tools-100-65
|
||||||
<<: *defaultServiceValues
|
<<: *defaultServiceValues
|
||||||
|
|
||||||
- name: "ippoolmanager-sql-server"
|
- name: "ippoolmanager-sql-server"
|
||||||
|
ports:
|
||||||
|
- 3001
|
||||||
host:
|
host:
|
||||||
<<: *vm-tools-100-65
|
<<: *vm-tools-100-65
|
||||||
<<: *defaultServiceValues
|
<<: *defaultServiceValues
|
||||||
|
|||||||
@ -1,12 +1,22 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
class Colors:
|
||||||
|
RESET = "\033[0m"
|
||||||
|
RED = "\033[31m"
|
||||||
|
GREEN = "\033[32m"
|
||||||
|
YELLOW = "\033[33m"
|
||||||
|
BLUE = "\033[34m"
|
||||||
|
MAGENTA = "\033[35m"
|
||||||
|
CYAN = "\033[36m"
|
||||||
|
WHITE = "\033[37m"
|
||||||
|
|
||||||
class BaseCli:
|
class BaseCli:
|
||||||
def info(self, message):
|
def info(self, message):
|
||||||
print(f'[INFO] {message}')
|
print(f'[{Colors.GREEN}INFO{Colors.RESET}] {message}')
|
||||||
|
|
||||||
def warning(self, message):
|
def warning(self, message):
|
||||||
print(f'[WARNING] {message}')
|
print(f'[{Colors.YELLOW}WARNING{Colors.RESET}] {message}')
|
||||||
|
|
||||||
def error(self, message, exit_code=1):
|
def error(self, message, exit_code=1):
|
||||||
print(f'[ERROR] {message}')
|
print(f'[{Colors.RED}ERROR{Colors.RESET}] {message}')
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
@ -1,14 +1,22 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field, asdict
|
||||||
|
from typing import List
|
||||||
|
import yaml
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Host:
|
class Host:
|
||||||
ip: str
|
ip: str
|
||||||
user: str
|
user: str
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return yaml.dump(asdict(self), default_flow_style=False)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Service:
|
class Service:
|
||||||
name: str
|
name: str
|
||||||
host: Host
|
|
||||||
compose_file: str
|
compose_file: str
|
||||||
env_file: str
|
env_file: str
|
||||||
|
host: Host = field(default_factory=Host)
|
||||||
|
ports: List[int] = field(default_factory=list)
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return yaml.dump(asdict(self), default_flow_style=False)
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from dataclass.service import Service, Host
|
|||||||
from base import BaseCli
|
from base import BaseCli
|
||||||
import yaml
|
import yaml
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import os
|
||||||
from typing import List
|
from typing import List
|
||||||
from constants import SERVICES_DIR_RELATIVE_GIT_ROOT
|
from constants import SERVICES_DIR_RELATIVE_GIT_ROOT
|
||||||
|
|
||||||
@ -56,12 +57,19 @@ class DockerServiceCLI(BaseCli):
|
|||||||
name=service_data['name'],
|
name=service_data['name'],
|
||||||
host=host,
|
host=host,
|
||||||
compose_file=f"{project_path}/{service_data['composeFile']}",
|
compose_file=f"{project_path}/{service_data['composeFile']}",
|
||||||
env_file=f"{project_path}/{service_data['envFile']}"
|
env_file=f"{project_path}/{service_data['envFile']}",
|
||||||
|
ports=service_data.get('ports', [])
|
||||||
)
|
)
|
||||||
services.append(service)
|
services.append(service)
|
||||||
return services
|
return services
|
||||||
|
|
||||||
def run_docker_command(self, service: Service):
|
def run_docker_command(self, service: Service):
|
||||||
|
self.info(f"Processing service:\n{service}")
|
||||||
|
|
||||||
|
for i in range(0, len(service.ports)):
|
||||||
|
self.info(f'Set env SVC_PORT_{i+1}={str(service.ports[i])}')
|
||||||
|
os.environ[f'SVC_PORT_{i+1}'] = str(service.ports[i])
|
||||||
|
|
||||||
command = [
|
command = [
|
||||||
'docker', '-H', f"{service.host.user}@{service.host.ip}",
|
'docker', '-H', f"{service.host.user}@{service.host.ip}",
|
||||||
'compose', '-f', f"{service.compose_file}",
|
'compose', '-f', f"{service.compose_file}",
|
||||||
@ -71,7 +79,6 @@ class DockerServiceCLI(BaseCli):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(command, check=True)
|
subprocess.run(command, check=True)
|
||||||
self.info(f"Service: {service.name} running on host: {service.host.ip}")
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
self.error(f"Error executing command: {' '.join(command)}, return code: {e.returncode}")
|
self.error(f"Error executing command: {' '.join(command)}, return code: {e.returncode}")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user