Skip to content
Browse files

Merge branch 'master' of github.com:yumike/djangolint

  • Loading branch information...
2 parents 9a14d38 + f43a832 commit 39b182b4a201a0e4262c697bff5a7ba6d279f1ec @nyumatova nyumatova committed Jul 31, 2011
Showing with 142 additions and 24 deletions.
  1. +11 −0 etc/supervisor_upstart.conf
  2. +36 −0 etc/supervisord.conf
  3. +82 −8 fabfile.py
  4. +1 −4 node.json
  5. +0 −10 project/settings/common.py
  6. +9 −0 project/settings/production.py
  7. +3 −2 requirements/production.txt
View
11 etc/supervisor_upstart.conf
@@ -0,0 +1,11 @@
+description "Supervisor for project"
+
+start on runlevel [2345]
+stop on runlevel [06]
+
+kill timeout 5
+respawn
+
+script
+ exec su -c '/home/project/.env/bin/supervisord --configuration /home/project/etc/supervisord.conf' project
+end script
View
36 etc/supervisord.conf
@@ -0,0 +1,36 @@
+[unix_http_server]
+file=/tmp/supervisor.sock ; (the path to the socket file)
+
+[supervisord]
+logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
+loglevel=info ; (log level;default info; others: debug,warn,trace)
+pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
+nodaemon=false ; (start in foreground if true;default false)
+minfds=1024 ; (min. avail startup file descriptors;default 1024)
+minprocs=200 ; (min. avail process descriptors;default 200)
+environment=PROJECT_ENV={project_env}
+
+; the below section must remain in the config file for RPC
+; (supervisorctl/web interface) to work, additional interfaces may be
+; added by defining them in separate rpcinterface: sections
+[rpcinterface:supervisor]
+supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
+
+[supervisorctl]
+serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
+
+
+[program:gunicorn]
+command=/home/project/.env/bin/gunicorn_django --preload --workers=2 --log-file=/tmp/gunicorn.log --pid=/tmp/gunicorn.pid --bind=127.0.0.1:8888 /home/project/project/project/settings
+
+[program:celery]
+command=/home/project/.env/bin/python /home/project/project/project/manage.py celeryd --time-limit=300 -f /tmp/celeryd.log -l INFO
+
+; The [include] section can just contain the "files" setting. This
+; setting can list multiple files (separated by whitespace or
+; newlines). It can also contain wildcards. The filenames are
+; interpreted as relative to this file. Included files *cannot*
+; include files themselves.
+
+;[include]
+;files = relative/directory/*.ini
View
90 fabfile.py
@@ -4,6 +4,7 @@
from datetime import datetime
from fabric.api import *
+from fabric.contrib.files import append, exists
@task
@@ -14,6 +15,13 @@ def vagrant():
@task
+def linode():
+ env.user = 'project'
+ env.hosts = ['178.79.172.9']
+ env.project_env = 'production'
+
+
+@task
def bootstrap():
with settings(user='root'):
run('apt-get -q -y update')
@@ -35,14 +43,23 @@ def provision():
chef_root = os.path.join(project_root, 'chef')
chef_name = 'chef-{0}'.format(datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S'))
chef_archive = '{0}.tar.gz'.format(chef_name)
+
local('cp -r {0} /tmp/{1}'.format(chef_root, chef_name))
- create_node_json('/tmp/{0}/node.json'.format(chef_name))
+
+ with open('node.json') as f:
+ data = json.load(f)
+ project = data.setdefault('project', {})
+ project['environment'] = env.project_env
+ with open('/tmp/{0}/node.json'.format(chef_name), 'w') as f:
+ json.dump(data, f)
+
solo_rb = ('file_cache_path "/tmp/chef-solo"',
'cookbook_path "/tmp/{0}/cookbooks"'.format(chef_name))
with lcd('/tmp'):
for line in solo_rb:
local("echo '{0}' >> {1}/solo.rb".format(line, chef_name))
local('tar czf {0} {1}'.format(chef_archive, chef_name))
+
with settings(user='root'):
put('/tmp/{0}'.format(chef_archive), '/tmp/{0}'.format(chef_archive))
local('rm -rf /tmp/{0}*'.format(chef_name))
@@ -52,12 +69,69 @@ def provision():
with settings(warn_only=True):
run('chef-solo -c solo.rb -j node.json')
run('rm -rf /tmp/{0}*'.format(chef_name))
+ upload_public_key('project', 'root')
+ prepare_env()
-def create_node_json(target):
- with open('node.json') as f:
- data = json.load(f)
- project = data.setdefault('project', {})
- project['environment'] = env.project_env
- with open(target, 'w') as f:
- json.dump(data, f)
+@task
+def prepare_env():
+ if not exists('.env'):
+ run('wget https://raw.github.com/pypa/virtualenv/develop/virtualenv.py')
+ run('python virtualenv.py --distribute --no-site-packages ~/.env')
+ run("echo 'source ~/.env/bin/activate' >> .profile")
+ if not exists('.git'):
+ run('git init .git --bare')
+ run('git clone .git project')
+ local('git push ssh://{user}@{host}:{port}/~/.git master'.format(**env))
+ with cd('project'):
+ run('git pull ~/.git master')
+ install_requirements()
+ manage('syncdb --migrate --noinput')
+ manage('collectstatic --noinput')
+ with open('etc/supervisord.conf') as f:
+ supervisor_config = f.read().format(**{'project_env': env.project_env})
+ run('mkdir -p ~/etc/ && rm -f ~/etc/supervisord.conf')
+ append('~/etc/supervisord.conf', supervisor_config)
+ with settings(user='root', warn_only=True):
+ with lcd('etc'):
+ put('supervisor_upstart.conf', '/etc/init/supervisor.conf')
+ run('stop supervisor')
+ run('start supervisor')
+
+
+@task
+def deploy(update_all='yes'):
+ local('git push ssh://{user}@{host}:{port}/~/.git master'.format(**env))
+ with cd('project'):
+ run('git pull ~/.git master')
+ if update_all == 'yes':
+ install_requirements()
+ manage('syncdb --migrate --noinput')
+ manage('collectstatic --noinput')
+ run('supervisorctl restart gunicorn')
+ run('supervisorctl restart celery')
+
+
+@task
+def install_requirements():
+ run('pip install -r requirements/{0}.txt'.format(env.project_env))
+
+
+@task
+def manage(command):
+ run('python project/manage.py {0}'.format(command))
+
+
+@task
+def upload_public_key(to=None, user=None):
+ with settings(user=user or env.user):
+ to = to or env.user
+ path = os.path.expanduser('~/.ssh/id_rsa.pub')
+ if to and os.path.exists(path):
+ key = ' '.join(open(path).read().strip().split(' ')[:2])
+ run('mkdir -p /home/{0}/.ssh'.format(to))
+ append('/home/{0}/.ssh/authorized_keys'.format(to), key, partial=True)
+ run('chown {0}:{0} /home/{0}/.ssh/authorized_keys'.format(to))
+ run('chmod 600 /home/{0}/.ssh/authorized_keys'.format(to))
+ run('chown {0}:{0} /home/{0}/.ssh'.format(to))
+ run('chmod 700 /home/{0}/.ssh'.format(to))
View
5 node.json
@@ -1,7 +1,4 @@
{
"run_list": [ "ssh", "apt", "packages", "curl", "git", "nginx", "python",
- "postgresql::server", "redis::server", "project" ],
- "packages": {
- "default": [ "libjpeg8-dev", "zlib1g-dev", "libfreetype6-dev", "liblcms1-dev" ]
- }
+ "postgresql::server", "redis::server", "project" ]
}
View
10 project/settings/common.py
@@ -106,18 +106,12 @@
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
- 'django.contrib.auth.context_processors.auth',
- 'django.core.context_processors.debug',
- 'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
- 'django.contrib.messages.context_processors.messages',
'lint.context_processors.report_pk',
)
@@ -129,11 +123,7 @@
)
INSTALLED_APPS = (
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
'django.contrib.sessions',
- 'django.contrib.sites',
- 'django.contrib.messages',
'django.contrib.staticfiles',
'lint',
'south',
View
9 project/settings/production.py
@@ -10,6 +10,15 @@
}
}
+CACHES = {
+ 'default': {
+ 'BACKEND': 'redis_cache.RedisCache',
+ 'LOCATION': '127.0.0.1:6379',
+ 'OPTIONS': {
+ 'DB': 1,
+ },
+ },
+}
BROKER_BACKEND = 'redis'
BROKER_HOST = 'localhost'
View
5 requirements/production.txt
@@ -1,7 +1,8 @@
-r base.txt
+django-redis-cache==0.8.2
+gunicorn==0.12.2
+meld3==0.6.7
psycopg2==2.4.2
redis==2.4.9
-gunicorn==0.12.2
supervisor==3.0a10
-meld3==0.6.7

0 comments on commit 39b182b

Please sign in to comment.
Something went wrong with that request. Please try again.