WebStack

Annotated docs/deploying.html

656:100da1109ca3
2007-09-08 paulb [project @ 2007-09-08 17:04:24 by paulb] Added missing copyright file.
paulb@654 1
<?xml version="1.0" encoding="iso-8859-1"?>
paulb@348 2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
paulb@601 3
<html xmlns="http://www.w3.org/1999/xhtml"><head>
paulb@654 4
  <title>Deploying a WebStack Application</title>
paulb@601 5
  <link href="styles.css" rel="stylesheet" type="text/css" /></head>
paulb@328 6
<body>
paulb@330 7
<h1>Deploying a WebStack Application</h1>
paulb@330 8
<p>The process of deploying a WebStack application should be as
paulb@348 9
straightforward as taking some adapter or "glue" code and either
paulb@348 10
running it
paulb@348 11
or using the deployment processes of the server environment or
paulb@348 12
framework in
paulb@330 13
which the application will be living.</p>
paulb@330 14
<h2>The Adapter Code</h2>
paulb@330 15
<p>What adapter or "glue" code does is to set up your applications main
paulb@330 16
resource object and to hook that object up with the underlying server
paulb@601 17
environment. For the&nbsp;<code>MyApplication</code> <a href="resources.html">example</a>, together with a simple environment,
paulb@349 18
looks something like
paulb@348 19
this:</p>
paulb@349 20
<pre>from WebStack.Adapters.BaseHTTPRequestHandler import deploy    # import the support for the server environment<br />from MyApplication import MyResource                           # import the main resource class<br />print "Serving..."<br />deploy(MyResource())                                           # connect a resource object to the server environment</pre>
paulb@348 21
<p>In the case of BaseHTTPRequestHandler, which is a module in the
paulb@348 22
Python standard library, you can just run this code, making sure that
paulb@348 23
the <code>MyApplication</code> module or package is on your <code>PYTHONPATH</code>.
paulb@348 24
Then, you can visit&nbsp;<code>http://localhost:8080</code> in your
paulb@601 25
browser and see the result.</p><h3>Root Resources and Site Maps</h3><p>The
paulb@601 26
above example suggested the direct deployment of a specific resource,
paulb@601 27
and this was quickly achieved by instantiating the resource within the
paulb@601 28
call to the <code>deploy</code> function. However, it may be more
paulb@601 29
desirable to have an application provide a function within the module
paulb@601 30
or package containing the resources which causes their initialisation
paulb@601 31
in a more sophisticated fashion and which returns a resource object
paulb@601 32
ready for use. Let us suppose that the <code>MyApplication</code> module provides a function for this purpose:</p><pre>from WebStack.Adapters.BaseHTTPRequestHandler import deploy    # import the support for the server environment<br />from MyApplication import get_site_map                         # import the function indicating the "root" resource<br />print "Serving..."<br />deploy(get_site_map())                                         # connect a resource object to the server environment</pre><p>Whilst
paulb@601 33
this appears to be trading one name for another, the intent is really
paulb@601 34
to provide a layer of abstraction which hides the details of resource
paulb@601 35
classes from the deployment code, even if the <code>get_site_map</code> function is only as simple as the following:</p><pre>def get_site_map():<br />    return MyResource()</pre><p>Of course, this function may be made more complicated as the need arises.</p>
paulb@349 36
<h3>More Demanding Adapter Code</h3>
paulb@330 37
<p>Unfortunately, not all server environments can be connected up with
paulb@330 38
applications this easily. Some environments require special classes and
paulb@349 39
functions to be defined in the adapter code in order for
paulb@348 40
applications to
paulb@349 41
be properly integrated into those environments. A summary of the
paulb@601 42
requirements of each environment can be found in <a href="writing-adapters.html">"Writing Adapters"</a>.</p>
paulb@330 43
<h2>The Deployment Process</h2>
paulb@330 44
<ul>
paulb@330 45
  <li><a href="writing-adapters.html">Writing Adapters</a></li>
paulb@331 46
  <li><a href="pythonpath.html">Getting PYTHONPATH Right</a></li>
paulb@330 47
  <li><a href="deploying-applications.html">Deploying an Application</a></li>
paulb@330 48
</ul>
paulb@654 49
</body></html>