Skip to content
Snippets Groups Projects
Commit 491ae1fa authored by Loraine Gueguen's avatar Loraine Gueguen
Browse files

replace call() with run(). Factorize run_command() and...

replace call() with run(). Factorize run_command() and run_docker_stack_deploy(service, working_dir)
parent 9095ecff
No related branches found
No related tags found
2 merge requests!12Release_2.0 next,!9Release 2.0 (merge dev to master)
...@@ -236,7 +236,6 @@ def make_traefik_compose_files(config, main_dir): ...@@ -236,7 +236,6 @@ def make_traefik_compose_files(config, main_dir):
# Return to main directory # Return to main directory
os.chdir(main_dir) os.chdir(main_dir)
def create_mounts(working_dir, main_dir): def create_mounts(working_dir, main_dir):
""" """
Create the folders (volumes) required by a container (to see required volumes, check their compose file) Create the folders (volumes) required by a container (to see required volumes, check their compose file)
...@@ -287,6 +286,12 @@ def create_mounts(working_dir, main_dir): ...@@ -287,6 +286,12 @@ def create_mounts(working_dir, main_dir):
logging.critical("Cannot access %s, exiting" % main_dir) logging.critical("Cannot access %s, exiting" % main_dir)
sys.exit(exc) sys.exit(exc)
def run_command(command, working_dir):
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=working_dir)
def run_docker_stack_deploy(service, working_dir):
run_command(["docker", "stack", "deploy", "-c", "./docker-compose.yml", service], working_dir)
def deploy_stacks(input_list, main_dir, deploy_traefik): def deploy_stacks(input_list, main_dir, deploy_traefik):
""" """
This function first deploys/redeploys the traefik stack, then deploys/redeploys the organism stack, then redeploys the traefik stack This function first deploys/redeploys the traefik stack, then deploys/redeploys the organism stack, then redeploys the traefik stack
...@@ -296,7 +301,7 @@ def deploy_stacks(input_list, main_dir, deploy_traefik): ...@@ -296,7 +301,7 @@ def deploy_stacks(input_list, main_dir, deploy_traefik):
""" """
main_dir = os.path.abspath(main_dir) main_dir = os.path.abspath(main_dir)
os.chdir(main_dir) traefik_dir = os.path.join(main_dir, "traefik")
# Get species for which to deploy the stacks # Get species for which to deploy the stacks
# Uses the get_unique_species_list method from utilities to deploy a stack only for the "species" level (i.e genus_species) # Uses the get_unique_species_list method from utilities to deploy a stack only for the "species" level (i.e genus_species)
...@@ -305,31 +310,22 @@ def deploy_stacks(input_list, main_dir, deploy_traefik): ...@@ -305,31 +310,22 @@ def deploy_stacks(input_list, main_dir, deploy_traefik):
if deploy_traefik: if deploy_traefik:
# Create the swarm cluster if needed # Create the swarm cluster if needed
logging.info("Initializing docker swarm (adding node)") logging.info("Initializing docker swarm (adding node)")
subprocess.call(["docker", "swarm", "init"], run_command(["docker", "swarm", "init"], main_dir)
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=main_dir)
# Deploy traefik stack # Deploy traefik stack
logging.info("Deploying traefik stack") logging.info("Deploying traefik stack")
os.chdir("./traefik") run_docker_stack_deploy("traefik", traefik_dir)
subprocess.call(["docker", "stack", "deploy", "-c", "./docker-compose.yml", "traefik"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=".")
os.chdir(main_dir)
# Deploy individual species stacks # Deploy individual species stacks
for sp in to_deploy_species_li: for sp in to_deploy_species_li:
os.chdir(sp) sp_dir = os.path.join(main_dir, sp)
logging.info("Deploying %s stack" % sp) logging.info("Deploying %s stack" % sp)
subprocess.call(["docker", "stack", "deploy", "-c", "./docker-compose.yml", "{0}_{1}".format(sp.split("_")[0], sp.split("_")[1])], run_docker_stack_deploy("{0}_{1}".format(sp.split("_")[0], sp.split("_")[1]), sp_dir)
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=".")
logging.info("Deployed %s stack" % sp) logging.info("Deployed %s stack" % sp)
os.chdir(main_dir)
# Update traefik stack # Update traefik stack
logging.info("Updating traefik stack") logging.info("Updating traefik stack")
os.chdir("./traefik") run_docker_stack_deploy("traefik", traefik_dir)
subprocess.call(["docker", "stack", "deploy", "-c", "./docker-compose.yml", "traefik"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=".")
os.chdir(main_dir)
if __name__ == "__main__": if __name__ == "__main__":
...@@ -400,7 +396,6 @@ if __name__ == "__main__": ...@@ -400,7 +396,6 @@ if __name__ == "__main__":
# Starting # Starting
logging.info("gga_init.py called for %s %s", deploy_stack_for_current_organism.genus, deploy_stack_for_current_organism.species) logging.info("gga_init.py called for %s %s", deploy_stack_for_current_organism.genus, deploy_stack_for_current_organism.species)
logging.debug("Jbrowse url to %s %s %s %s", deploy_stack_for_current_organism.genus, deploy_stack_for_current_organism.species, deploy_stack_for_current_organism.sex, deploy_stack_for_current_organism.strain)
# Make/update directory tree # Make/update directory tree
deploy_stack_for_current_organism.make_directory_tree() deploy_stack_for_current_organism.make_directory_tree()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment