Skip to content

Commit 9bc3531

Browse files
committed
Add quick deployment example
1 parent bc376b6 commit 9bc3531

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

config/biztest-nginx.conf

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
upstream bizcluster {
2+
server 127.0.0.1:10001;
3+
}
4+
5+
server {
6+
listen 0.0.0.0:80;
7+
server_name biztest.curiousllc.com;
8+
9+
access_log /var/log/nginx/yd_access.log;
10+
error_log /var/log/nginx/yd_error.log;
11+
12+
location /static/ {
13+
alias /root/static/;
14+
expires 48h;
15+
}
16+
17+
set $home /root/BizTest;
18+
client_max_body_size 3M;
19+
location / {
20+
if ($request_method = 'OPTIONS') {
21+
add_header 'Access-Control-Allow-Origin' '*';
22+
add_header 'Access-Control-Allow-Credentials' 'true';
23+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
24+
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
25+
}
26+
27+
if ($request_method = 'POST') {
28+
add_header 'Access-Control-Allow-Origin' '*';
29+
add_header 'Access-Control-Allow-Credentials' 'true';
30+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
31+
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
32+
}
33+
34+
35+
# the socket an port your wsgi daemon listens on
36+
uwsgi_read_timeout 1300;
37+
uwsgi_pass bizcluster;
38+
include uwsgi_params;
39+
root $home;
40+
}
41+
}

config/biztest-supervisor.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[program:biztest]
2+
command=/root/launch.sh /root/BizTestEnv uwsgi --enable-threads --single-interpreter --pp /root/BizTest/ -H /root/BizTestEnv --module runserver:app --socket 127.0.0.1:10001 --master --processes 3 --logger syslog
3+
directory=/root/BizTest
4+
environment=
5+
user=root
6+
autostart=true
7+
autorestart=true
8+
stdout_logfile=/var/log/supervisor.log
9+
redirect_stderr=true
10+
stopsignal=QUIT

fabfile.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from fabric.api import env, run, cd, prefix, sudo
2+
from fabric.contrib.project import rsync_project
3+
from fabric.contrib.files import exists
4+
from contextlib import contextmanager as _contextmanager
5+
6+
7+
# the user to use for the remote commands
8+
env.user = 'root'
9+
10+
# the servers where the commands are executed
11+
env.hosts = ['104.131.15.37']
12+
env.root = '/root'
13+
env.project = '%s/BizTest' % env.root
14+
env.environment = '%s/BizTestEnv' % env.root
15+
env.activate = 'source %s/bin/activate' % env.environment
16+
env.forward_agent = True
17+
env.node_version = 'v0.10.36'
18+
19+
20+
@_contextmanager
21+
def virtualenv():
22+
with cd(env.project):
23+
with prefix(env.activate):
24+
yield
25+
26+
27+
@_contextmanager
28+
def buildenv():
29+
with cd(env.root):
30+
yield
31+
32+
33+
def deploy():
34+
if not exists('%s/launch.sh' % env.root):
35+
# We haven't installed anything yet
36+
sudo('aptitude update')
37+
sudo('aptitude -y upgrade')
38+
sudo('aptitude install -y nginx supervisor ruby python-virtualenv gcc make python-dev git wget curl make g++ libevent-dev '
39+
'python-setuptools memcached libmemcached-dev libxml2-dev libxslt1-dev postgresql-9.3 postgresql-server-dev-9.3')
40+
41+
if not exists('%s/node' % env.root):
42+
run('wget http://nodejs.org/dist/{0}/node-{0}.tar.gz'.format(env.node_version))
43+
run('tar -xzf node-{}.tar.gz'.format(env.node_version))
44+
with cd('node-{}'.format(env.node_version)):
45+
run('./configure --prefix=%s/node' % env.root)
46+
run('make && make install')
47+
run('%s/node/bin/npm install -g grunt-cli' % env.root)
48+
49+
if not exists(env.environment):
50+
with cd(env.root):
51+
run('virtualenv %s' % env.environment)
52+
53+
rsync_project(
54+
remote_dir=env.project,
55+
local_dir='./',
56+
exclude=('*.pyc', 'config.py', '.git', '.gitignore', '.tmp', 'node_modules', '.idea', 'dist', 'alembic.ini', 'dist/index.html', 'app/scripts/config.js', 'app/index.html', 'bower_components'),
57+
)
58+
59+
if not exists('/etc/supervisor/conf.d/biztest.conf'):
60+
sudo('cp %s/config/biztest-supervisor.conf /etc/supervisor/conf.d/biztest.conf' % env.project)
61+
sudo('supervisorctl reread')
62+
sudo('supervisorctl update')
63+
sudo('supervisorctl start biztest')
64+
65+
if not exists('/etc/nginx/sites-enabled/biztest'):
66+
sudo('cp %s/config/biztest-nginx.conf /etc/nginx/sites-enabled/biztest' % env.project)
67+
sudo('service nginx reload')
68+
69+
if not exists('%s/config.py' % env.project):
70+
sudo('cp %s/config-template %s/config.py' % (env.project, env.project))
71+
72+
with virtualenv():
73+
run('pip install -r requirements.txt')
74+
75+
if not exists('/root/bizness.db'):
76+
with virtualenv():
77+
run('PYTHONPATH=%s DATABASE_URL=sqlite:////root/bizness.db python %s/tools/populate_db.py' % (env.project, env.project))
78+
79+
sudo('supervisorctl stop biztest')
80+
sudo('supervisorctl start biztest')
81+
82+
#with cd(env.project):
83+
# run('%s/node/bin/npm install' % env.root)
84+
# run('%s/node/bin/bower install' % env.root)
85+
# run('grunt')

0 commit comments

Comments
 (0)