X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/85758488fc4c0f60e4b958df9c4c7cd67a732000..00a90d6175599e055f5a84697c8388d81ac1b007:/fabfile.py diff --git a/fabfile.py b/fabfile.py index 8ae349f0..399f1c2f 100644 --- a/fabfile.py +++ b/fabfile.py @@ -36,13 +36,13 @@ def production(): env.virtualenv = os.path.join(env.sandbox, 'bin', 'virtualenv') env.pip = os.path.join(env.sandbox, 'python', 'bin', 'pip') - env.python = env.target = os.path.join(env.sandbox, 'python', 'bin', 'python') - + env.python = os.path.join(env.sandbox, 'python', 'bin', 'python') common() def common(): env.path = os.path.join(env.sandbox, env.project_name) + env.target = os.path.join(env.path, 'bin', 'python') # ========= @@ -61,18 +61,26 @@ def setup(): """ require('hosts', 'sandbox', provided_by=[staging, production]) - run("mkdir -p %(path)s; mkdir -p %(path)s/www/wsgi;" % env) + run("mkdir -p %(path)s; mkdir -p %(path)s/www/wsgi; mkdir -p %(path)s/www/media" % env) # make a git mirror - run("""\ -cd %(path)s; + run("""cd %(path)s; git clone %(giturl)s mirror; cd %(path)s/mirror; git pull""" % env, pty=True) run('%(virtualenv)s %(path)s' % env, pty=True) - run('cd %(path)s; mkdir -p releases; mkdir -p shared; mkdir -p packages;' % env, pty=True) + run('cd %(path)s; rm -rf releases shared packages; mkdir -p releases; mkdir -p shared; mkdir -p packages;' % env, pty=True) + + # symlink static content + run("""cd %(path)s/www/media; +ln -sf %(path)s/releases/current/%(project_name)s/static static +ln -sf %(path)s/lib/python2.6/site-packages/django/contrib/admin/media admin-media +mkdir -p dynamic +""" % env) + run('cd %(path)s/releases; ln -s . current; ln -s . previous' % env, pty=True) + deploy() @@ -91,7 +99,7 @@ def deploy(): upload_wsgi_script() # upload_vhost_sample() install_requirements() - copy_localsettings() + hardlink_localsettings() symlink_current_release() migrate() django_compress() @@ -134,7 +142,7 @@ def prepare_package_from_git(): run('mkdir -p %(path)s/releases/%(release)s' % env, pty=True) run('mkdir -p %(path)s/packages' % env, pty=True) - run('cd %(path)s/mirror; git archive --format=tar %(gitbranch)s | gzip > %(path)s/packages/%(release)s.tar.gz' % env) + run('cd %(path)s/mirror; git pull; git archive --format=tar %(gitbranch)s | gzip > %(path)s/packages/%(release)s.tar.gz' % env) run('cd %(path)s/releases/%(release)s && tar zxf ../../packages/%(release)s.tar.gz' % env, pty=True) @@ -153,19 +161,26 @@ def upload_wsgi_script(): def install_requirements(): "Install the required packages from the requirements file using pip" - print '>>> install requirements' + + print '>>> Instaling global requirements' require('release', provided_by=[deploy]) run('cd %(path)s; %(path)s/bin/pip install -r %(path)s/releases/%(release)s/%(project_name)s/config/requirements.txt' % env, pty=True) + print '>>> Instaling site requirements' + + with settings(warn_only=True): + run('cd %(path)s; %(path)s/bin/pip install -r %(sandbox)s/etc/%(project_name)s/requirements.txt' % env, pty=True) + -def copy_localsettings(): - "Copy localsettings.py from root directory to release directory (if this file exists)" - print ">>> copy localsettings" +def hardlink_localsettings(): + "Hardlink localsettings.py from root directory to release directory (if this file exists)" + print ">>> Hardlink localsettings" require('release', 'path', provided_by=[deploy]) require('sandbox', provided_by=[staging, production]) + # hardlink localsettings with settings(warn_only=True): - run('cp %(sandbox)s/etc/%(project_name)s/localsettings.py %(path)s/releases/%(release)s/%(project_name)s' % env) + run('ln %(sandbox)s/etc/%(project_name)s/localsettings.py %(path)s/releases/%(release)s/%(project_name)s' % env) def symlink_current_release(): @@ -183,10 +198,10 @@ def migrate(): print '>>> migrate' require('project_name', provided_by=[staging, production]) with cd('%(path)s/releases/current/%(project_name)s' % env): - run('%(target) manage.py syncdb --noinput' % env, pty=True) + run('%(target)s manage.py syncdb --noinput' % env, pty=True) if env.use_south: - run('%(target) manage.py migrate' % env, pty=True) + run('%(target)s manage.py migrate' % env, pty=True) def django_compress(): @@ -194,7 +209,7 @@ def django_compress(): print '>>> migrate' require('project_name', provided_by=[staging, production]) with cd('%(path)s/releases/current/%(project_name)s' % env): - run('%(target) manage.py synccompress --force' % env, pty=True) + run('%(target)s manage.py synccompress --force' % env, pty=True) def restart_webserver():