Deploying A TurboGears Project to DotCloud
2012-03-20 08:57:23 | 1 Comment
Hello everyone!
Recently I have seen a cloud service called DotCloud. It seemed nice and I wanted to check its Python support. I've looked at their documentation and saw their Django docs which basically means they support WSGI. I also wanted to see how much effort does it take to deploy on this service. I have jumped in, signed up and tried to deploy a very simple quickstarted TurboGears project to DotCloud. It went well.
Let's go ahead and deploy a quickstarted project.
First of all, you need a DotCloud account. After signin up, [you need to install "dotcloud" cli](http://docs.dotcloud.com/firststeps/install/).
Now that we are free to go, let's create our TurboGears project.
$ virtualenv --no-site-packages tg2env
$ cd tg2env/
$ source bin/activate
(tg2env)$ easy_install -i http://tg.gy/current tg.devtools
(tg2env)$ paster quickstart -x -n -m example
(tg2env)$ cd example
(tg2env)$ python setup.py develop
What will the above commands do?
* Create a virtual Python environment.
* Install TurboGears and its dependencies.
* Creates a TurboGears project with no database and authentication support
and using mako templates.
For more information, you can run `paster quickstart --help` command or visit [Quickstarting A TurboGears2 Project](http://turbogears.org/2.1/docs/main/QuickStart.html) documents.
We need requirements.txt file because DotCloud uses pip to install our project's dependencies. Next, create a file called requirements.txt and add the following:
# requirements.txt
-i http://www.turbogears.org/2.1/downloads/current/index
tg.devtools
Let's create an application in the cloud with `dotcloud create tgtest` command. "How it is going to work" you are wondering. It will not work unless we put up a simple file called `wsgi.py` in our example/ project with the following content:
# wsgi.py
from paste.deploy import loadapp
application = loadapp('config:/home/dotcloud/current/development.ini')
In our project directory we need to create a dotcloud.yml file so DotCloud knows what we are going to use.
# dotcloud.yml
www:
type: python
We have one thing left. Since this is not an application in the wild and just for testing purposes, we leave the configuration file as development.ini. In this file, there is directive `debug = true`, set it to false like `debug = false`. Now, we are ready to go and push our project.
dotcloud push tgtest
Sit back and enjoy the output in your terminal, until you see:
18:54:28 [www] Using /home/dotcloud/env/lib/python2.6/site-packages
18:54:28 [www] Finished processing dependencies for example==0.1dev
18:54:32 [www] Build completed successfully. Compiled image size is 17MB
18:54:32 ---> Initializing new services... (This may take a few minutes)
18:54:32 [www.0] Initializing...
18:54:42 [www.0] Service initialized
18:54:44 ---> All services have been initialized. Deploying code...
18:54:44 [www.0] Deploying build revision rsync-1332269603326...
18:54:50 [www.0] Running postinstall script...
18:54:52 [www.0] Launching...
18:54:53 [www.0] Waiting for the service to become responsive...
18:54:54 [www.0] Re-routing traffic to the new build...
18:54:55 [www.0] Successfully deployed build revision rsync-1332269603326
18:54:55 ---> Deploy finished
Deployment finished. Your application is available at the following URLs
www: http://tgtest-mengu.dotcloud.com/
Good luck!
Did you enjoy this post? You should follow me on twitter here.


Comments
Leave a Response