Skip to content
Snippets Groups Projects
Commit 5538403f authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Parametrised webapp host+port and local docker registry host+port. Moved all...

Parametrised webapp host+port and local docker registry host+port. Moved all data (registry+shared) in the data_rosetta folder.
parent 1de86ae1
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ services: ...@@ -9,7 +9,7 @@ services:
- SAFEMODE=False - SAFEMODE=False
privileged: true privileged: true
volumes: volumes:
- ./data/shared:/shared - ./data_rosetta/shared:/shared
# - ./data/singularity_cache:/rosetta/.singularity/cache # Not working, check permissions... # - ./data/singularity_cache:/rosetta/.singularity/cache # Not working, check permissions...
ports: ports:
- "8590:8590" - "8590:8590"
...@@ -23,7 +23,7 @@ services: ...@@ -23,7 +23,7 @@ services:
- SAFEMODE=False - SAFEMODE=False
privileged: true privileged: true
volumes: volumes:
- ./data/shared:/shared - ./data_rosetta/shared:/shared
ports: ports:
- "8591:8590" - "8591:8590"
- "5901:5900" - "5901:5900"
...@@ -33,7 +33,7 @@ services: ...@@ -33,7 +33,7 @@ services:
hostname: dregistry hostname: dregistry
image: "rosetta/dregistry" image: "rosetta/dregistry"
volumes: volumes:
- ./data/dregistry:/var/lib/registry - ./data_rosetta/dregistry:/var/lib/registry
ports: ports:
- "5000:5000" - "5000:5000"
...@@ -45,6 +45,10 @@ services: ...@@ -45,6 +45,10 @@ services:
- SAFEMODE=False - SAFEMODE=False
- DJANGO_LOG_LEVEL=CRITICAL - DJANGO_LOG_LEVEL=CRITICAL
- ROSETTA_LOG_LEVEL=DEBUG - ROSETTA_LOG_LEVEL=DEBUG
#- ROSETTA_WEBAPP_HOST=
#- ROSETTA_WEBAPP_PORT=8080
#- LOCAL_DOCKER_REGISTRY_HOST=
#- LOCAL_DOCKER_REGISTRY_PORT=5000
ports: ports:
- "8080:8080" - "8080:8080"
- "8000:8590" - "8000:8590"
......
...@@ -221,11 +221,9 @@ class agent_api(PublicGETAPI): ...@@ -221,11 +221,9 @@ class agent_api(PublicGETAPI):
except (Task.DoesNotExist, ValidationError): except (Task.DoesNotExist, ValidationError):
return HttpResponse('Unknown task uuid "{}"'.format(task_uuid)) return HttpResponse('Unknown task uuid "{}"'.format(task_uuid))
import socket
hostname = socket.gethostname()
webapp_ip = socket.gethostbyname(hostname)
host_conn_string = 'http://{}:8080'.format(webapp_ip) from.utils import get_webapp_conn_string
webapp_conn_string = get_webapp_conn_string()
action = request.GET.get('action', None) action = request.GET.get('action', None)
...@@ -275,7 +273,7 @@ while True: ...@@ -275,7 +273,7 @@ while True:
break break
logger.info(' - ports: "{},{},{}"'.format(port, port+1, port+2)) logger.info(' - ports: "{},{},{}"'.format(port, port+1, port+2))
response = urlopen("'''+host_conn_string+'''/api/v1/base/agent/?task_uuid={}&action=set_ip_port&ip={}&port={}".format(task_uuid, ip, port)) response = urlopen("'''+webapp_conn_string+'''/api/v1/base/agent/?task_uuid={}&action=set_ip_port&ip={}&port={}".format(task_uuid, ip, port))
response_content = response.read() response_content = response.read()
if response_content != 'OK': if response_content != 'OK':
logger.error(response_content) logger.error(response_content)
......
...@@ -169,6 +169,11 @@ class RemoteComputingManager(ComputingManager): ...@@ -169,6 +169,11 @@ class RemoteComputingManager(ComputingManager):
else: else:
raise NotImplementedError('Remote tasks not requiring keys are not yet supported') raise NotImplementedError('Remote tasks not requiring keys are not yet supported')
# Get webapp conn string
from.utils import get_webapp_conn_string
webapp_conn_string = get_webapp_conn_string()
# 1) Run the container on the host (non blocking) # 1) Run the container on the host (non blocking)
if task.container.type == 'singularity': if task.container.type == 'singularity':
...@@ -182,12 +187,8 @@ class RemoteComputingManager(ComputingManager): ...@@ -182,12 +187,8 @@ class RemoteComputingManager(ComputingManager):
else: else:
authstring = '' authstring = ''
import socket
hostname = socket.gethostname()
webapp_ip = socket.gethostbyname(hostname)
run_command = 'ssh -i {} -4 -o StrictHostKeyChecking=no {}@{} '.format(user_keys.private_key_file, user, host) run_command = 'ssh -i {} -4 -o StrictHostKeyChecking=no {}@{} '.format(user_keys.private_key_file, user, host)
run_command += '/bin/bash -c \'"wget {}:8080/api/v1/base/agent/?task_uuid={} -O /tmp/agent_{}.py &> /dev/null && export BASE_PORT=\$(python /tmp/agent_{}.py 2> /tmp/{}.log) && '.format(webapp_ip, task.uuid, task.uuid, task.uuid, task.uuid) run_command += '/bin/bash -c \'"wget {}/api/v1/base/agent/?task_uuid={} -O /tmp/agent_{}.py &> /dev/null && export BASE_PORT=\$(python /tmp/agent_{}.py 2> /tmp/{}.log) && '.format(webapp_conn_string, task.uuid, task.uuid, task.uuid, task.uuid)
run_command += 'export SINGULARITY_NOHTTPS=true && export SINGULARITYENV_BASE_PORT=\$BASE_PORT && {} '.format(authstring) run_command += 'export SINGULARITY_NOHTTPS=true && export SINGULARITYENV_BASE_PORT=\$BASE_PORT && {} '.format(authstring)
run_command += 'exec nohup singularity run --pid --writable-tmpfs --containall --cleanenv ' run_command += 'exec nohup singularity run --pid --writable-tmpfs --containall --cleanenv '
...@@ -295,6 +296,10 @@ class SlurmComputingManager(ComputingManager): ...@@ -295,6 +296,10 @@ class SlurmComputingManager(ComputingManager):
else: else:
raise NotImplementedError('Remote tasks not requiring keys are not yet supported') raise NotImplementedError('Remote tasks not requiring keys are not yet supported')
# Get webapp conn string
from.utils import get_webapp_conn_string
webapp_conn_string = get_webapp_conn_string()
# Get task computing parameters and set sbatch args # Get task computing parameters and set sbatch args
sbatch_args = '' sbatch_args = ''
if task.computing_options: if task.computing_options:
...@@ -314,6 +319,7 @@ class SlurmComputingManager(ComputingManager): ...@@ -314,6 +319,7 @@ class SlurmComputingManager(ComputingManager):
# Set output and error files # Set output and error files
sbatch_args += ' --output=\$HOME/{}.log --error=\$HOME/{}.log '.format(task.uuid, task.uuid) sbatch_args += ' --output=\$HOME/{}.log --error=\$HOME/{}.log '.format(task.uuid, task.uuid)
# 1) Run the container on the host (non blocking) # 1) Run the container on the host (non blocking)
if task.container.type == 'singularity': if task.container.type == 'singularity':
...@@ -326,13 +332,10 @@ class SlurmComputingManager(ComputingManager): ...@@ -326,13 +332,10 @@ class SlurmComputingManager(ComputingManager):
else: else:
authstring = '' authstring = ''
import socket
hostname = socket.gethostname()
webapp_ip = socket.gethostbyname(hostname)
run_command = 'ssh -i {} -4 -o StrictHostKeyChecking=no {}@{} '.format(user_keys.private_key_file, user, host) run_command = 'ssh -i {} -4 -o StrictHostKeyChecking=no {}@{} '.format(user_keys.private_key_file, user, host)
run_command += '\'bash -c "echo \\"#!/bin/bash\nwget {}:8080/api/v1/base/agent/?task_uuid={} -O \$HOME/agent_{}.py &> /dev/null && export BASE_PORT=\\\\\\$(python \$HOME/agent_{}.py 2> \$HOME/{}.log) && '.format(webapp_ip, task.uuid, task.uuid, task.uuid, task.uuid) run_command += '\'bash -c "echo \\"#!/bin/bash\nwget {}/api/v1/base/agent/?task_uuid={} -O \$HOME/agent_{}.py &> \$HOME/{}.log && export BASE_PORT=\\\\\\$(python \$HOME/agent_{}.py 2> \$HOME/{}.log) && '.format(webapp_conn_string, task.uuid, task.uuid, task.uuid, task.uuid, task.uuid)
run_command += 'export SINGULARITY_NOHTTPS=true && export SINGULARITYENV_BASE_PORT=\\\\\\$BASE_PORT && {} '.format(authstring) run_command += 'export SINGULARITY_NOHTTPS=true && export SINGULARITYENV_BASE_PORT=\\\\\\$BASE_PORT && {} '.format(authstring)
run_command += 'exec nohup singularity run --pid --writable-tmpfs --containall --cleanenv ' run_command += 'exec nohup singularity run --pid --writable-tmpfs --containall --cleanenv '
...@@ -340,7 +343,10 @@ class SlurmComputingManager(ComputingManager): ...@@ -340,7 +343,10 @@ class SlurmComputingManager(ComputingManager):
# Set registry # Set registry
if task.container.registry == 'docker_local': if task.container.registry == 'docker_local':
registry = 'docker://dregistry:5000/' # Get local Docker registry conn string
from.utils import get_local_docker_registry_conn_string
local_docker_registry_conn_string = get_local_docker_registry_conn_string()
registry = 'docker://{}/'.format(local_docker_registry_conn_string)
elif task.container.registry == 'docker_hub': elif task.container.registry == 'docker_hub':
registry = 'docker://' registry = 'docker://'
else: else:
......
import os
import traceback import traceback
import hashlib import hashlib
import random import random
...@@ -425,7 +426,43 @@ class dt_range(object): ...@@ -425,7 +426,43 @@ class dt_range(object):
return self.__next__() return self.__next__()
#================================
# Others
#================================
def debug_param(**kwargs): def debug_param(**kwargs):
for item in kwargs: for item in kwargs:
logger.critical('Param "{}": "{}"'.format(item, kwargs[item])) logger.critical('Param "{}": "{}"'.format(item, kwargs[item]))
def get_my_ip():
import socket
hostname = socket.gethostname()
my_ip = socket.gethostbyname(hostname)
return my_ip
def get_webapp_conn_string():
webapp_host = os.environ.get('ROSETTA_WEBAPP_HOST', get_my_ip())
webapp_port = os.environ.get('ROSETTA_WEBAPP_PORT', '8080')
webapp_conn_string = 'http://{}:{}'.format(webapp_host, webapp_port)
return webapp_conn_string
def get_local_docker_registry_conn_string():
local_docker_registry_host = os.environ.get('LOCAL_DOCKER_REGISTRY_HOST', 'dregistry')
local_docker_registry_port = os.environ.get('LOCAL_DOCKER_REGISTRY_PORT', '5000')
local_docker_registry_conn_string = '{}:{}'.format(local_docker_registry_host, local_docker_registry_port)
return local_docker_registry_conn_string
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment