services: make it possible to run services in localhost
This commit is contained in:
parent
52f26cd0e0
commit
cac19b4716
@ -63,20 +63,33 @@ class DockerServiceCLI(BaseCli):
|
||||
services.append(service)
|
||||
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):
|
||||
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 = [
|
||||
'docker', '-H', f"{service.host.user}@{service.host.ip}",
|
||||
'compose', '-f', f"{service.compose_file}",
|
||||
'--env-file', f"{service.env_file}",
|
||||
'up', '-d'
|
||||
]
|
||||
|
||||
os.environ['SVC_HOST'] = str(service.host.ip)
|
||||
command = self.create_docker_command(service)
|
||||
try:
|
||||
subprocess.run(command, check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user