@@ -420,38 +420,32 @@ def box_install(args):
420420 # start box with updated docker-compose.yml
421421 box_start (args )
422422
423- # get internal IP of new container
424- # (linking only those container names that appear there)
425- #TODO: AFTER SOLVING A TODO ONLY REMOVE THE "TODO:" FROM THE LINE!!!
426- #TODO: find out the containers to link, e.g. by reading out nginx.conf
427- #TODO: currently, this only gets the IP if there is a container that by coincidence has the same name as the installer
428- container_ip = subprocess .check_output (["docker" , "inspect" ,
429- "-f" , "'{{ .NetworkSettings.IPAddress }}'" , service_name ]).replace ("'" , "" ).strip ()
430-
431- entries_list = []
432- #separator_location="location"
433- separator_http = "http"
434- # write IP into nginx.conf
435- # taken from http://stackoverflow.com/questions/13089234/replacing-text-in-a-file-with-python
436- with open (join (servicedir , service_name , "nginx.conf" )) as infile , open (join (servicedir , service_name , "nginx." + service_name + ".conf" ), 'w' ) as outfile :
423+ #TODO: AFTER SOLVING A TODO ONLY REMOVE THE "TODO:" NOT THE WHOLE LINE!!!
424+
425+ proxied_servers = []
426+ proxied_ips = {}
427+
428+ # parse nginx.conf to get a list of all proxied containers
429+ #TODO: make sure to only read URLs after a "proxy_pass"
430+ with open (join (servicedir , service_name , "nginx.conf" )) as f :
431+ proxied_servers = [w .replace ('http://' , '' ) for w in re .findall ('(https?:\/\/[A-Za-z0-9]+)' ,f .read ())]
432+
433+ # now get the IPs for the proxied containers
434+ for proxy in proxied_servers :
435+ container_ip = subprocess .check_output (["docker" , "inspect" ,
436+ "-f" , "'{{ .NetworkSettings.IPAddress }}'" , proxy ]).replace ("'" , "" ).strip ()
437+ proxied_ips [proxy ] = container_ip
438+
439+ # finally, replace the values
440+ with open (join (servicedir , service_name , "nginx.conf" )) as infile , open (join (servicedir , service_name , "nginx.adapted.conf" ), 'w' ) as outfile :
437441 for line in infile :
438- if separator_http in line :
439- # for line in infile:
440- # print("Read the following line:{}".format(line))
441- entry_name = re .search (r'\//(.*)\:' , line .split ()[1 ]).group (0 )[2 :- 1 ]
442- entries_list .extend (entry_name )
443- print ("The following location will be added to the Adapter: {}" .format (entry_name ))
444- for entry_name in entries_list :
445- replacements = {'http://' + entry_name :'http://' + container_ip }
446- for src , target in replacements .iteritems ():
447- line = line .replace (src , target )
448- outfile .write (line )
449-
450- # copy nginx.conf into container
451- #TODO: run the script directly from python
452- subprocess .check_output (["./add_nginx_conf.sh" , service_name ])
442+ for src , target in proxied_ips .iteritems ():
443+ line = line .replace ("http://" + src , "http://" + target )
444+ outfile .write (line )
453445
454- #TODO: send signal HUP to adapter container (currently done from shell)
446+ # copy nginx.adapted.conf into container
447+ #TODO: run the script directly from python, including sending HUP signal to adapter
448+ subprocess .check_output (["./add_nginx_conf.sh" , service_name ])
455449
456450 return 0
457451
@@ -464,10 +458,13 @@ def box_start(args):
464458 if not check_tls (dir , url ):
465459 return 1
466460 except :
467- print ("This directory does not seem to contain a LayersBox " )
461+ print ("This directory does not seem to contain a Layers Box configuration. " )
468462 return 1
469463 subprocess .check_output (["docker-compose" , "up" , "-d" ])
470- print ("You can reach LayersBox now at https://{}/" .format (url ))
464+
465+ #TODO: regenerate nginx.adapted.conf files for all proxied services
466+
467+ print ("You can now reach your Layers Box at https://{}/" .format (url ))
471468 return 0
472469
473470
@@ -476,7 +473,7 @@ def box_stop(args):
476473 try :
477474 read_url (args .directory )
478475 except :
479- print ("This directory does not seem to contain a LayersBox " )
476+ print ("This directory does not seem to contain a Layers Box configuration. " )
480477 return 1
481478 subprocess .check_output (["docker-compose" , "stop" ])
482479 return 0
0 commit comments