This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
71 lines (53 loc) · 1.75 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
from shutil import copytree, copy
from fabric.api import cd, run, local, lcd, put
from fabric.contrib.files import exists
SERVICE_NAME = 'tinkoff'
BUILD_PATH = 'build'
BUILD_FILENAME = 'build.tar.gz'
BUILD_FOLDERS = ['requirements', 'etc', 'tj_feed']
BUILD_FILES = []
APP_PATH = 'current'
DEPLOY_PATH = 'deploy'
BACKUP_PATH = 'backup'
VENV_PATH = 'venv'
LOG_PATH = 'logs'
def prepare_destination_host():
"""
Init destination host structure for project
"""
if not exists(APP_PATH):
run(f'mkdir -p {APP_PATH}')
if not exists(VENV_PATH):
run(f'python3.9 -m venv {VENV_PATH}')
run(f'{VENV_PATH}/bin/pip install --upgrade pip')
if not exists(LOG_PATH):
run(f'mkdir -p {LOG_PATH}')
if exists(DEPLOY_PATH):
run(f'rm -rf {DEPLOY_PATH}')
def deployment():
"""
Deploy app and server configs
"""
# make local build
os.mkdir(BUILD_PATH)
for folder in BUILD_FOLDERS:
copytree(folder, os.path.join(BUILD_PATH, folder))
for filename in BUILD_FILES:
copy(filename, os.path.join(BUILD_PATH, filename))
with lcd(BUILD_PATH):
local(f'tar -czf ../{BUILD_FILENAME} .')
# load build to host
run('mkdir -p %s' % DEPLOY_PATH)
put(BUILD_FILENAME, DEPLOY_PATH)
with cd(DEPLOY_PATH):
run(f'tar -xzf {BUILD_FILENAME}')
run(f'{VENV_PATH}/bin/pip install -r %s --upgrade' % os.path.join(DEPLOY_PATH, 'requirements', 'common.txt'))
if exists(BACKUP_PATH):
run('rm -rf %s' % BACKUP_PATH)
run('mv %s %s' % (APP_PATH, BACKUP_PATH))
run('mv %s %s' % (DEPLOY_PATH, APP_PATH))
run('crontab %s' % os.path.join(APP_PATH, 'etc', 'crontab.txt'))
run('supervisorctl restart tinkoff')