Перенес код деплоя в основной скрипт
This commit is contained in:
		| @@ -1,19 +0,0 @@ | ||||
| from fabric import Connection | ||||
| import os | ||||
| import shlex | ||||
|  | ||||
|  | ||||
| def deploy(context, app_name, ssh_host): | ||||
|     docker_compose = os.path.join(os.path.dirname(__file__), "docker-compose.yml") | ||||
|     print("Deploy app from", docker_compose) | ||||
|     print("Start setup remote host", ssh_host) | ||||
|     with Connection(ssh_host) as c: | ||||
|         c.put( | ||||
|             local=docker_compose, | ||||
|             remote=f"/home/{app_name}/docker-compose.yml", | ||||
|         ) | ||||
|         c.run("cp .env .env.prod") | ||||
|         c.run("mkdir -p data") | ||||
|         c.run( | ||||
|             f"docker-compose --project-name {shlex.quote(app_name)} --env-file=.env.prod up --detach --remove-orphans" | ||||
|         ) | ||||
							
								
								
									
										38
									
								
								app/tasks.py
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								app/tasks.py
									
									
									
									
									
								
							| @@ -1,3 +1,6 @@ | ||||
| import os | ||||
| import shlex | ||||
| import fabric | ||||
| from invoke import task | ||||
|  | ||||
| SERVER_HOST_FILE = "../ansible/hosts_prod" | ||||
| @@ -6,22 +9,43 @@ DOKER_REGISTRY = "cr.yandex/crplfk0168i4o8kd7ade" | ||||
|  | ||||
| @task(name="deploy:gitea") | ||||
| def deploy_gitea(context): | ||||
|     from gitea.deploy import deploy | ||||
|  | ||||
|     deploy(context, "gitea", ssh_host("gitea")) | ||||
|     deploy("gitea", dirs=["data"]) | ||||
|  | ||||
|  | ||||
| @task(name="deploy:wiki") | ||||
| def deploy_wiki(context): | ||||
|     from wiki.deploy import deploy | ||||
|  | ||||
|     deploy(context, "wiki", ssh_host("wiki")) | ||||
|     deploy("wiki") | ||||
|  | ||||
|  | ||||
| def read_host(): | ||||
|     with open("../ansible/hosts_prod") as f: | ||||
|     with open(SERVER_HOST_FILE) as f: | ||||
|         return f.read().strip() | ||||
|  | ||||
|  | ||||
| def ssh_host(app_name): | ||||
|     return f"{app_name}@{read_host()}" | ||||
|  | ||||
|  | ||||
| def deploy(app_name: str, dirs=None): | ||||
|     docker_compose = os.path.join(app_name, "docker-compose.yml") | ||||
|     assert os.path.exists(docker_compose) | ||||
|     conn_str = ssh_host(app_name) | ||||
|     dirs = dirs or [] | ||||
|     print("Deploy app from", docker_compose) | ||||
|     print("Start setup remote host", conn_str) | ||||
|     with fabric.Connection(conn_str) as c: | ||||
|         print("Copy docker compose file to remote host") | ||||
|         c.put( | ||||
|             local=docker_compose, | ||||
|             remote=f"/home/{app_name}/docker-compose.yml", | ||||
|         ) | ||||
|         print("Copy environment file") | ||||
|         c.run("cp .env .env.prod") | ||||
|         for d in dirs: | ||||
|             print("Create remote directory", d) | ||||
|             c.run(f"mkdir -p {d}") | ||||
|         print("Up services") | ||||
|         c.run( | ||||
|             f"docker-compose --project-name {shlex.quote(app_name)} --env-file=.env.prod up --detach --remove-orphans" | ||||
|         ) | ||||
|     print("Done.") | ||||
|   | ||||
| @@ -1,18 +0,0 @@ | ||||
| from fabric import Connection | ||||
| import os | ||||
| import shlex | ||||
|  | ||||
|  | ||||
| def deploy(context, app_name, ssh_host): | ||||
|     docker_compose = os.path.join(os.path.dirname(__file__), "docker-compose.yml") | ||||
|     print("Deploy app from", docker_compose) | ||||
|     print("Start setup remote host", ssh_host) | ||||
|     with Connection(ssh_host) as c: | ||||
|         c.put( | ||||
|             local=docker_compose, | ||||
|             remote=f"/home/{app_name}/docker-compose.yml", | ||||
|         ) | ||||
|         c.run("cp .env .env.prod") | ||||
|         c.run( | ||||
|             f"docker-compose --project-name {shlex.quote(app_name)} --env-file=.env.prod up --detach --remove-orphans" | ||||
|         ) | ||||
		Reference in New Issue
	
	Block a user