Search code examples
pythonwsgipyramidpasterdotcloud

Base path in paster configuration


I'm trying to deploy some Pyramid code to dotcloud. Unfortunately some paths are not mapped in the same way as in local paster deployment. When I'm running the development configuration with local server through paster serve ..., I can access static files configured in:

config.add_static_view('static', 'appname:static')

however on the dotcloud servers, when the scripts run via the following wsgi.py:

import os, sys
from paste.deploy import loadapp
current_dir = os.path.dirname(__file__)
application = loadapp('config:production.ini', relative_to=current_dir)

static content is searched for in a wrong directory. Instead of /home/dotcloud/current/static/pylons.css, it should look in /home/dotcloud/current/appname/static/pylons.css

Is there some part of wsgi configuration which can define the base directory? What am I missing? The application is run via nginx / uwsgi.

I tried to load config:../production.ini, relative_to=current_dir + '/appname' but that didn't change anything.


Solution

  • On DotCloud, URLs starting with /static are handled directly by nginx, not by uwsgi. That means that your code will never see those requests: they will be served straight away from the static/ subdirectory of your application.

    One possible workaround is to setup a symlink from static to appname/static.

    If you don't want to clutter your repository with such a symlink, you can use a postinstall script instead:

    #!/bin/sh
    # This creates the symlink required by DotCloud to serve static content from nginx
    ln -s ~/current/appname/static ~/current/static
    

    The symlink is sleek, but the postinstall scripts gives you the opportunity to drop in a comment in the file, to explain its purpose :-)

    Future releases of DotCloud might offer a "naked configuration" toggle, where the nginx configuration won't include any special path handling, just in case you don't want them.

    Meanwhile, if you want to see the nginx default configuration of your DotCloud service, you can just dotcloud ssh to your service, and inspect /etc/nginx/sites-enabled/default.