forked from MapStory/mapstory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
199 lines (114 loc) · 4.55 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from fabric.api import abort, cd, env, prefix, run, sudo, shell_env
from fabric.contrib.console import confirm
"""
Example Usage: fab dev collect runserver
The command above will use Fabric to connect to dev environment, collect static files, and run the django server.
"""
env.activate = 'source /home/mapstory/.virtualenvs/mapstory/bin/activate'
env.remote_interrupt = True
env.notify_message = 'No slacking here! New features have been deployed to http://mapstory.beta.boundlessgeo.com so check it out and let us know what you think!'
def __check_config():
if 'config' not in env:
abort('You must specify a configuration to use this method')
def dev():
"""
Specifies the development configuration
"""
env.user = 'vagrant'
env.hosts = ['192.168.56.151']
env.key_filename = '~/.vagrant.d/insecure_private_key'
env.config = 'local'
def beta():
"""
Specifies the beta configuration
"""
env.user = 'ubuntu'
env.hosts = ['mapstory.beta.boundlessgeo.com']
env.key_filename = '~/.ssh/mapstory-v2.pem'
env.config = 'beta'
def update(branch='master'):
"""
Update repository to specified branch
TODO: fix this to fetch, checkout, pull
"""
with cd('/srv/git/mapstory/geonode'):
sudo('git pull mapstory/geonode {0}'.format(branch), user='mapstory')
with cd('/srv/git/mapstory/mapstory-geonode'):
sudo('git reset --hard', user='mapstory')
sudo('git pull', user='mapstory')
def pip(download=False):
"""
Reinstall python requirements
"""
with cd('/srv/git/mapstory/mapstory-geonode'):
with prefix(env.activate):
if download:
sudo('pip install --download install/ --exists-action '
'i -r requirements/.txt', user='mapstory')
sudo('pip install -r requirements.txt', user='mapstory')
def collect():
"""
Collect static files for geonode and mapstory-geonode
"""
with prefix(env.activate):
with cd('/srv/git/mapstory/geonode/geonode/static'):
run('npm install')
run('bower install --noinput')
sudo('grunt copy', user='mapstory')
with cd('/srv/git/mapstory/mapstory-geonode/mapstory/static'):
run('npm install')
run('bower install --noinput')
sudo('grunt less', user='mapstory')
with cd('/srv/git/mapstory/mapstory-geonode'):
sudo('python manage.py collectstatic --link --noinput --ignore node_modules', user='mapstory')
def runserver():
"""
Stops Gunicorn and runs django runserver
"""
__check_config()
if (env.config != 'local' and
not confirm('This is designed to only be run locally. Continue?',
default=False)):
abort('Aborting at users request')
sudo('supervisorctl stop gunicorn-django')
with cd('/srv/git/mapstory/mapstory-geonode'):
with prefix(env.activate):
sudo('python manage.py runserver', user='www-data')
sudo('supervisorctl start gunicorn-django')
def restart():
"""
Restart Nginx, Geoserver, and Gunicorn on system
"""
sudo('supervisorctl restart gunicorn-django')
sudo('service nginx restart')
sudo('service tomcat7 restart')
sudo('supervisorctl restart mapstory-celery')
def notify(channel='#general', username='webhookbot',
message=env.notify_message, icon=':ship:',
end_point='https://hooks.slack.com/services/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'):
"""
Notify others via a slackchat message
"""
payload = 'payload={"channel": "%s", "username": "%s", "text": "%s", "icon_emoji": "%s"}'% (channel, username,
message, icon)
curl = "curl -X POST --data-urlencode '{0}' {1}".format(payload, end_point)
run(curl)
def syncdb():
"""
Synchronize the database models
"""
with cd('/srv/git/mapstory/mapstory-geonode'):
with prefix(env.activate):
sudo('python manage.py syncdb --noinput --no-initial-data', user='mapstory')
def tail(logfile='gunicorn-django', count=30):
"""
Tail the app log file
"""
run('tail -n {0} -f /var/log/{1}.log'.format(count, logfile))
def test():
"""
Synchronize the database models
"""
with cd('/srv/git/mapstory/mapstory-geonode'):
with prefix(env.activate):
sudo('python manage.py test mapstory.tests --settings=mapstory.settings.test_settings', user='mapstory')