services: make it possible to run services in localhost

This commit is contained in:
tylen 2025-05-11 23:15:51 +03:00
parent 52f26cd0e0
commit cac19b4716

View File

@ -63,20 +63,33 @@ class DockerServiceCLI(BaseCli):
services.append(service) services.append(service)
return services return services
def create_docker_command(self, service: Service):
command_str = ['docker']
if service.host.ip != 'localhost':
command_str.append('-H')
command_str.append(f'{service.host.user}@{service.host.ip}')
command_str.append('compose')
command_str.append('-f')
command_str.append(f'{service.compose_file}')
if service.env_file:
command_str.append('--env-file')
command_str.append(f'{service.env_file}')
command_str.append('up')
command_str.append('-d')
self.info(f"Executing command: {' '.join(command_str)}")
return command_str
def run_docker_command(self, service: Service): def run_docker_command(self, service: Service):
self.info(f"Processing service:\n{service}") self.info(f"Processing service:\n{service}")
for i in range(0, len(service.ports)): for i in range(0, len(service.ports)):
self.info(f'Set env SVC_PORT_{i+1}={str(service.ports[i])}') self.info(f'Set env SVC_PORT_{i+1}={str(service.ports[i])}')
os.environ[f'SVC_PORT_{i+1}'] = str(service.ports[i]) os.environ[f'SVC_PORT_{i+1}'] = str(service.ports[i])
os.environ['SVC_HOST'] = str(service.host.ip)
command = [ command = self.create_docker_command(service)
'docker', '-H', f"{service.host.user}@{service.host.ip}",
'compose', '-f', f"{service.compose_file}",
'--env-file', f"{service.env_file}",
'up', '-d'
]
try: try:
subprocess.run(command, check=True) subprocess.run(command, check=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e: