Skip to content

Commit

Permalink
Allow the user to specify the overlay network they want to use
Browse files Browse the repository at this point in the history
  • Loading branch information
evilkermit committed Apr 25, 2023
1 parent df03a0b commit 08586e6
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 18 deletions.
1 change: 1 addition & 0 deletions api/substrate.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 17 additions & 6 deletions src/substrate/targets/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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']
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions src/substrate/tools/braid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -62,7 +66,7 @@ def start(self):
),
mounts=mounts,
name='braid',
networks=[f'substrate-{self.name}-net'],
networks=[network_name],
workdir='/opt/run'
)

Expand Down
8 changes: 7 additions & 1 deletion src/substrate/tools/generic_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])
Expand All @@ -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
)
8 changes: 6 additions & 2 deletions src/substrate/tools/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -41,5 +45,5 @@ def start(self):
),
mounts=mounts,
name='hello-world',
networks=[f'substrate-{self.name}-net']
networks=[network_name]
)
13 changes: 9 additions & 4 deletions src/substrate/tools/nc_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
8 changes: 6 additions & 2 deletions src/substrate/tools/ospray_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -41,5 +45,5 @@ def start(self):
),
mounts=mounts,
name='ospray-studio',
networks=[f'substrate-{self.name}-net']
networks=[network_name]
)
7 changes: 6 additions & 1 deletion src/substrate/tools/tapestry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 08586e6

Please sign in to comment.