Skip to content

Commit cfa55ae

Browse files
authored
Allow changing ports services (#810) (#812)
allow dynamic allocation of published port by the swarm travis optimisation: only pull cache if it is necessary to build
1 parent 47373d3 commit cfa55ae

File tree

9 files changed

+51
-51
lines changed

9 files changed

+51
-51
lines changed

.env-devel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ POSTGRES_DB=simcoredb
99
POSTGRES_HOST=postgres
1010
POSTGRES_PORT=5432
1111

12+
RABBIT_HOST=rabbit
13+
RABBIT_PORT=5672
1214
RABBITMQ_USER=simcore
1315
RABBITMQ_PASSWORD=simcore
1416
RABBITMQ_PROGRESS_CHANNEL=comp.backend.channels.progress

ops/travis/build/test-images

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ install() {
1616
}
1717

1818
before_script() {
19-
make pull-cache || true
19+
{
20+
make pull-cache
21+
} || {
22+
# if this is the very first build in a branch
23+
# there is no cache available so let's use the main one if possible
24+
if [[ -v DOCKER_REGISTRY ]]; then
25+
branch_registry=${DOCKER_REGISTRY}
26+
export DOCKER_REGISTRY=itisfoundation
27+
# try getting the main cache, and set back the DOCKER_REGISTRY if it fails...
28+
make pull-cache || export DOCKER_REGISTRY=${branch_registry}
29+
fi
30+
} || true
2031
make pull || true
2132
}
2233

ops/travis/integration-testing/simcore-sdk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ before_script() {
2929
then
3030
pip freeze
3131
# pull the test images if registry is set up, else build the images
32-
make pull-cache || true
33-
make pull || make build
32+
make pull || ((make pull-cache || true) && make build)
3433
docker images
3534
fi
3635
}

ops/travis/integration-testing/webserver

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ install() {
1818

1919
before_script() {
2020
pip list -v
21-
make pull-cache || true
22-
make pull || make build
21+
make pull || ((make pull-cache || true) && make build)
2322
docker images
2423
}
2524

ops/travis/system-testing/build_and_run

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ before_install() {
1414
install() {
1515
bash ops/travis/helpers/ensure_python_pip
1616
pip3 install -r ops/travis/system-testing/requirements.txt
17-
make pull-cache || true
18-
make pull || make build
17+
make pull || ((make pull-cache || true) && make build)
1918
}
2019
2120
before_script() {

services/docker-compose.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
org.label-schema.vcs-url: "https://github.com/ITISFoundation/osparc-simcore"
1616
org.label-schema.vcs-ref: "${VCS_REF}"
1717
ports:
18-
- '8043:8043'
18+
- '8043'
1919
deploy:
2020
placement:
2121
constraints:
@@ -36,7 +36,7 @@ services:
3636
org.label-schema.vcs-url: "https://github.com/ITISFoundation/osparc-simcore"
3737
org.label-schema.vcs-ref: "${VCS_REF}"
3838
ports:
39-
- '8001:8080'
39+
- '8080'
4040
environment:
4141
# on Windows follow http://www.computerperformance.co.uk/powershell/powershell_profile_ps1.htm
4242
# currently needs to set $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1 in powershell to make this works
@@ -121,6 +121,8 @@ services:
121121
- POSTGRES_DB=${POSTGRES_DB}
122122
- POSTGRES_HOST=${POSTGRES_HOST}
123123
- POSTGRES_PORT=${POSTGRES_PORT}
124+
- RABBIT_HOST=${RABBIT_HOST}
125+
- RABBIT_PORT=${RABBIT_PORT}
124126
- RABBITMQ_USER=${RABBITMQ_USER}
125127
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
126128
- RABBITMQ_PROGRESS_CHANNEL=${RABBITMQ_PROGRESS_CHANNEL}
@@ -165,8 +167,6 @@ services:
165167
- output:/home/scu/output
166168
- log:/home/scu/log
167169
- /var/run/docker.sock:/var/run/docker.sock
168-
ports:
169-
- "8000:8000"
170170
environment:
171171
- RABBITMQ_USER=${RABBITMQ_USER}
172172
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
@@ -209,7 +209,7 @@ services:
209209
org.label-schema.vcs-url: "https://github.com/ITISFoundation/osparc-simcore"
210210
org.label-schema.vcs-ref: "${VCS_REF}"
211211
ports:
212-
- "11111:8080"
212+
- "8080"
213213
environment:
214214
- APIHUB_HOST=apihub
215215
- APIHUB_PORT=8043
@@ -243,8 +243,8 @@ services:
243243
- RABBITMQ_DEFAULT_USER=${RABBITMQ_USER}
244244
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD}
245245
ports:
246-
- "5672:5672"
247-
- "15672:15672"
246+
- "5672"
247+
- "15672"
248248
#--------------------------------------------------------------------
249249
postgres:
250250
image: postgres:10
@@ -255,15 +255,15 @@ services:
255255
volumes:
256256
- postgres:/var/lib/postgresql/data
257257
ports:
258-
- "5432:5432"
258+
- "5432"
259259
#--------------------------------------------------------------------
260260
minio:
261261
image: minio/minio
262262
environment:
263263
- MINIO_ACCESS_KEY=12345678
264264
- MINIO_SECRET_KEY=12345678
265265
ports:
266-
- "9001:9000"
266+
- "9000"
267267
command: server /data
268268
volumes:
269269
input:

services/web/server/src/simcore_service_webserver/config/server-docker-dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ db:
2121
host: ${POSTGRES_HOST}
2222
port: ${POSTGRES_PORT}
2323
rabbit:
24+
host: ${RABBIT_HOST}
25+
port: ${RABBIT_PORT}
2426
user: ${RABBITMQ_USER}
2527
password: ${RABBITMQ_PASSWORD}
2628
channels:

services/web/server/tests/integration/conftest.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from pathlib import Path
88
from typing import Dict
99

10+
import docker
1011
import pytest
1112
import trafaret_config
1213
import yaml
13-
1414
from simcore_service_webserver.application_config import app_schema
1515
from simcore_service_webserver.cli import create_environ
1616
from simcore_service_webserver.resources import resources as app_resources
@@ -38,7 +38,7 @@ def here():
3838
return Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
3939

4040
@pytest.fixture(scope="module")
41-
def webserver_environ(request, devel_environ, services_docker_compose) -> Dict[str, str]:
41+
def webserver_environ(request, devel_environ, services_docker_compose, docker_stack) -> Dict[str, str]:
4242
""" Environment variables for the webserver application
4343
4444
"""
@@ -53,18 +53,21 @@ def webserver_environ(request, devel_environ, services_docker_compose) -> Dict[s
5353

5454
# get the list of core services the test module wants
5555
core_services = getattr(request.module, 'core_services', [])
56-
5756
# OVERRIDES:
5857
# One of the biggest differences with respect to the real system
5958
# is that the webserver application is replaced by a light-weight
6059
# version tha loads only the subsystems under test. For that reason,
6160
# the test webserver is built-up in webserver_service fixture that runs
6261
# on the host.
6362
for name in core_services:
63+
if 'ports' not in services_docker_compose['services'][name]:
64+
continue
65+
66+
# published port is sometimes dynamically defined by the swarm
67+
6468
environ['%s_HOST' % name.upper()] = '127.0.0.1'
65-
environ['%s_PORT' % name.upper()] = \
66-
services_docker_compose['services'][name]['ports'][0].split(':')[0] # takes port exposed
67-
# to swarm boundary since webserver is installed in the host and therefore outside the swarm's network
69+
environ['%s_PORT' % name.upper()] = get_service_published_port(name)
70+
# to swarm boundary since webserver is installed in the host and therefore outside the swarm's network
6871
from pprint import pprint
6972
pprint(environ)
7073
return environ
@@ -77,9 +80,6 @@ def _recreate_config_file():
7780
cfg = yaml.safe_load(f)
7881
# test webserver works in host
7982
cfg["main"]['host'] = '127.0.0.1'
80-
cfg["rabbit"]["host"] = '127.0.0.1'
81-
cfg["rabbit"]["port"] = "5672"
82-
cfg["director"]["host"] = "127.0.0.1"
8383

8484
with config_file_path.open('wt') as f:
8585
yaml.dump(cfg, f, default_flow_style=False)
@@ -90,7 +90,6 @@ def _recreate_config_file():
9090
config_environ = {}
9191
config_environ.update(webserver_environ)
9292
config_environ.update( create_environ(skip_host_environ=True) ) # TODO: can be done monkeypathcing os.environ and calling create_environ as well
93-
9493
# validates
9594
cfg_dict = trafaret_config.read_and_validate(config_file_path, app_schema, vars=config_environ)
9695

@@ -114,3 +113,17 @@ def resolve_environ(service, environ):
114113
value = environ.get(value, value)
115114
_environs[key] = value
116115
return _environs
116+
117+
def get_service_published_port(service_name: str) -> str:
118+
published_port = "-1"
119+
client = docker.from_env()
120+
services = [x for x in client.services.list() if service_name in x.name]
121+
if not services:
122+
return published_port
123+
service_endpoint = services[0].attrs["Endpoint"]
124+
125+
if "Ports" not in service_endpoint or not service_endpoint["Ports"]:
126+
return published_port
127+
128+
published_port = service_endpoint["Ports"][0]["PublishedPort"]
129+
return str(published_port)

services/web/server/tests/unit/test_rest.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,3 @@ async def test_frontend_config(client):
115115

116116
data, _ = await assert_status(response, web.HTTPOk)
117117
assert data["invitation_required"] is enabled
118-
119-
120-
@pytest.mark.skip(reason="SAN: this must be added to ensure easier transition")
121-
async def test_start_pipeline(client):
122-
123-
resp = await client.post("/start_pipeline",
124-
json={
125-
"project_id":"asdfsk-sdfsdgsd-sdfsfd-sdfsd",
126-
"workbench":{
127-
"eroiuriet-dsffdgjh-eriter-dfdfg":{
128-
129-
}
130-
}
131-
132-
})
133-
assert resp.status == 200
134-
135-
payload = await resp.json()
136-
data, error = tuple(payload.get(k) for k in ('data', 'error'))
137-
138-
assert data
139-
assert not error
140-
141-
assert data['name'] == 'simcore_service_webserver'
142-
assert data['status'] == 'SERVICE_RUNNING'

0 commit comments

Comments
 (0)