Monday, October 24, 2011

Google AppEngine for Go - Installation and Setup

Setting up Google AppEngine for Go is real simple and can have you testing out functionality quickly. There are a few things that might be better to inform you early - they are simpler than setting up certain other development environments, so you might end up searching for complexity and ending up confused for not finding it.

A few things to note …
* The development environment has all the basic things that you would need built in - including a AppEngine server to test your applications with, a DataStore where you can store data similar to how you would eventually do with a live app hosted on the AppEngine servers, and other API support and tools that allow you to mimic the real AppEngine for purposes of development and testing.
* Since this AppEngine environment is for Go, there is also the appropriate Go compilers, packages, and tools as part of the download.
* If you have another separate installation of Go (like I have), it does not affect the AppEngine for Go setup.
* If you have the environment variable GOROOT set for the separate installation of Go, don’t change it. AppEngine knows where to pick up its version of Go (which happens to be "install root"/google_appengine/goroot).


I’m not sure if installing the “c tools” like gcc, awk, make, etc. is required to be installed. Since I had already installed the Go development environment separately, all these were already present. In any case, I would suggest that you start with this step: http://golang.org/doc/install.html#ctools.

Download and Install

1. Navigate to the webpage http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Go
2. Download the zip file appropriate to your system. My OS is a 64 bit Ubuntu 11.10 and so I download go_appengine_sdk_linux_amd64-1.5.5.zip
3. Extract to this file to a directory of your choice. It has one folder called google_appengine which contains the entire AppEngine for Go development environment.
4. For convenience add a PATH value to the path to the google_appengine folder since you will want to execute a file within it called dev_appserver.py. Since I have a bash shell for my Linux I added an entry to my .bashrc file in my home directory: PATH=$PATH:/home/vj/coding/golang/google_appengine
5. One additional note: when I extracted the .zip file, the python scripts did not have execute permissions. I needed to change the permissions of the python script to be executable. On my Linux machine, within the google_appengine folder, I ran the command: chmod +x *.py

If you have set the path and given the execute permissions (if required) as in steps 4 and 5, you can check if it is ok so far, by executing dev_appserver.py at the command line.

~/coding/golang/google_appengine$ dev_appserver.py
Invalid arguments
Runs a development application server for an application.

dev_appserver.py [options]

Application root must be …


Run a demo app

There are a few demo apps along with the SDK bundle. Let’s check one to ensure things are going good so far.

* Go to the directory google_appengine/demos. You should see a few folders, for example helloworld, guestbook, etc.
* From within the demos directory, execute the command: dev_appserver.py helloworld
* There might a few WARNINGs and INFOs, but if the last line is Running application helloworld on port 8080: http://localhost:8080, we are good.
* At this point the helloworld application has been instantiated within the local AppEngine server and is ready to serve the user on your machine at the port 8080.
* Open a browser and navigate to http://localhost:8080
* If you see a webpage with “Hello World” followed by a few UTF characters, great! It’s a successfully running Go web application executing on the AppEngine.
* On Linux you can stop the application and no longer serve user requests by stopping the script - Ctrl+C in the command window. After you’ve done this, trying to navigate to http://localhost:8080 will give you an error similar to “Page not found” or “Could not connect to server”, and you can thus know that the application is shut down.

3 comments:

  1. Followed it step by step.
    Awesome! Thanks

    ReplyDelete
  2. Thanks Satish, I really needed this!

    ReplyDelete
  3. Hi, I have a question. When I want to test dev_appserver.py --help, do I have to do this under the google_appengine folder?

    ReplyDelete

If you think others also will find these tutorials useful, kindly "+1" it above and mention the link in your own blogs, responses, and entries on the net so that others also may reach here. Thank you.

Note: Only a member of this blog may post a comment.