-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
110 lines (91 loc) · 2.78 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from fabric.api import *
from fabric.colors import red
from fabric.contrib.files import upload_template
from settings import USER, PASS
from settings import HOSTS, DOMAIN, SUBDOMAIN
REPO = 'https://github.com/mitrofun/portfolio.git'
PROJECT_NAME = 'portfolio'
PROJECTS_DIR = 'projects'
PROJECT_DIR = '{projects_dir}/{project}'.format(projects_dir=PROJECTS_DIR, project=PROJECT_NAME)
env.hosts = HOSTS
def clone_project():
with cd(PROJECTS_DIR):
try:
run('git clone {repo}'.format(repo=REPO))
except:
print(red('dir {} already have, del dir and clone again'.format(PROJECT_NAME)))
run('rm -rf {project}'.format(project=PROJECT_NAME))
run('git clone {repo}'.format(repo=REPO))
def create_config(build):
if build:
env.root += 'build/'
context = {
'domain': env.domain,
'root': env.root
}
env.nginx = '{}/config/nginx.conf'.format(env.project_dir)
upload_template('config/nginx.template', env.nginx, context, use_jinja=True, )
def link_conf():
nginx_link = '/etc/nginx/sites-enabled/{}.conf'.format(env.domain)
sudo('ln -s {} {}'.format(env.nginx, nginx_link))
@task
def reload():
"""
Рестарт nginx
:return:
"""
sudo('nginx -s reload')
@task
def install_bower():
sudo('apt-get install nodejs -y')
sudo('apt-get install npm -y')
sudo('npm install -g bower')
sudo('ln -s /usr/bin/nodejs /usr/bin/node')
def bower_install():
with cd(env.root):
try:
run('bower i')
except:
install_bower()
run('bower i')
@task
def update(user=USER, pas=PASS):
"""
Загружаем последние изменения и рестартим nginx
:param user: Пользователь
:param pas: Пароль
:return: Обновление проекта
"""
env.user = user
env.password = pas
with cd(PROJECT_DIR):
run('git pull origin master')
run('npm i')
run('bundle install')
run('gulp clean')
run('gulp prod')
reload()
def initial_setting(user, pas):
env.user = user
env.password = pas
env.work = SUBDOMAIN
env.domain = '{}.{}'.format(SUBDOMAIN, DOMAIN)
env.project_dir = '/home/{user}/projects/{project}'.format(user=user, project=PROJECT_NAME)
env.root = '/home/{user}/projects/{project}/'.format(user=user, project=PROJECT_NAME)
@task(alias='deploy')
def config_deploy(user=USER, pas=PASS):
env.build = True
initial_setting(user, pas)
clone_project()
bower_install()
with cd(env.root):
run('npm i')
run('bundle install')
run('gulp clean')
run('gulp prod')
create_config(env.build)
link_conf()
reload()