Перенес запуск скриптов деплоя в общий файл
This commit is contained in:
parent
6b714a8486
commit
ea43f571ae
19
app/gitea/deploy.py
Normal file
19
app/gitea/deploy.py
Normal file
@ -0,0 +1,19 @@
|
||||
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"
|
||||
)
|
@ -1,23 +0,0 @@
|
||||
from fabric import Connection
|
||||
from invoke import task
|
||||
import shlex
|
||||
|
||||
# Run task with `invoke deploy`
|
||||
|
||||
APP_NAME = "gitea"
|
||||
SSH_HOST = f"{APP_NAME}@158.160.115.150"
|
||||
|
||||
|
||||
@task
|
||||
def deploy(c):
|
||||
print("Ready to setup remote host")
|
||||
with Connection(SSH_HOST) as c:
|
||||
c.put(
|
||||
local="docker-compose.yml",
|
||||
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"
|
||||
)
|
27
app/tasks.py
Normal file
27
app/tasks.py
Normal file
@ -0,0 +1,27 @@
|
||||
from invoke import task
|
||||
|
||||
SERVER_HOST_FILE = "../ansible/hosts_prod"
|
||||
DOKER_REGISTRY = "cr.yandex/crplfk0168i4o8kd7ade"
|
||||
|
||||
|
||||
@task(name="deploy:gitea")
|
||||
def deploy_gitea(context):
|
||||
from gitea.deploy import deploy
|
||||
|
||||
deploy(context, "gitea", ssh_host("gitea"))
|
||||
|
||||
|
||||
@task(name="deploy:wiki")
|
||||
def deploy_wiki(context):
|
||||
from wiki.deploy import deploy
|
||||
|
||||
deploy(context, "wiki", ssh_host("wiki"))
|
||||
|
||||
|
||||
def read_host():
|
||||
with open("../ansible/hosts_prod") as f:
|
||||
return f.read().strip()
|
||||
|
||||
|
||||
def ssh_host(app_name):
|
||||
return f"{app_name}@{read_host()}"
|
18
app/wiki/deploy.py
Normal file
18
app/wiki/deploy.py
Normal file
@ -0,0 +1,18 @@
|
||||
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"
|
||||
)
|
@ -1,26 +0,0 @@
|
||||
from fabric import Connection
|
||||
from invoke import task
|
||||
import subprocess
|
||||
import shlex
|
||||
|
||||
APP_NAME = "wiki"
|
||||
SSH_HOST = f"{APP_NAME}@158.160.115.150"
|
||||
DOCKER_REGISTRY = "cr.yandex/crplfk0168i4o8kd7ade"
|
||||
|
||||
|
||||
def run(args):
|
||||
return subprocess.run(args, check=True, capture_output=True).stdout
|
||||
|
||||
|
||||
@task
|
||||
def deploy(c):
|
||||
print("Ready to setup remote host")
|
||||
with Connection(SSH_HOST) as c:
|
||||
c.put(
|
||||
"docker-compose.yml",
|
||||
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"
|
||||
)
|
Loading…
Reference in New Issue
Block a user