-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
122 lines (96 loc) · 3.04 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
111
112
113
114
115
116
117
118
119
120
121
122
from fabric.api import *
from fabric.contrib.files import upload_template
env.hosts = ['54.191.70.60']
env.user = 'ubuntu'
env.key_filename = '~/.ssh/r_blog_analytics.pem'
env.shell = "/bin/bash -l -i -c"
env.use_ssh_config = True
env.project_name = "rocketu_blog_analytics"
from fabric.colors import *
from fabric.decorators import task
from fabric.operations import local
def restart_app():
sudo("service supervisor restart")
sudo("service nginx restart")
@task
def deploy():
with prefix("workon blog_analytics"):
with cd("/home/ubuntu/ru_blog_analytics"):
run("git pull origin master")
run("pip install -r requirements.txt")
run("python manage.py migrate")
run("python manage.py collectstatic --noinput")
restart_app()
@task
def setup_postgres(database_name, password):
sudo("adduser {}".format(database_name))
sudo("apt-get install postgresql postgresql-contrib libpq-dev")
with settings(sudo_user='postgres'):
sudo("createuser {}".format(database_name))
sudo("createdb {}".format(database_name))
alter_user_statement = "ALTER USER {} WITH PASSWORD '{}';".format(database_name, password)
sudo('psql -c "{}"'.format(alter_user_statement))
@task
def setup_nginx(project_name, server_name):
"""
$ fab setup_nginx:rocketu_blog_analytics,54.191.70.60
:param project_name:
:param server_name:
:return:
"""
upload_template("./deploy/nginx.conf",
"/etc/nginx/sites-enabled/{}.conf".format(project_name),
{'server_name': server_name},
use_sudo=True,
backup=False)
restart_app()
@task
def setup_gunicorn(project_name, proc_name):
"""
project name and proc name should be the same,
but are not in my example
$ fab setup_gunicorn:ru_blog_analytics,rocketu_blog_analytics
:param project_name:
:param proc_name:
:return:
"""
upload_template("./deploy/gunicorn.conf.py",
"{}/gunicorn.conf.py".format(project_name),
{'proc_name': proc_name},
)
restart_app()
@task
def setup_supervisor(project_name, server_name):
"""
Need to finish
https://students.rocketu.com/week8/2_pm/#/9
:param project_name:
:param server_name:
:return:
"""
upload_template("./deploy/supervisor.conf",
"/etc/supervisor/conf.d/{}.conf".format(project_name),
{'server_name': server_name},
use_sudo=True,
backup=False)
restart_app()
# @task
# def ubuntu_hello():
# run("lsb_release -a")
@task
def ubuntu_hello():
with hide("stdout"):
output = run("lsb_release -a")
print(yellow(output))
@task
def hello():
print("I'm alive!")
@task
def goodbye():
print(green("I'm alive!"))
@task
def create_file(file_name):
local("touch ~/Desktop/{}.txt".format(file_name))
@task
def create_dir(pathname, dir_name):
local("mkdir ~/{}/{}".format(pathname, dir_name))