deploying a pylons app to google app engine

21
Deploying a Pylons app to Google App Engine Boston Python meetup - 6/18/08 Nate Aune www.jazkarta.com www.nateaune.com 1

Upload: jazkarta-inc

Post on 18-Dec-2014

6.744 views

Category:

Technology


3 download

DESCRIPTION

A presentation at the Boston Python Users Group demonstrating how to build a Pylons app and deploy it to Google App Engine.

TRANSCRIPT

Page 1: Deploying a Pylons app to Google App Engine

Deploying a Pylons app to Google App Engine

Boston Python meetup - 6/18/08

Nate Aunewww.jazkarta.comwww.nateaune.com

1

Page 2: Deploying a Pylons app to Google App Engine

Disclaimer #1"I just started using Pylons last week."

2

Page 3: Deploying a Pylons app to Google App Engine

Disclaimer #2"I just started using Google App Engine last week."

3

Page 4: Deploying a Pylons app to Google App Engine

App: Gigblastr

• Goal: make it easier to promote an event

• Fill out a form with event details

• Blast event to dozens of event listing sites

• Similar to TubeMogul but for events instead of videos.

4

Page 5: Deploying a Pylons app to Google App Engine

Tubemogul.com

5

Page 6: Deploying a Pylons app to Google App Engine

Add event

Title Poludaktulos Orchestra

Musician

The Poludaktulos Orchestra (the "Many-Fingered Orchestra") employs unique instrumentation in its lively performances of northern Greek brass band music.

URL http://myspace.com/poludaktulosorchestra

Description

Blast it!

Venue Johnny D's

Date 11/8/08

Start Time 9:00pm End 11:00pm

6

Page 7: Deploying a Pylons app to Google App Engine

Brief history

Implemented using content rules for Plone

• version 0.1 @ DevHouseBoston3 2007

• posting to Twitter and Eventful

• version 0.2 @ Home

• posting to Upcoming.org

• version 0.3 @ DevHouseBoston4 2008

• rewrite as Pylons app deployed to GAE

7

Page 8: Deploying a Pylons app to Google App Engine

Bootstrap with the appenginemonkey

$ svn co http://appengine-monkey.googlecode.com/svn/trunk ape-monkey$ cd ape-monkey$ python2.5 appengine-boot.py --paste-deploy ~/gae/gigblastr$ cd ~/gae/gigblastr$ source bin/activate(gigblastr)$ easy_install Mako==dev Pylons==dev Paste...(gigblastr)$ cd src(gigblastr)$ paster create --template=pylons GigBlastr(gigblastr)$ cd GigBlastr(gigblastr)$ python setup.py develop(gigblastr)$ python -m pth_relpath_fixup

8

Page 9: Deploying a Pylons app to Google App Engine

Configure your environment

• Edit development.ini[app:the-app]use = config:src/GigBlastr/development.ini

$ /usr/bin/python2.5 /usr/local/google_appengine/dev_appserver.py \ ~/gae/gigblastr/

• Launch the application

• Visit http://localhost:8080/

9

Page 10: Deploying a Pylons app to Google App Engine

Edit the routes

• In GigBlastr/config/routing.py

map.connect('', controller='hello', action='index')

• Create a 'hello' controller

$ paster controller hello

• Restart and visit http://localhost:8080/hello/index

10

Page 11: Deploying a Pylons app to Google App Engine

Hello Worldimport logging

from pylons import request, response, sessionfrom pylons import tmpl_context as cfrom pylons.controllers.util import abort, redirect_to

from gigblaster.lib.base import BaseController, render#import gigblaster.model as model

log = logging.getLogger(__name__)

class HelloController(BaseController):

def index(self): # Return a rendered template # return render('/template.mako') # or, Return a response return 'Hello World'

11

Page 12: Deploying a Pylons app to Google App Engine

Twitter

• In GigBlastr/controller/hello.py

import twitter

def tweet(self): api = twitter.Api(username='natea', password='xxxxxxx')

status = api.PostUpdate('testing tweets from GAE') return status.text

(gigblastr)$ easy_install python_twitter

• Restart and visit http://localhost:8080/hello/tweet/index

12

Page 13: Deploying a Pylons app to Google App Engine

Eventful

• In GigBlastr/controller/hello.py

import eventful

def evtful(self): api = eventful.API('xxxxxxxxxxxxx')

events = api.call('/events/search', q='music', l='Cambridge, MA') for event in events['events']['event']: print "%s at %s" % (event['title'], event['venue_name'])

(gigblastr)$ easy_install eventful

• Restart and visit http://localhost:8080/hello/evtful/index

13

Page 14: Deploying a Pylons app to Google App Engine

Upload app to GAE

$ cd gigblastr$ /usr/bin/python2.5 /usr/local/google_appengine/appcfg.py update .

• 973 files - whew!

• If your app has more than 1000 files, you'll have to remove some unused eggs.

14

Page 15: Deploying a Pylons app to Google App Engine

Remove _speedups

• Remove _speedups.py and _speedups.so from simplejson

• They are trying to cache on the file system, which is a no-no on GAE.

import simplejson File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/__init__.py", line 113, in <module> from encoder import JSONEncoder File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/encoder.py", line 6, in <module> from simplejson import _speedups File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/_speedups.py", line 7, in <module> __bootstrap__() File "/base/data/home/apps/gigblastr/1.8/lib/python2.5/site-packages/simplejson-1.8.1-py2.5-macosx-10.5-i386.egg/simplejson/_speedups.py", line 5, in __bootstrap__ del __bootstrap__, __loader__NameError: global name '__loader__' is not defined

15

Page 16: Deploying a Pylons app to Google App Engine

Guido, the creator of Python speaks!

16

Page 17: Deploying a Pylons app to Google App Engine

ianbicking to the rescue!

Ian responds one week later

17

Page 18: Deploying a Pylons app to Google App Engine

Use httplib on GAE

## If you want to use httplib but get socket errors, ## you should uncomment this line: appengine_monkey.install_httplib()

• In paste-deploy.py:

18

Page 19: Deploying a Pylons app to Google App Engine

No Twitter from GAE:(

19

Page 20: Deploying a Pylons app to Google App Engine

More info

• Google App Enginehttp://code.google.com/appengine/

• Pylonshttp://pylonshq.com

• Instructions for Pylons on GAEhttp://code.google.com/p/appengine-monkey/wiki/Pylons

• DevHouseBostonhttp://devhouseboston.org

20

Page 21: Deploying a Pylons app to Google App Engine

Thanks!

• To Ian Bicking for making appengine-monkey, making the instructions, and helping on IRC.

• The kind folks in #pylons who helped me get my head around Pylons syntax

21