def update():
    # TODO: perform db backup
    with cd(env.code_path):
        cmd('git pull')
    virtualenv('python %s migrate' % env.manage_path)

    deploy_static_files()

    restart()
def install_pil():
    """ Custom PIL installation to activate JPEG support """
    # Install required packages
    packages = ['libjpeg8', 'libjpeg8-dev', 'libfreetype6', 'libfreetype6-dev', 'zlib1g-dev']
    sudo('aptitude -y install %s' % ' '.join(packages))

    # PIL requires custom installation to activate JPEG support
    virtualenv('pip install -I pil --no-install')
    sed(os.path.join(env.env_path, 'build', 'pil', 'setup.py'),
            '# standard locations',
            'add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")')
    virtualenv('pip install -I pil --no-download')
def deploy():
    cmd('mkdir -p %s %s %s %s' % (
            env.code_path, env.env_path, env.STATIC_ROOT, os.path.join(env.logs_path)))

    cmd('git clone %s %s' % (env.conf['repository'], env.code_path))

    # Provide data for Django settings
    # TODO: change the owner of this file
    put(StringIO.StringIO(json.dumps(env.conf, indent=4)),
            os.path.join(env.code_path, 'deployment', 'config.json'))

    # Create virtualenv
    cmd('virtualenv --no-site-packages %s' % env.env_path)

    virtualenv('pip install -r %s' % os.path.join(env.code_path, 'deployment', 'requirements.prod.txt'))

    # TODO: a hack until django 1.5 is released
    virtualenv('pip install --no-deps django-grappelli==2.4.3')

    # Create uwsgi settings and run the daemon
    file_from_template(os.path.join('..', 'templates', 'uwsgi.ini'),
            os.path.join(env.code_path, 'deployment', 'uwsgi.ini'), root=False)

    # TODO: use uWSGI Emperor
    file_from_template(os.path.join('..', 'templates', 'upstart'), '/etc/init/uwsgi.conf')

    # Nginx site configuration
    file_from_template(os.path.join('..', 'templates', 'nginx_website.conf'),
            '/etc/nginx/sites-available/%s' % env.conf['DOMAIN'])

    sudo('ln -s /etc/nginx/sites-available/%(domain)s /etc/nginx/sites-enabled/%(domain)s' % {
            'domain': env.conf['DOMAIN']})

    # Initialize database
    init_db()

    # TODO: supervisord config file

    deploy_static_files()

    restart()
def deploy_static_files():
    # TODO: minify static files
    virtualenv('python %s collectstatic -c --noinput' % env.manage_path)
Beispiel #5
0
def init_db():
    virtualenv('python %s syncdb --noinput --all' % env.manage_path)
    virtualenv('python %s migrate --fake' % env.manage_path)
    virtualenv('python %s createsuperuser' % env.manage_path)