Introduction

An Albatross application can be deployed in a web server as a CGI (albatross.cgiapp), FastCGI (albatross.fcgiapp) or mod_python (albatross.apacheapp) application. It can also be deployed as a standalone HTTP server (albatross.httpdapp). To demonstrate each of these deployment options we're going to use a simple, single page application and a series of deployment scripts.

If you want to rebuild this entire example then you can copy all of the following files to a single directory that is accessible to Apache. (Don't forget to make the CGI scripts executable.)

The Application

First, here's the application module, app.py:

   1 from albatross import SimpleApp
   2                                                                                 
   3 class Home:
   4     name = 'home'
   5     def page_display(self, ctx):
   6         ctx.run_template('home.html')
   7                                                                                 
   8 class App(SimpleApp):
   9     def __init__(self, base_url, base_dir):
  10         SimpleApp.__init__(
  11             self,
  12             base_url=base_url,
  13             template_path=base_dir,
  14             start_page=Home.name,
  15             secret='-=secret=-'
  16             )
  17         self.register_page(Home.name, Home())

And here's the home.html template:

<html>
  <body>
    <p>Boo!</p>
  </body>
</html>

One thing to note is that app.py contains no deployment code. It's possible to put the deployment code into the application's main module but we're going to use separate "connector" scripts for this demonstration so that the application code needs no changes.

Deployment Scripts

Web Server

The deployment scripts, or "connector" scripts as I like to call them, are extremely simple. Their only purpose is to create an application instance and connect it to the web server. Hopefully the scripts are obvious so I will not go into much (if any) detail.

As mentioned above, I used Apache to test these. Here's a simple .htaccess file that may help:

Options +ExecCGI
AddHandler cgi-script cgi
AddHandler fastcgi-script fcgi
AddHandler python-program py
PythonHandler connector

CGI

CGIs are run from the directory they are in so the application's base_dir can be '.'.

connector.cgi:

                                                                                
from albatross import cgiapp
import app
                                                                                
theApp = app.App('connector.cgi', '.')
theApp.run(cgiapp.Request())

FastCGI

FastCGIs, like CGIs, are run from the directory of the script.

connector.fcgi:

                                                                                
from albatross import fcgiapp
import app
                                                                                
theApp = app.App('connector.fcgi', '.')
while fcgiapp.running():
    theApp.run(fcgiapp.Request())

mod_python

mod_python programs run inside Apache. mod_python adds the script's directory to the sys.path but the current working directory could be anywhere so this time we need to be explicit about where the application is installed so that the templates can be found.

connector.py:

   1 from albatross import apacheapp
   2 import app
   3 
   4 base_dir = '/home/matt/public_html/albatross/deploy'
   5                                                                                 
   6 theApp = app.App('connector.py', base_dir)
   7 def handler(req):
   8     return theApp.run(apacheapp.Request(req))

Standalone Server

The albatross.httpdapp module contains a simple, standalone HTTP server (based on Python's BaseHTTPServer) and a helper script, al-httpd.

standalone.py:

                                                                                
from albatross import httpdapp
import app
                                                                                
theApp = app.App('/', '.')

To run it use "al-httpd standalone.theApp 8001".

None: DeploymentOptions (last edited 2011-02-15 06:05:18 by localhost)