Skip to content

Commit 0e3edab

Browse files
authored
Is788/allow different stack name (#789)
* director/sidecar independant of stack name using SWARM_STACK_NAME * allow choosing port where simcore platform is available
1 parent 023a767 commit 0e3edab

File tree

7 files changed

+37
-19
lines changed

7 files changed

+37
-19
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export VCS_REF:=$(shell git rev-parse --short HEAD)
4747
export VCS_REF_CLIENT:=$(shell git log --pretty=tformat:"%h" -n1 services/web/client)
4848
export VCS_STATUS_CLIENT:=$(if $(shell git status -s),'modified/untracked','clean')
4949
export BUILD_DATE:=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
50-
50+
export SWARM_STACK_NAME ?= services
5151
# using ?= will only set if absent
5252
export DOCKER_IMAGE_TAG ?= latest
5353
$(info DOCKER_IMAGE_TAG set to ${DOCKER_IMAGE_TAG})
@@ -131,13 +131,12 @@ up-devel: up-swarm-devel
131131
up-swarm: .env docker-swarm-check
132132
${DOCKER} swarm init
133133
${DOCKER_COMPOSE} -f services/docker-compose.yml -f services/docker-compose.tools.yml config > $(TEMPCOMPOSE).tmp-compose.yml ;
134-
${DOCKER} stack deploy -c $(TEMPCOMPOSE).tmp-compose.yml services
134+
${DOCKER} stack deploy -c $(TEMPCOMPOSE).tmp-compose.yml ${SWARM_STACK_NAME}
135135

136136
up-swarm-devel: .env docker-swarm-check $(CLIENT_WEB_OUTPUT)
137137
${DOCKER} swarm init
138138
${DOCKER_COMPOSE} -f services/docker-compose.yml -f services/docker-compose.devel.yml -f services/docker-compose.tools.yml config > $(TEMPCOMPOSE).tmp-compose.yml
139-
${DOCKER} stack deploy -c $(TEMPCOMPOSE).tmp-compose.yml services
140-
139+
${DOCKER} stack deploy -c $(TEMPCOMPOSE).tmp-compose.yml ${SWARM_STACK_NAME}
141140

142141
.PHONY: up-webclient-devel
143142
# target: up-webclient-devel: – init swarm and deploys all core and tool services up in development mode. Then it stops the webclient service and starts it again with the watcher attached.

services/director/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ENV REGISTRY_USER = ''
2727
ENV REGISTRY_PW = ''
2828
ENV REGISTRY_URL = ''
2929
ENV PUBLISHED_HOST_NAME=''
30+
ENV SWARM_STACK_NAME = ''
3031
ENV EXTRA_HOSTS_SUFFIX = 'undefined'
3132

3233

services/director/src/simcore_service_director/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
PUBLISHED_HOST_NAME = os.environ.get("PUBLISHED_HOST_NAME", "")
3333
NODE_SCHEMA_LOCATION = os.environ.get("NODE_SCHEMA_LOCATION",
3434
"{root}/{version}/schemas/node-meta-v0.0.1.json".format(root=API_ROOT, version=API_VERSION))
35+
SWARM_STACK_NAME = os.environ.get("SWARM_STACK_NAME")

services/director/src/simcore_service_director/producer.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,27 @@ def __get_service_entrypoint(service_boot_parameters_labels: Dict) -> str:
124124
return param['value']
125125
return ''
126126

127+
def _get_swarm_network(client: DockerClient) -> docker.models.networks.Network:
128+
network_name = "default"
129+
if config.SWARM_STACK_NAME:
130+
network_name = config.SWARM_STACK_NAME
131+
# try to find the network name (usually named STACKNAME_default)
132+
networks = [x for x in client.networks.list(filters={"scope":"swarm"}) if network_name in x.name]
133+
if not networks or len(networks)>1:
134+
raise exceptions.DirectorException(msg="Swarm network name is not configured, found following networks: {}".format(networks))
135+
return networks[0]
136+
127137

128138
def __add_to_swarm_network_if_ports_published(
129139
client: DockerClient,
130140
docker_service_runtime_parameters: Dict):
131-
# TODO: SAN this is a brain killer... change services to something better...
132141
if "endpoint_spec" in docker_service_runtime_parameters:
133-
network_id = "services_default"
134-
log.debug(
135-
"Adding swarm network with id: %s to docker runtime parameters", network_id)
136-
list_of_networks = client.networks.list(
137-
names=[network_id], filters={"scope": "swarm"})
138-
for network in list_of_networks:
139-
__add_network_to_service_runtime_params(
140-
docker_service_runtime_parameters, network)
141-
log.debug("Added swarm network %s to docker runtime parameters", network_id)
142+
try:
143+
swarm_network = _get_swarm_network(client)
144+
log.debug("Adding swarm network with id: %s to docker runtime parameters", swarm_network.name)
145+
__add_network_to_service_runtime_params(docker_service_runtime_parameters, swarm_network)
146+
except exceptions.DirectorException:
147+
log.exception("Could not find a swarm network, not in a swarm?")
142148

143149

144150
def __add_uuid_label_to_service_runtime_params(

services/docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ services:
5757
- S3_SECRET_KEY=${S3_SECRET_KEY}
5858
- S3_BUCKET_NAME=${S3_BUCKET_NAME}
5959
- STORAGE_ENDPOINT=${STORAGE_ENDPOINT}
60-
- EXTRA_HOSTS_SUFFIX=osparc.io
60+
- EXTRA_HOSTS_SUFFIX=${EXTRA_HOSTS_SUFFIX}
6161
- PUBLISHED_HOST_NAME=${PUBLISHED_HOST_NAME}
62+
- SWARM_STACK_NAME=${SWARM_STACK_NAME}
6263
volumes:
6364
- '/var/run/docker.sock:/var/run/docker.sock'
6465
deploy:
@@ -105,7 +106,7 @@ services:
105106
org.label-schema.vcs-url: "https://github.com/ITISFoundation/osparc-simcore"
106107
org.label-schema.vcs-ref: "${VCS_REF}"
107108
ports:
108-
- '9081:8080'
109+
- ${SIMCORE_PORT:-9081}:8080
109110
environment:
110111
- APIHUB_HOST=apihub
111112
- APIHUB_PORT=8043
@@ -185,6 +186,7 @@ services:
185186
- REGISTRY_URL=${REGISTRY_URL}
186187
- REGISTRY_USER=${REGISTRY_USER}
187188
- REGISTRY_PW=${REGISTRY_PW}
189+
- SWARM_STACK_NAME=${SWARM_STACK_NAME}
188190
depends_on:
189191
- rabbit
190192
- postgres

services/sidecar/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ ENV PATH "/home/scu/.local/bin:$PATH"
2121
ENV SC_PIP pip3 --no-cache-dir
2222
ENV SC_BUILD_TARGET base
2323

24+
# used for finding the volumes
25+
ENV SWARM_STACK_NAME = ''
26+
2427
EXPOSE 8080
2528

2629
VOLUME /home/scu/input

services/sidecar/src/sidecar/core.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def __init__(self):
5858
# current task
5959
self._task = None
6060

61+
# stack name
62+
self._stack_name = None
63+
6164
# executor options
6265
self._executor = ExecutorSettings()
6366

@@ -278,6 +281,9 @@ def initialize(self, task, user_id):
278281
# volume paths for car container (w/o prefix)
279282
self._docker.env = ["{}_FOLDER=/{}".format(name.upper(), tail) for name, tail in tails.items()]
280283

284+
# stack name, should throw if not set
285+
self._stack_name = os.environ["SWARM_STACK_NAME"]
286+
281287
# config nodeports
282288
node_ports.node_config.USER_ID = user_id
283289
node_ports.node_config.NODE_UUID = task.node_id
@@ -304,9 +310,9 @@ def process(self):
304310
docker_image = self._docker.image_name + ":" + self._docker.image_tag
305311
self._docker.client.containers.run(docker_image, "run",
306312
detach=False, remove=True,
307-
volumes = {'services_input' : {'bind' : '/input'},
308-
'services_output' : {'bind' : '/output'},
309-
'services_log' : {'bind' : '/log'}},
313+
volumes = {'{}_input'.format(self._stack_name) : {'bind' : '/input'},
314+
'{}_output'.format(self._stack_name) : {'bind' : '/output'},
315+
'{}_log'.format(self._stack_name) : {'bind' : '/log'}},
310316
environment=self._docker.env)
311317
except docker.errors.ContainerError as _e:
312318
log.exception("Run container returned non zero exit code %s", str(_e))

0 commit comments

Comments
 (0)