77import docker
88import docker .errors
99
10- from bughog import config , worker
10+ from bughog import config
1111from bughog .parameters import ExperimentParameters
1212from bughog .version_control .state .base import State
1313from bughog .web .clients import Clients
@@ -19,22 +19,14 @@ class WorkerManager:
1919 def __init__ (self , subject_type : str , subject_name : str , max_nb_of_containers : int ) -> None :
2020 self .max_nb_of_containers = max_nb_of_containers
2121
22- if self .max_nb_of_containers == 1 :
23- logger .info ('Running in single container mode' )
24- else :
25- self .container_id_pool = Queue (maxsize = self .max_nb_of_containers )
26- for i in range (self .max_nb_of_containers ):
27- self .container_id_pool .put (i )
28- self .client = docker .from_env ()
29- self .worker_image_ref = self .__get_worker_image_ref (subject_type , subject_name )
22+ self .container_id_pool = Queue (maxsize = self .max_nb_of_containers )
23+ for i in range (self .max_nb_of_containers ):
24+ self .container_id_pool .put (i )
25+ self .client = docker .from_env ()
26+ self .worker_image_ref = self .__get_worker_image_ref (subject_type , subject_name )
3027
3128 def start_experiment (self , params : ExperimentParameters , state : State , blocking_wait = True ) -> None :
32- if self .max_nb_of_containers != 1 :
33- return self .__run_container (params , state , blocking_wait )
34-
35- # Single container mode
36- worker .run (params , state )
37- Clients .push_results_to_all ()
29+ return self .__run_container (params , state , blocking_wait )
3830
3931 def __run_container (self , params : ExperimentParameters , state : State , blocking_wait = True ) -> None :
4032 try :
@@ -71,8 +63,22 @@ def start_container_thread():
7163 except docker .errors .APIError :
7264 logger .error ('Could not consult list of active containers' , exc_info = True )
7365
66+ debug = bool (os .getenv ('DEVELOPMENT' ))
7467 container = None
7568 try :
69+ volumes = [
70+ os .path .join (host_pwd , '.devcontainer' ) + ':/app/.devcontainer:ro' ,
71+ os .path .join (host_pwd , '.vscode' ) + ':/app/.vscode:ro' ,
72+ os .path .join (host_pwd , 'config' ) + ':/app/config:ro' ,
73+ os .path .join (host_pwd , 'subject' ) + ':/app/subject:rw' ,
74+ os .path .join (host_pwd , 'logs' ) + ':/app/logs:rw' ,
75+ os .path .join (host_pwd , 'nginx/ssl' ) + ':/etc/nginx/ssl:ro' ,
76+ ]
77+ debug_kwargs = {}
78+ if debug :
79+ volumes .append (os .path .join (host_pwd , 'bughog' ) + ':/app/bughog:rw' )
80+ debug_kwargs ['ports' ] = {'5678/tcp' : 5678 }
81+ debug_kwargs ['environment' ] = {'DEVELOPMENT' : '1' }
7682 container = self .client .containers .run (
7783 self .worker_image_ref ,
7884 name = container_name ,
@@ -82,13 +88,9 @@ def start_container_thread():
8288 detach = True ,
8389 labels = ['bh_worker' ],
8490 command = [params .serialize (), state .serialize ()],
85- volumes = [
86- os .path .join (host_pwd , 'config' ) + ':/app/config:ro' ,
87- os .path .join (host_pwd , 'subject' ) + ':/app/subject:rw' ,
88- os .path .join (host_pwd , 'logs' ) + ':/app/logs:rw' ,
89- os .path .join (host_pwd , 'nginx/ssl' ) + ':/etc/nginx/ssl:ro' ,
90- ],
91+ volumes = volumes ,
9192 tmpfs = {'/memory' : 'exec,size=3g,mode=1777' },
93+ ** debug_kwargs ,
9294 )
9395 result = container .wait ()
9496 if result ['StatusCode' ] != 0 :
0 commit comments