|
33
|
1 |
from fabric.api import env, local, put, run, lcd, task, prefix, sudo |
|
27
|
2 |
from fabric.contrib.files import exists |
|
|
3 |
from fabric.colors import green |
|
|
4 |
import tempfile |
|
|
5 |
import shutil |
|
|
6 |
import os |
|
|
7 |
import settings |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
def __init(): |
|
|
11 |
if not env.get('temp_folder', None): |
|
|
12 |
env['temp_folder'] = tempfile.mkdtemp() |
|
|
13 |
print(green("working folder is %s" % env['temp_folder'])) |
|
|
14 |
|
|
|
15 |
def __clean(): |
|
|
16 |
if env.get('temp_folder', None): |
|
|
17 |
print(green("Removing %s" % env['temp_folder'])) |
|
|
18 |
shutil.rmtree(env['temp_folder']) |
|
|
19 |
|
|
|
20 |
def get_version_path(): |
|
|
21 |
return os.path.join(env['temp_folder'], env['version']) |
|
|
22 |
|
|
|
23 |
def export(): |
|
|
24 |
local('hg archive -r %s %s' % (env['version'], get_version_path()) ) |
|
|
25 |
|
|
|
26 |
def pack(): |
|
|
27 |
# create a new source distribution as tarball |
|
|
28 |
with lcd(get_version_path()): |
|
|
29 |
local('python setup.py sdist --formats=gztar', capture=False) |
|
|
30 |
|
|
|
31 |
def create_virtualenv(): |
|
|
32 |
with lcd(get_version_path()): |
|
|
33 |
tmpd = run('mktemp -d').strip() |
|
|
34 |
put('virtualenv/*.txt', tmpd) |
|
|
35 |
run('virtualenv -p /usr/bin/python3 %s' % env.srv_venv_path) |
|
|
36 |
with prefix('source %s/bin/activate' % env.srv_venv_path): |
|
|
37 |
run('pip install -r %s/requirements.txt' % tmpd) |
|
|
38 |
run('pip install -r %s/requirements_srvr.txt' % tmpd) |
|
|
39 |
run('rm -fr %s' % tmpd) |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
def deploy(): |
|
|
43 |
# figure out the release name and version |
|
|
44 |
with lcd(get_version_path()): |
|
|
45 |
dist = local('python setup.py --fullname', capture=True).strip() |
|
|
46 |
print(green("dist is %s" % dist)) |
|
|
47 |
|
|
|
48 |
# upload the source tarball to the temporary folder on the server |
|
|
49 |
put('dist/%s.tar.gz' % dist, '/tmp/%s.tar.gz' % dist) |
|
|
50 |
# create a place where we can unzip the tarball, then enter |
|
|
51 |
# that directory and unzip it |
|
|
52 |
# now setup the package with our virtual environment's |
|
|
53 |
# python interpreter |
|
|
54 |
with prefix('source %s/bin/activate' % env.srv_venv_path): |
|
|
55 |
run('pip install -U --force-reinstall /tmp/%s.tar.gz' % dist) |
|
|
56 |
# now that all is set up, delete the folder again |
|
|
57 |
|
|
|
58 |
run('rm -rf /tmp/%s.tar.gz' % dist) |
|
33
|
59 |
sudo('supervisorctl restart catedit', shell=False) |
|
27
|
60 |
|
|
|
61 |
@task(default=True) |
|
|
62 |
def deploy_version(version='tip'): |
|
|
63 |
env['version'] = version |
|
|
64 |
__init() |
|
|
65 |
export() |
|
|
66 |
pack() |
|
|
67 |
if not exists(env.srv_venv_path): |
|
|
68 |
create_virtualenv() |
|
|
69 |
deploy() |
|
|
70 |
__clean() |