diff --git a/api/substrate.config.yaml b/api/substrate.config.yaml index 1b6622f..5548475 100644 --- a/api/substrate.config.yaml +++ b/api/substrate.config.yaml @@ -17,6 +17,7 @@ data: ### Local deployment ### Each node should have Docker Engine installed. docker: + network: OPTIONAL - the name of the overlay network to use port: OPTIONAL - the port to be expose the Docker service on replicas: OPTIONAL - the number of replicas the Docker swarm should use advertise_addr: REQUIRED if using multiple local nodes - the IP:PORT to use to add nodes to the swarm diff --git a/src/substrate/targets/docker_swarm.py b/src/substrate/targets/docker_swarm.py index ad1c732..0489eed 100644 --- a/src/substrate/targets/docker_swarm.py +++ b/src/substrate/targets/docker_swarm.py @@ -15,6 +15,10 @@ def __init__(self, _, config, tool): self.tool = tool self.docker = from_env() + self.network_name = self.config['docker'].get( + 'network', + 'substrate-{self.tool.name}-net' + ) self.network = None ssh_dir = os.path.join(Path.home(), '.ssh') @@ -35,10 +39,14 @@ def create_swarm(self): pass self.log('✓\n') - self.network = self.docker.networks.create( - f'substrate-{self.tool.name}-net', - driver='overlay' - ) + networks = self.docker.networks.list(names=[self.network_name]) + if networks: + self.network = networks[0] + else: + self.network = self.docker.networks.create( + self.network_name, + driver='overlay' + ) manager_token = self.docker.swarm.attrs['JoinTokens']['Manager'] worker_token = self.docker.swarm.attrs['JoinTokens']['Worker'] @@ -125,8 +133,11 @@ def destroy_swarm(self): self.log('✓\n') self.log('Removing the swarm service…') - for obj in self.docker.services.list(filters={'name': self.tool.name}) + self.docker.networks.list(names=[f'substrate-{self.tool.name}-net']): # noqa: E501 - obj.remove() + for obj in self.docker.services.list(filters={'name': self.tool.name}) + self.docker.networks.list(names=[self.network_name]): # noqa: E501 + try: + obj.remove() + except APIError: + pass self.log('✓\n') def log(self, message): diff --git a/src/substrate/tools/braid.py b/src/substrate/tools/braid.py index db6c3f5..16c55fe 100644 --- a/src/substrate/tools/braid.py +++ b/src/substrate/tools/braid.py @@ -39,9 +39,13 @@ def __init__(self, config, data_sources): def start(self): mounts = super().start() - docker = from_env() + network_name = self.config['docker'].get( + 'network', + 'substrate-braid-net' + ) + mounts.append( Mount('/opt/run', self.braid_path, type='bind', read_only=True) ) @@ -62,7 +66,7 @@ def start(self): ), mounts=mounts, name='braid', - networks=[f'substrate-{self.name}-net'], + networks=[network_name], workdir='/opt/run' ) diff --git a/src/substrate/tools/generic_tool.py b/src/substrate/tools/generic_tool.py index 4f790a7..a0fa9c6 100644 --- a/src/substrate/tools/generic_tool.py +++ b/src/substrate/tools/generic_tool.py @@ -33,6 +33,12 @@ def start(self): mounts = super().start() docker = from_env() + + network_name = self.config['docker'].get( + 'network', + f'substrate-{self.name}-net' + ) + self.port = self.config['docker'].get('port', self.port) environment_variables = self.config['docker'].get('env', []) arguments = self.config.get('args', []) @@ -49,6 +55,6 @@ def start(self): env=environment_variables, mounts=mounts, name=self.name, - networks=[f'substrate-{self.name}-net'], + networks=[network_name], init=True ) diff --git a/src/substrate/tools/hello_world.py b/src/substrate/tools/hello_world.py index de44aad..6a22962 100644 --- a/src/substrate/tools/hello_world.py +++ b/src/substrate/tools/hello_world.py @@ -26,9 +26,13 @@ def __init__(self, config, data_sources): def start(self): mounts = super().start() - docker = from_env() + network_name = self.config['docker'].get( + 'network', + 'substrate-hello-net' + ) + self.port = self.config['docker'].get('port', self.port) docker.services.create( 'seelab/substrate-hello-world:latest', @@ -41,5 +45,5 @@ def start(self): ), mounts=mounts, name='hello-world', - networks=[f'substrate-{self.name}-net'] + networks=[network_name] ) diff --git a/src/substrate/tools/nc_slicer.py b/src/substrate/tools/nc_slicer.py index 4e9af78..b60bd75 100644 --- a/src/substrate/tools/nc_slicer.py +++ b/src/substrate/tools/nc_slicer.py @@ -27,6 +27,12 @@ def __init__(self, config, data_sources): def start(self): mounts = super().start() docker = from_env() + + network_name = self.config['docker'].get( + 'network', + 'substrate-slicer-net' + ) + self.port = self.config['docker'].get('port', self.port) docker.services.create( 'seelab/substrate-nc-slicer', @@ -37,12 +43,11 @@ def start(self): ), mounts=mounts, name='nc-slicer', - networks=[f'substrate-{self.name}-net'], + networks=[network_name], init=True ) - # TODO: + # TODO: # fix nc-slicer -> nc_slicer and init=True in main substrate repo # set up dockerhub org and move images to it - # impliment water-and-land changes to nc_slicer image - + # impliment water-and-land changes to nc_slicer image diff --git a/src/substrate/tools/ospray_studio.py b/src/substrate/tools/ospray_studio.py index b3564e2..74e4d06 100644 --- a/src/substrate/tools/ospray_studio.py +++ b/src/substrate/tools/ospray_studio.py @@ -26,9 +26,13 @@ def __init__(self, config, data_sources): def start(self): mounts = super().start() - docker = from_env() + network_name = self.config['docker'].get( + 'network', + 'substrate-ospray-studio-net' + ) + self.port = self.config['docker'].get('port', self.port) docker.services.create( 'seelab/substrate-ospray-studio:latest', @@ -41,5 +45,5 @@ def start(self): ), mounts=mounts, name='ospray-studio', - networks=[f'substrate-{self.name}-net'] + networks=[network_name] ) diff --git a/src/substrate/tools/tapestry.py b/src/substrate/tools/tapestry.py index bc294f6..6d7e451 100644 --- a/src/substrate/tools/tapestry.py +++ b/src/substrate/tools/tapestry.py @@ -40,6 +40,11 @@ def start(self): mounts = super().start() docker = from_env() + network_name = self.config['docker'].get( + 'network', + 'substrate-tapestry-net' + ) + mounts.append(Mount('/app', self.app_path, type='bind', read_only=True)) mounts.append( Mount('/config', self.config_path, type='bind', read_only=True) @@ -58,7 +63,7 @@ def start(self): ), mounts=mounts, name='tapestry', - networks=[f'substrate-{self.name}-net'] + networks=[network_name] ) def upload_to_s3(self):