From a7d807af1096c152baf5c32f4f4b3f1a26ea2c76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Sat, 17 Apr 2010 15:34:42 +0200 Subject: [PATCH] Some cleanup before production deploy. --- README.md | 32 +++++ README.rst | 36 ----- cas.vhost.template | 51 +++++++ cas.wsgi.template | 11 +- fabfile.py | 159 --------------------- {cas => src/cas}/__init__.py | 0 {cas => src/cas}/logging.cfg | 0 {cas => src/cas}/manage.py | 0 {cas => src/cas}/settings.py | 4 +- {cas => src/cas}/templates/cas/login.html | 0 {cas => src/cas}/templates/cas/logout.html | 0 {cas => src/cas}/templates/cas_base.html | 0 {cas => src/cas}/urls.py | 0 {cas => src/cas}/utils.py | 0 14 files changed, 90 insertions(+), 203 deletions(-) create mode 100644 README.md delete mode 100644 README.rst create mode 100644 cas.vhost.template delete mode 100644 fabfile.py rename {cas => src/cas}/__init__.py (100%) rename {cas => src/cas}/logging.cfg (100%) rename {cas => src/cas}/manage.py (100%) mode change 100755 => 100644 rename {cas => src/cas}/settings.py (97%) rename {cas => src/cas}/templates/cas/login.html (100%) rename {cas => src/cas}/templates/cas/logout.html (100%) rename {cas => src/cas}/templates/cas_base.html (100%) rename {cas => src/cas}/urls.py (100%) rename {cas => src/cas}/utils.py (100%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..d63f735 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +O projekcie +----------- + +CAS to aplikacja WWW służąca do uwierzytelniania (a w przyszłości również autoryzacji) użytkowników +serwisów Fundacji Nowoczesna Polska. Implementuje on protokół CAS w +wersji 1.0. + +Wymagania +--------- + +* Django 1.1 +* zuber/django-cas-provider + +Instalacja i uruchomienie +------------------------- + +1. Ściągnij i zainstaluj pip +2. Przejdź do katalogu aplikacji w konsoli +3. Zainstaluj wymagane biblioteki (patrz sekcja wymagania_) komendą + + pip install -r requirements.txt + +4. Wypełnij bazę danych (Django poprosi o utworzenie pierwszego użytkownika) + + ./manage.py syncdb + +5. Uruchom serwer deweloperski + + ./manage.py runserver + +6. Przy wdrożeniu będziesz musiał najpewniej utworzyć plik `localsettings.py` i wpisać tam +ustawienia używanej bazy danych. Zalecane jest serwowanie aplikacji przez modwsgi na serwerze Apache2. \ No newline at end of file diff --git a/README.rst b/README.rst deleted file mode 100644 index bccda5b..0000000 --- a/README.rst +++ /dev/null @@ -1,36 +0,0 @@ -================================ -Fundacja Nowoczesna Polska - CAS -================================ - -O projekcie -=========== -CAS to aplikacja WWW służąca do autentykacji (a w przyszłości również autoryzacji) użytkowników -serwisów Fundacji Nowoczesna Polska. Implementuje on protokół `CAS `_ w -wersji 1.0. - -Wymagania -========= -* `Django 1.1 `_ -* `zuber/django-cas-provider `_ - -Instalacja i uruchomienie -========================= -1. Ściągnij i zainstaluj `pip `_ -2. Przejdź do katalogu aplikacji w konsoli -3. Zainstaluj wymagane biblioteki (patrz sekcja wymagania_) komendą:: - - pip install -r requirements.txt - -4. Wypełnij bazę danych (Django poprosi o utworzenie pierwszego użytkownika):: - - ./manage.py syncdb - -5. Uruchom serwer deweloperski:: - - ./manage.py runserver - -6. Przy wdrożeniu będziesz musiał najpewniej utworzyć plik `localsettings.py` i wpisać tam -ustawienia używanej bazy danych. Zalecane jest serwowanie aplikacji -przez `modwsgi `_ na serwerze `Apache2 `_ -przy pomocy załączonego skryptu `dispatch.fcgi`. Inne strategie wdrożeniowe opisane -są w `Dokumentacji Django `_. \ No newline at end of file diff --git a/cas.vhost.template b/cas.vhost.template new file mode 100644 index 0000000..d951258 --- /dev/null +++ b/cas.vhost.template @@ -0,0 +1,51 @@ + + ServerName $DOMAIN + ServerAlias $DOMAIN_ALIASES + + ServerAdmin $ADMIN_EMAIL + + Alias /robots.txt $MEDIA_ROOT/static/robots.txt + Alias /favicon.ico $MEDIA_ROOT/static/favicon.ico + + Alias /media/ $MEDIA_ROOT + + # + # Logs + LogLevel info + + # + # WSGI configuration follows + # + + WSGIDaemonProcess $PROJECT_NAME processes=2 threads=1 user=$WSGI_USER group=$WSGI_USER display-name=%{GROUP} + WSGIProcessGroup $PROJECT_NAME + WSGIScriptAlias / $WSGI_TARGET + + + Order allow,deny + Allow from all + + + + # Insert filter + SetOutputFilter DEFLATE + + # Don't compress images + SetEnvIfNoCase Request_URI \ + \.(?:xsl|xml|json|gif|jpe?g|png)$ no-gzip dont-vary + + + + Order allow,deny + Allow from all + + + # + # Header unset ETag + # FileETag None + # ExpiresActive On + # ExpiresDefault "now plus 1 year" + # + + + \ No newline at end of file diff --git a/cas.wsgi.template b/cas.wsgi.template index 2124c1e..d8c87da 100644 --- a/cas.wsgi.template +++ b/cas.wsgi.template @@ -1,6 +1,6 @@ -#!%(python)s +#!$PYTHON import site -site.addsitedir('%(path)s/lib/python2.5/site-packages') +site.addsitedir('$PYTHON_SITE') import os from os.path import abspath, dirname, join @@ -12,13 +12,12 @@ sys.stdout = sys.stderr # Add apps and lib directories to PYTHONPATH sys.path = [ - '%(path)s/releases/current/%(project_name)s', - '%(path)s/releases/current/provider', - '%(path)s/releases/current', + '$PROJECT_ROOT/src', + '$PROJECT_ROOT/provider', ] + sys.path # Run Django -os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' +os.environ['DJANGO_SETTINGS_MODULE'] = '$PROJECT_NAME.settings' from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler() diff --git a/fabfile.py b/fabfile.py deleted file mode 100644 index d70c13f..0000000 --- a/fabfile.py +++ /dev/null @@ -1,159 +0,0 @@ -from __future__ import with_statement # needed for python 2.5 -from fabric.api import * -from fabric.contrib import files - -import os - - -# ========== -# = Config = -# ========== -# Globals -env.project_name = 'cas' -env.use_south = False - -# Servers -def staging(): - """Use staging server""" - env.hosts = ['stigma.nowoczesnapolska.org.pl:2222'] - env.user = 'platforma' - env.path = '/var/services/cas' - env.python = '/usr/bin/python' - env.virtualenv = '/usr/bin/virtualenv' - env.pip = '/usr/bin/pip' - -def production(): - """Use production server""" - env.hosts = ['wolnelektury.pl:22123'] - env.user = 'fundacja' - env.path = '/opt/lektury/cas' - env.python = '/opt/lektury/basevirtualenv/bin/python' - env.virtualenv = '/opt/lektury/basevirtualenv/bin/virtualenv' - env.pip = '/opt/lektury/basevirtualenv/bin/pip' - - -# ========= -# = Tasks = -# ========= -def test(): - "Run the test suite and bail out if it fails" - require('hosts', 'path', provided_by=[staging, production]) - result = run('cd %(path)s/%(project_name)s; %(python)s manage.py test' % env) - -def setup(): - """ - Setup a fresh virtualenv as well as a few useful directories, then run - a full deployment. virtualenv and pip should be already installed. - """ - require('hosts', 'path', provided_by=[staging, production]) - - run('mkdir -p %(path)s; cd %(path)s; %(virtualenv)s --no-site-packages .;' % env, pty=True) - run('cd %(path)s; mkdir releases; mkdir shared; mkdir packages;' % env, pty=True) - run('cd %(path)s/releases; ln -s . current; ln -s . previous' % env, pty=True) - deploy() - -def deploy(): - """ - Deploy the latest version of the site to the servers, - install any required third party modules, - install the virtual host and then restart the webserver - """ - require('hosts', 'path', provided_by=[staging, production]) - - import time - env.release = time.strftime('%Y-%m-%dT%H%M') - - upload_tar_from_git() - upload_wsgi_script() - # upload_vhost_sample() - install_requirements() - copy_localsettings() - symlink_current_release() - migrate() - restart_webserver() - -def deploy_version(version): - "Specify a specific version to be made live" - require('hosts', 'path', provided_by=[localhost,webserver]) - env.version = version - with cd(env.path): - run('rm releases/previous; mv releases/current releases/previous;', pty=True) - run('ln -s %(version)s releases/current' % env, pty=True) - restart_webserver() - -def rollback(): - """ - Limited rollback capability. Simple loads the previously current - version of the code. Rolling back again will swap between the two. - """ - require('hosts', provided_by=[staging, production]) - require('path') - with cd(env.path): - run('mv releases/current releases/_previous;', pty=True) - run('mv releases/previous releases/current;', pty=True) - run('mv releases/_previous releases/previous;', pty=True) - restart_webserver() - - -# ===================================================================== -# = Helpers. These are called by other functions rather than directly = -# ===================================================================== -def upload_tar_from_git(): - "Create an archive from the current Git master branch and upload it" - print '>>> upload tar from git' - require('release', provided_by=[deploy]) - local('git archive --format=tar master | gzip > %(release)s.tar.gz' % env) - run('mkdir -p %(path)s/releases/%(release)s' % env, pty=True) - run('mkdir -p %(path)s/packages' % env, pty=True) - put('%(release)s.tar.gz' % env, '%(path)s/packages/' % env) - run('cd %(path)s/releases/%(release)s && tar zxf ../../packages/%(release)s.tar.gz' % env, pty=True) - local('rm %(release)s.tar.gz' % env) - -def upload_vhost_sample(): - "Create and upload Apache virtual host configuration sample" - print ">>> upload vhost sample" - files.upload_template('%(project_name)s.vhost.template' % env, '%(path)s/%(project_name)s.vhost.sample' % env, context=env) - -def upload_wsgi_script(): - "Create and upload a wsgi script sample" - print ">>> upload wsgi script sample" - files.upload_template('%(project_name)s.wsgi.template' % env, '%(path)s/%(project_name)s.wsgi' % env, context=env) - run('chmod ug+x %(path)s/%(project_name)s.wsgi' % env) - -def install_requirements(): - "Install the required packages from the requirements file using pip" - print '>>> install requirements' - require('release', provided_by=[deploy]) - run('cd %(path)s; %(pip)s install -E . -r %(path)s/releases/%(release)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" - require('release', provided_by=[deploy]) - require('path', provided_by=[staging, production]) - - with settings(warn_only=True): - run('cp %(path)s/localsettings.py %(path)s/releases/%(release)s/%(project_name)s' % env) - -def symlink_current_release(): - "Symlink our current release" - print '>>> symlink current release' - require('release', provided_by=[deploy]) - require('path', provided_by=[staging, production]) - with cd(env.path): - run('rm releases/previous; mv releases/current releases/previous') - run('ln -s %(release)s releases/current' % env) - -def migrate(): - "Update the database" - print '>>> migrate' - require('project_name', provided_by=[staging, production]) - with cd('%(path)s/releases/current/%(project_name)s' % env): - run('../../../bin/python manage.py syncdb --noinput' % env, pty=True) - if env.use_south: - run('../../../bin/python manage.py migrate' % env, pty=True) - -def restart_webserver(): - "Restart the web server" - print '>>> restart webserver' - run('touch %(path)s/releases/current/%(project_name)s/%(project_name)s.wsgi' % env) diff --git a/cas/__init__.py b/src/cas/__init__.py similarity index 100% rename from cas/__init__.py rename to src/cas/__init__.py diff --git a/cas/logging.cfg b/src/cas/logging.cfg similarity index 100% rename from cas/logging.cfg rename to src/cas/logging.cfg diff --git a/cas/manage.py b/src/cas/manage.py old mode 100755 new mode 100644 similarity index 100% rename from cas/manage.py rename to src/cas/manage.py diff --git a/cas/settings.py b/src/cas/settings.py similarity index 97% rename from cas/settings.py rename to src/cas/settings.py index 38343ab..a039d14 100644 --- a/cas/settings.py +++ b/src/cas/settings.py @@ -22,7 +22,7 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with # although not all choices may be available on all operating systems. # If running in a Windows environment this must be set to the same as your # system time zone. -TIME_ZONE = 'Europe/Warsaw' +TIME_ZONE = 'Europe/Warsaw Poland' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html @@ -93,7 +93,7 @@ INSTALLED_APPS = ( LOGIN_URL = '/cas/login/' LOGOUT_URL = '/cas/logout/' CAS_CUSTOM_ATTRIBUTES_CALLBACK = 'utils.custom_attributes_callback' -SESSION_COOKIE_NAME = 'fnpcas_sessionid' +SESSION_COOKIE_NAME = 'fnpcas' # Python logging settings import logging diff --git a/cas/templates/cas/login.html b/src/cas/templates/cas/login.html similarity index 100% rename from cas/templates/cas/login.html rename to src/cas/templates/cas/login.html diff --git a/cas/templates/cas/logout.html b/src/cas/templates/cas/logout.html similarity index 100% rename from cas/templates/cas/logout.html rename to src/cas/templates/cas/logout.html diff --git a/cas/templates/cas_base.html b/src/cas/templates/cas_base.html similarity index 100% rename from cas/templates/cas_base.html rename to src/cas/templates/cas_base.html diff --git a/cas/urls.py b/src/cas/urls.py similarity index 100% rename from cas/urls.py rename to src/cas/urls.py diff --git a/cas/utils.py b/src/cas/utils.py similarity index 100% rename from cas/utils.py rename to src/cas/utils.py -- 2.20.1