-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
167 lines (136 loc) · 6.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
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
import os
from fabric.api import *
# the user to use for the remote commands
env.user = 'wdft'
# the servers where the commands are executed
env.hosts = ['midgewater.twdb.state.tx.us:22222']
WOFPY_DEPLOYMENTS_DIR = '/space/www/wofpy_deployments/'
CENTRAL_REGISTRY_DEPLOYMENTS_DIR = '/space/www/'
def pack_cbi():
pack('cbi')
def deploy_cbi():
pack('cbi')
deploy('cbi')
build_cbi_cache()
def deploy_tceq():
pack('tceq')
deploy('tceq')
copy_cache_file('tceq', 'tceq_pyhis_cache.db')
def deploy_tpwd():
pack('tpwd')
deploy('tpwd')
copy_cache_file('tpwd', 'tpwd_pyhis_cache.db')
def pack(app):
"""creates new source distribution as tarball"""
local_app_dir = os.path.join('wofpy_deployments', app + '_deployment')
with lcd(local_app_dir):
local('python setup.py sdist --formats=gztar', capture=False)
def deploy(app):
"""deploys an application"""
local_app_dir = os.path.join('wofpy_deployments', app + '_deployment')
remote_app_dir = os.path.join(WOFPY_DEPLOYMENTS_DIR,
app + '_deployment')
deployment_python = os.path.join('/space/www/wsgi_env/bin/python')
# figure out the release name and version
with lcd(local_app_dir):
dist = local('python setup.py --fullname', capture=True).strip()
wsgi_dir = 'wsgi'
wsgi_conf_file = app + '_apache_wsgi.conf'
remote_wsgi_conf_file = os.path.join(remote_app_dir, wsgi_conf_file)
app_conf_file = app + '_config.cfg'
# calculate file paths
dist_tar = '%s.tar.gz' % dist
temp_remote_install_dir = os.path.join('/tmp', local_app_dir)
temp_dist_tar = os.path.join('/tmp', dist_tar)
# upload the source tarball to the temporary folder on the server
put(os.path.join(local_app_dir, 'dist', dist_tar),
temp_dist_tar)
# create a place where we can unzip the tarball, then enter
# that directory and unzip it
run('mkdir -p %s' % temp_remote_install_dir)
with cd(temp_remote_install_dir):
run('tar -xzf %s' % temp_dist_tar)
# now setup the package with our virtual environment's python
# interpreter
with cd(os.path.join(temp_remote_install_dir, dist)):
run(deployment_python + ' setup.py install')
# now that all is set up, delete the folder again
run('rm -rf %s %s' % (temp_dist_tar, temp_remote_install_dir))
# and finally touch the .wsgi file so that mod_wsgi triggers
# a reload of the application
with lcd(local_app_dir):
put(wsgi_dir, remote_app_dir)
put(wsgi_conf_file, remote_wsgi_conf_file)
put(app_conf_file, remote_app_dir)
def build_cbi_cache():
"""runs the build_cbi_cache script on the remote machine"""
deployment_name = 'cbi_deployment'
local_app_dir = os.path.join('wofpy_deployments', deployment_name)
remote_app_dir = os.path.join(WOFPY_DEPLOYMENTS_DIR,
deployment_name)
# deployment_python = os.path.join(remote_app_dir,
# 'cbi_env/bin/python')
cbi_cache_dir = '/space/www/wofpy_deployments/cbi_deployment/cache/'
with lcd(local_app_dir):
put('cbi/build_cbi_cache.py', remote_app_dir)
put('cbi/cbi_cache_models.py', remote_app_dir)
with cd(remote_app_dir):
run('mkdir -p %s' % cbi_cache_dir)
run('python %s/build_cbi_cache.py --dropall True' % remote_app_dir)
def copy_cache_file(app, cache_file):
"""runs the build_cbi_cache script on the remote machine"""
deployment_name = app + '_deployment'
local_app_dir = os.path.join('wofpy_deployments', deployment_name)
remote_app_dir = os.path.join(WOFPY_DEPLOYMENTS_DIR,
deployment_name)
# deployment_python = os.path.join(remote_app_dir,
# 'cbi_env/bin/python')
remote_cache_dir = os.path.join(remote_app_dir, 'cache/')
local_cache_dir = os.path.join(local_app_dir, 'cache/')
get_filesize_command = "du -b %s | awk '{print $1}'" % cache_file
with cd(remote_cache_dir):
remote_size = run(get_filesize_command)
with lcd(local_cache_dir):
local_size = local(get_filesize_command, capture=True)
if local_size != remote_size:
put(cache_file, remote_cache_dir)
def deploy_central():
"""deploys an application"""
deployment_name = 'wdft_central'
local_app_dir = deployment_name
with lcd(local_app_dir):
local('python setup.py sdist --formats=gztar', capture=False)
remote_app_dir = os.path.join(CENTRAL_REGISTRY_DEPLOYMENTS_DIR,
local_app_dir,)
deployment_python = os.path.join('/space/www/wsgi_env/bin/python')
# figure out the release name and version
with lcd(local_app_dir):
dist = local('python setup.py --fullname', capture=True).strip()
wsgi_dir = 'wsgi'
wsgi_conf_file = 'wdft_central_apache_wsgi.conf'
remote_wsgi_conf_file = os.path.join(remote_app_dir, wsgi_conf_file)
data_dir = 'data'
# calculate file paths
dist_tar = '%s.tar.gz' % dist
temp_remote_install_dir = os.path.join('/tmp', local_app_dir)
temp_dist_tar = os.path.join('/tmp', dist_tar)
# upload the source tarball to the temporary folder on the server
put(os.path.join(local_app_dir, 'dist', dist_tar),
temp_dist_tar)
# create a place where we can unzip the tarball, then enter
# that directory and unzip it
run('mkdir -p %s' % temp_remote_install_dir)
with cd(temp_remote_install_dir):
run('tar -xzf %s' % temp_dist_tar)
# now setup the package with our virtual environment's python
# interpreter
with cd(os.path.join(temp_remote_install_dir, dist)):
run(deployment_python + ' setup.py install')
# now that all is set up, delete the folder again
run('rm -rf %s %s' % (temp_dist_tar, temp_remote_install_dir))
# and finally touch the .wsgi file so that mod_wsgi triggers
# a reload of the application
with lcd(local_app_dir):
put(wsgi_dir, remote_app_dir)
put(wsgi_conf_file, remote_wsgi_conf_file)
put(data_dir, remote_app_dir)