Compiled Websites with Plone, Django, Xapian and SSI

26
Compiled Websites with Plone, Django and SSI Łukasz Langa Wojciech Lichota

description

Slides from RuPy 2009 talk "Compiled Websites with Plone, Django, Xapian and SSI" by Łukasz Langa and Wojciech Lichota.

Transcript of Compiled Websites with Plone, Django, Xapian and SSI

Page 1: Compiled Websites with Plone, Django, Xapian and SSI

"

Compiled Websites with Plone, Django and SSI

Łukasz Langa"Wojciech Lichota"

Page 2: Compiled Websites with Plone, Django, Xapian and SSI

Agenda

  Reasoning

  Plone and Static Deployment

  Django and SSI

  Search (Xapian)

Page 3: Compiled Websites with Plone, Django, Xapian and SSI

Reasoning

  Security solutions requiring 100% guarantee that the content cannot be edited from the Web

  Performance dynamic Websites are resource hungry

  Quality Assurance the ability to review complete content and functionality before every deployment

The Problem

Page 4: Compiled Websites with Plone, Django, Xapian and SSI

Reasoning

  Security front-end/back-end division

two-level authentication

  Performance throwing hardware at the problem

caching

  Quality Assurance dedicated workflow environments

test instances

Existing Approaches

Page 5: Compiled Websites with Plone, Django, Xapian and SSI

Reasoning The Solution

Website compilation

Page 6: Compiled Websites with Plone, Django, Xapian and SSI

The Solution Static Deployment

  Convert all Website resources to static files   HTML

  CSS

  JS

  attachments

  media

  Deploy the HTML on a traditional Web server ✓  orders of magnitude

better performance

✓  incredibly simple scalability

✓  server-agnostic quality assurance

Page 7: Compiled Websites with Plone, Django, Xapian and SSI

Static Deployment with external tools

  Examples:   HTTrack    wget  -­‐-­‐mirror  

✓  out-of-the-box solution

✗  weak control of output

✗  slow

Page 8: Compiled Websites with Plone, Django, Xapian and SSI

Static Deployment with internal tools

  Solutions for Plone:   enpraxis.staticsite    stxnext.staticdeployment  

✓  much faster than external solutions

✓  fully configurable

✓  easy to customize

✗  needs integration with website

Page 9: Compiled Websites with Plone, Django, Xapian and SSI

Static Deployment stxnext.staticdeployment  

  Open-Source (ZPL)

  two parts of configuration   basic: for content editors

  advanced: for administrators

  incremental

  content transformations

  pluggable

  integration with Xapian

Page 10: Compiled Websites with Plone, Django, Xapian and SSI

stxnext.staticdeployment  

Page 11: Compiled Websites with Plone, Django, Xapian and SSI

stxnext.staticdeployment  

Page 12: Compiled Websites with Plone, Django, Xapian and SSI

Static Deployment ...too static!

  User profiles

  Commenting

  User communication

  Search

We need something more sophisticated!

Page 13: Compiled Websites with Plone, Django, Xapian and SSI

The Solution   Plone + Static

Deployment

  Django for:   User profiles

  Commenting

  User communication

  Xapian for search

Compiled Website

Page 14: Compiled Websites with Plone, Django, Xapian and SSI

The Solution How to glue components together?

  client-side approach: JavaScript ✓  simple implementation

✗  many requests

✗  page flickering

  server-side approach: Apache SSI

✓  single request

✓  transparent to the user

✗  skin customization Compiled Website

Page 15: Compiled Websites with Plone, Django, Xapian and SSI

The Glue Apache mod_include (SSI)

  HTML preprocessor provided by Apache httpd at least since version 1.3

  Processing controlled by SGML comments

  Basically enables:   conditional text

  inclusion of other files

  inclusion of programs

  printing/setting environment variables

Page 16: Compiled Websites with Plone, Django, Xapian and SSI

Apache m

od_include

  A basic SSI element:

<!-­‐-­‐#element  attribute=value  attribute=value  ...  -­‐-­‐>    

  Typical elements:   #include    #echo    #exec    #set    #if  /  #elif  /  #else  /  #endif  

no whitespace

Page 17: Compiled Websites with Plone, Django, Xapian and SSI

Apache m

od_include

  Enabling SSI in the server configuration:

...  LoadModule  include_module  modules/mod_include.so  ...  AddType  text/html  .html  AddOutputFilter  INCLUDES  .html  ...  Options  +Includes  

  Examples of basic directives:   current date on the server

<!-­‐-­‐#echo  var="DATE_LOCAL"  -­‐-­‐>

  file modification date Last  modified:  <!-­‐-­‐#flastmod  file="index.html"  -­‐-­‐>

  inclusion of results from a dynamic application <!-­‐-­‐#include  virtual="/app-­‐comments/thread/3/"  -­‐-­‐>  

  executing local commands <!-­‐-­‐#exec  cmd="uptime"  -­‐-­‐>  

Page 18: Compiled Websites with Plone, Django, Xapian and SSI

Apache m

od_include

  Inclusion of results from a dynamic application <!-­‐-­‐#include  virtual="/app-­‐comments/thread/3/"  -­‐-­‐>  

  How to specify an external application to be available from /app-­‐comments  ?

RewriteEngine  on  RewriteRule  ^/app-­‐comments/(.*)$  http://localhost:8686/$1  [L,P]  

  What if the external application is not available?   Apache includes the following message by default:

[an  error  occurred  while  processing  this  directive]  

  This can be customized in server configuration by:

SSIErrorMsg  "<!-­‐-­‐  Error  -­‐-­‐>”  

  The default message can be overriden in HTML by:

<!-­‐-­‐#config  errmsg=”Custom  message"  -­‐-­‐>  

Page 19: Compiled Websites with Plone, Django, Xapian and SSI

Gotchas Gluing Django with SSI

  context-specific arguments need to be GET params   by default Django uses

URL parts

  redirect after POST requests   POST requests cannot

render anything

  form validation requires additional plumbing

  Website templating in two places   Plone skin

  Django templates

Page 20: Compiled Websites with Plone, Django, Xapian and SSI

Gotchas Apache httpd

  Apache is slow...

Page 21: Compiled Websites with Plone, Django, Xapian and SSI

Gotchas Apache httpd

  Apache is slow... NOT!   mpm_prefork  is evil

  use mpm_worker  

  any experience with mpm_event?

  Advantages of Apache:   largest install base

  maturity measured in years

  the best WSGI module available (mod_wsgi)

Page 22: Compiled Websites with Plone, Django, Xapian and SSI

What about search? Xapian with SSI

   python-­‐xapian  binding

  Ranked search

  Suggests spelling corrections

  no Polish stemming

Page 23: Compiled Websites with Plone, Django, Xapian and SSI

"

Compiled Websites Starring

Łukasz Langa"lukasz.langa.pl [email protected] @llanga

Page 24: Compiled Websites with Plone, Django, Xapian and SSI

"

Compiled Websites Starring

Wojciech Lichota

www.lichota.pl [email protected] @wlichota

Page 25: Compiled Websites with Plone, Django, Xapian and SSI

"

Compiled Websites Guest Starring

Django Pony

www.djangopony.com @djangopony

Page 26: Compiled Websites with Plone, Django, Xapian and SSI

Questions?