forked from elighcash/microweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
96 lines (61 loc) · 2.1 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
import os
from fabric.api import env
from fabric.api import sudo
from fabric.api import prefix
from fabric.contrib.project import rsync_project
from fabric.context_managers import settings
from contextlib import contextmanager
env.hosts = []
env.serve_root = '/srv/www/django'
env.project_name = 'microweb'
env.virtualenv_name = 'microwebenv'
env.project_root = os.path.join(env.serve_root, env.project_name)
env.virtualenv_root = os.path.join(env.serve_root, env.virtualenv_name)
env.requirements_path = os.path.join(env.project_root, 'requirements.txt')
env.activate = 'source %s' % os.path.join(env.virtualenv_root, 'bin/activate')
@contextmanager
def activate_virtualenv():
with prefix(env.activate):
yield
def dev_env():
env.hosts.append('wpy01.dev.microcosm.cc')
def dev2_env():
env.hosts.append('wpyrapha.dev.microcosm.cc')
def prod_env():
env.hosts.append('wpy01.microcosm.cc:2020')
def test_env():
env.hosts.append('deployment@dev.microco.sm')
def destroy_virtualenv():
sudo('rm -rf %s' % env.virtualenv_root, user='django')
def create_virtualenv():
sudo('virtualenv %s' % env.virtualenv_root, user='django')
def install_requirements():
with activate_virtualenv():
sudo('pip install -r %s' % env.requirements_path, user='django')
def collectstatic():
with activate_virtualenv():
sudo('python %s collectstatic --noinput' % os.path.join(env.project_root, 'manage.py'), user='django')
def rsync():
rsync_project(
env.serve_root,
extra_opts='--exclude .git/ --exclude ENV/ --delete --rsync-path="sudo -u django rsync"'
)
def start_service():
sudo('service microweb start', user='root')
def stop_service():
sudo('service microweb stop', user='root')
def restart_service():
sudo('service microweb restart', user='root')
def restart_memcached():
sudo('service memcached restart', user='root')
def first_deploy():
create_virtualenv()
rsync()
install_requirements()
collectstatic()
start_service()
def redeploy():
rsync()
install_requirements()
collectstatic()
restart_service()