Developing for Google App Engine from ChromeOS

The backstory

The holiday season brings with it a lot of great things including family, traveling, and a lot of time to relax. I travel pretty frequently and am accustomed to the whole process. I make it a personal challenge to see how slim I can pack (much to the exasperation of my wife). For this trip, in particular, my goal was to only bring one laptop. As I was packing to go on vacation I basically had one rule: no work laptop.

No problem. I'll just use one of my laptops (I am an IT guy, after all). Well, as it turns out I only have two laptops. One is an ASUS G75VW, a 17.3" gaming laptop (it's really a mildly portable desktop), and the other is a 10" ASUS Chromebook Flip.

I love my Flip. It's got great battery life that lasts 10-12 hours and is the perfect size for traveling. If Erin and I go to a coffee shop I frequently just have her toss it in her purse next to her iPad. As a convertible laptop I can play games on planes during take-off/landing, but it still has a physical keyboard.

Chromebook Flip and a coffee.. the essentials

Alright, alright, to the point of this post. One project I wanted to work on during my down time was my GAEmes database. Normally I'd just remotely access a virtual machine running from my apartment to write and submit code. For whatever reason I decided it would be a fun challenge to see if I could completely adapt my workflow to allow for App Engine development from the cloud. This means no remotely accessing machines I've got stuffed away in my closet.

Coding in the cloud

The first step was to figure out some way of writing/testing code from ChromeOS. There were two paths I could take. I could either write code locally on my Flip and find some way to deploy it into App Engine or find some sort of cloud IDE that would allow me to write and test code from the browser.

I ended up going the cloud IDE route because it seemed a bit more true to the nature of my challenge. There are a couple of options out there: Nitrous.iocodeanywhere.com, and c9.io (to name a few). Nitrous seems to directly support App Engine development, but doesn't have a free tier. I ended up going with Cloud9 because it was free, integrated into GitHub, and I could get the App Engine devappserver working (sort of).

Setting up a Cloud9 Workspace

Setting up a Cloud9 workspace is surprisingly easy. You can set up a free account at c9.io or log in with your GitHub or Bitbucket credentials. The latter options give you instant integration with your repositories.

Once signed in you can either clone one of your pre-existing repos into a workspace, try out the test workspace, or create a new workspace from scratch. For the purpose of this post I'll assume you're creating a new workspace from scratch. Be sure the keep the custom template selected.

Create a workspace with the custom template

This will drop you into the Cloud9 IDE interface for your newly created workspace. I've found the tiling options to be super useful for working on a small screen. Of particular note you'll see a bash terminal at the bottom of your screen. That's where we'll need to do a little work.

Cloud9 IDE

Installing Python App Engine SDK

We need to download, install, and configure the Python App Engine SDK to handle debugging and deploying our app. Let's get started.

$ VERSION=1.9.30
$ cd ~/
$ wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_$VERSION.zip
$ unzip google_appengine_$VERSION.zip

You should now have a folder in the home directory called google_appengine. This contains everything you need to deploy your app. Google has some great documentation on uploading and deploying apps to AppEngine.

Note: The first time you use appcfg.py you'll need to specify the --noauth_local_webserver flag.

Set up devappserver2.py

At this point you have everything you need to deploy an app. However, the debugging process will pretty painful if you need to deploy to AppEngine to test any change. The dev app server is great for debugging, but requires a bit of hacking to make it work in the Cloud9 environment. Full credit for this bit goes to Ole over at stack overflow.

First, open up the devappserver code:
$ open ~/google_appengine/google/appengine/tools/devappserver2/devappserver2.py
This should open up devappserver2.py in the text editor. First, comment out the following lines (lines 827-830 in SDK 1.9.30).
admin = admin_server.AdminServer(options.admin_host, options.admin_port,
                              self._dispatcher, configuration, xsrf_path)
admin.start()
self._running_modules.append(admin)

Next, we need to add the second line below (currently located at line ~1030). I've added the previous line for context:

options = PARSER.parse_args()
# Add this next line
options.host = os.environ['IP']
Lastly, modify the following lines (currently 927-928):
return api_server.APIServer(options.api_host, options.api_port,
                            configuration.app_id)
to look like this.
return api_server.APIServer(os.environ['IP'], options.api_port,
                            configuration.app_id)
You should now be able to launch the devappserver (without the use of the admin console, sadly). Once serving you can use the preview menu to view the served content.


That's it! You should now be able to write, test, and deploy apps for AppEngine from a ChromeOS device.

~MJ