Tuesday, September 30, 2008

Little secret: dev_appserver is_required



If you do skip around and rearrange the steps of the tutorials for Google App Engine, one thing you may try to do, is continually, incrementally, directly upload to Google, using appcfg.py update ...

Unfortunately, this won't work. If you use GQL and the Datastore API, you'll find that you need to run the local development server dev_appserver.py before deploying ... the dev server creates an index.yaml file, essentially mapping your db model and its use to Big Table. This gets deployed with your application. So, skipping this step (at least for most applications, which use the db) is not an option.

If you don't run the local dev_appserver, you'll get error messages from Google's servers when you run your webapp, like this:

Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 499, in __call__
handler.get(*groups)
File "/base/data/home/apps/2splice/1.31/main.py", line 20, in get
for greeting in greetings:
File "/base/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1257, in __iter__
return self.run()
File "/base/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1589, in run
query_run = self._proto_query.Run(*self._args, **self._kwds)
File "/base/python_lib/versions/1/google/appengine/ext/gql/__init__.py", line 581, in Run
res = bind_results.Get(self.__limit, offset)
File "/base/python_lib/versions/1/google/appengine/api/datastore.py", line 938, in Get
return self._Run(limit, offset)._Next(limit)
File "/base/python_lib/versions/1/google/appengine/api/datastore.py", line 887, in _Run
str(exc) + '\nThis query needs this index:\n' + yaml)
NeedIndexError: no matching index found.
This query needs this index:
- kind: Greeting
properties:
- name: date
direction: desc

Sunday, September 21, 2008

Google App Engine: quick-end-to-end



Here's a breathless, running narration of a one-hour attempt to get App Engine serving a web application.

A small complaint: the tutorials for Google App Engine are not geared towards getting a first real webapp deployed quickly. They are, instead, intended to give a web developer a pretty complete survey of the infrastructure for web development. Unfortunately, this means you really need to dig around to understand how to fully deploy, say, "helloworld" to "helloworld.com".

So, to address this deficit, here's an end-to-end, holistic version of the Google App Engine tutorial. I'm using a Macbook, running 10.4.11, and my domain name registrar is Network Solutions:

1) Gain registration-level control over the domain name: networks solutions, godaddy, register.com, etc.

2) Sign up for free Standard Google Apps, using that domain, here. (Update: here's the current link directly to the free Standard Google Apps edition)

3) Log into http://appengine.google.com/a/[your-domain-name].

4) Follow the instructions to name your app (after your-domain-name is easiest) ... you get an access code, for verification, on your cellphone.

5) Install Python 2.5 on your local machine, from here. No earlier version will work, but installers are available for all platforms. Note that after installation, on a Mac, you'll need to use Get Info on any python file, to make all python scripts open with the 2.5 Python launcher (which was just installed in your Applications directory).

6) Download the Google App Engine Launcher for your local machine, here. Copy it to your Applications directory before launching it. Launch and install. On the Mac you'll need to restart your shell (or terminal) to pick up the new python.

7) Then, from the first half of the third page of the tutorial:
a) create a your-app-name directory
b) within that directory, make an app.yaml file, as described above, changing 'helloworld' to your-app-name within the file.
c) borrow the "helloworld" app itself above, and copy it into a your-app-name.py file.
d) in the shell, cd to the parent of this directory
e) upload / deploy your app with appcfg.py update your-app-name/
f) appcfg will ask you for the email and password of your google app account.
g) back on your appengine overview page (http://appengine.google.com/), you'll get a notice that an app was successfully deployed.

8) On this page (http://appengine.google.com/) click the name of the app. This will bring you to your app engine app's dashboard.

9) Click "versions". Follow the instructions for "add domain" ... you will need to prove the domain by signing up for Google Apps from here (The instructions on that page read: Changing a CNAME Record), and then come back to versions->add domain, type the domain name and click "add domain ..." so that ghs.google.com. will handle CNAME aliases from your registrar.

10) Back at my registrar, I delete the A Record for www, and do an "advanced DNS" move: a CNAME alias for www, to ghs.google.com. This works, and my app is now hosted by google at the domain I want.

8, 9 and 10 can be stumbled upon here.