questions about integrating deform into production environment

60 views
Skip to first unread message

Jonathan Vanasco

unread,
Feb 3, 2012, 1:16:12 PM2/3/12
to pylons-discuss
under all the integration docs, deform ends up being set as a static
route under pyramid as /deform

i'm wondering - has anybody put together a solution that can have one
of these ( or similar ) happen during the startup/config process :

1- copy deform's /static files to app/static/deform
2- symlink deform/static to app/static/deform ( or an option of your
choice )

one of those options would greatly simplify setup and rewrites on
proxy and caching servers - as all the deform dependents would then
fall under existing rules


Kai Groner

unread,
Feb 6, 2012, 12:01:13 PM2/6/12
to pylons-...@googlegroups.com
This works:
      config.add_static_view('static/deform', 'deform:static')
      config.add_static_view('static', 'myapp:static')


Kai

Chris McDonough

unread,
Feb 6, 2012, 12:06:06 PM2/6/12
to pylons-...@googlegroups.com

Note also that this works:

config.add_static_view('http://another/static/file/server',
'deform:static')

- C


>
>
>
>
>
> Kai
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/e3oMXi47emoJ.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discuss
> +unsub...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.


Jonathan Vanasco

unread,
Feb 6, 2012, 12:29:42 PM2/6/12
to pylons-discuss
Sorry, i think I was unclear:

If i do either of those methods, which i do now, requests are still
going through the WSGI server.

- I want to bypass that completely, by making the actual files of the
referenced deform library directly accessible to the frontend server
( which would be nginx or varnish ).
- I don't want pyramid to ever handle these files
- I want to ensure that the files are 'up to date' ( ie, not have to
continually copy the deform static files )

Chris McDonough

unread,
Feb 6, 2012, 12:31:08 PM2/6/12
to pylons-...@googlegroups.com
On Mon, 2012-02-06 at 09:29 -0800, Jonathan Vanasco wrote:
> Sorry, i think I was unclear:
>
> If i do either of those methods, which i do now, requests are still
> going through the WSGI server.

The example I gave is not. See
http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/assets.html#serving-static-assets paragraph starting with "Instead of representing a URL prefix,...."

> - I want to bypass that completely, by making the actual files of the
> referenced deform library directly accessible to the frontend server
> ( which would be nginx or varnish ).
> - I don't want pyramid to ever handle these files
> - I want to ensure that the files are 'up to date' ( ie, not have to
> continually copy the deform static files )

Use a symlink and the above.

- C

cd34

unread,
Feb 6, 2012, 1:37:47 PM2/6/12
to pylons-discuss
On Feb 3, 1:16 pm, Jonathan Vanasco <jonat...@findmeon.com> wrote:
> 1- copy deform's /static files to app/static/deform
> 2- symlink deform/static to app/static/deform ( or an option of your
> choice )

In apache, I've always done something like:

Alias /deform/static /var/www/pyr27/lib/python2.7/site-packages/
deform-0.9.3-py2.7.egg/deform/static

For nginx:

location ^~ /deform/static {
alias /var/www/pyr27/lib/python2.7/site-packages/deform-0.9.3-
py2.7.egg/deform/static;
}

In order to prevent Apache or Nginx from seeing the requests, the
webserver itself needs to handle those before handing it to the wsgi
process.

If you are using mod_wsgi, merely having the files in the right place
only works if you are using a mod_rewrite that tests -f and then
passes to mod_wsgi. If you're running with WSGIScriptAlias, you need
to make sure your alias is set before the ScriptAlias line since
Apache parses config files in order.

cd34

unread,
Feb 6, 2012, 1:37:49 PM2/6/12
to pylons-discuss
On Feb 3, 1:16 pm, Jonathan Vanasco <jonat...@findmeon.com> wrote:
> 1- copy deform's /static files to app/static/deform
> 2- symlink deform/static to app/static/deform ( or an option of your
> choice )

cd34

unread,
Feb 6, 2012, 1:39:22 PM2/6/12
to pylons-discuss
On Feb 6, 12:29 pm, Jonathan Vanasco <jonat...@findmeon.com> wrote:
> ( which would be nginx or varnish ).

If you are using Varnish, designing your VCL well enough would fix the
requests from hitting the backend too frequently and would be almost
hands-off as you wouldn't have any external config file for apache/
nginx to change if you upgraded deform.

Jonathan Vanasco

unread,
Feb 6, 2012, 1:51:58 PM2/6/12
to pylons-discuss
yep, know all that.

I meant i wanted to know if anyone has automated this for production ,
as part of a pyramid/deform integration package

essentially the following:

---------------

myapp/__init__.py
from pyramid.events import ApplicationCreated
from pyramid.events import subscriber

config.add_subscriber('myapp.subscribers.deform_static_prep',
'pyramid.events.ApplicationCreated')


myapp/subscribers/deform_static_prep.py

import deform
import os

def deform_static_prep(event):

static_subdir=
event.request.registry.settings['deform.static_subdir']

deform_dir= os.path.dirname(deform.__file__)
deform_dir_static= os.path.join( deform_dir , 'static' )

app_dir= os.path.dirname( myapp.__file__ )
app_dir_static= os.path.join( app_dir , 'static' )
app_dir_static_deform= os.path.join( app_dir_static ,
static_subdir )

if os.path.lexists(app_dir_static_deform):
os.unlink(app_dir_static_deform)

os.symlink( deform_dir_static, app_dir_static_deform )

Jonathan Vanasco

unread,
Feb 6, 2012, 2:00:03 PM2/6/12
to pylons-discuss
the line above should actually be:

static_subdir= event.app.registry.settings['deform.static_subdir']


Chris McDonough

unread,
Feb 6, 2012, 2:28:29 PM2/6/12
to pylons-...@googlegroups.com

No.. I'd never do that as part of an app. I might cause a build script
to do it, but I'd never make the app itself responsible.

- C


cd34

unread,
Feb 6, 2012, 2:36:38 PM2/6/12
to pylons-discuss
If you wanted to automate, put it in the git hooks, puppet or
capistrano or whatever deployment engine configs.

I can see a use case for having the Pyramid app do it, but, your
deployment scripts are a better place to make those decisions, though,
it is a little more than just dropping a Pyramid app into place.
Reply all
Reply to author
Forward
0 new messages