Cross-posted from Phillip Smith
Lots is happening in the Perl Web framework world these days. The three main frameworks are getting better at a faster-and-faster rate, great screencasts are starting to appear, and – finally – Perl is moving into the cloud, thanks to support from new Platform-as-a-Service vendors like dotCloud.
I cracked open an old project this weekend with the intention of getting back to work on it. I thought I’d give dotCloud another try, as I wanted a quick way to have this application interact with OAuth providers (hard to do on my local machine). But I quickly noticed that many of the existing Perl Web framework on dotCloud posts – of which there are several – were a bit out of date, and didn’t reference dotCloud’s new command-line tool or way of deploying services. (Though, I should note, that they’re excellent posts and I steal from them liberally here.)
Anyway, after a bit of poking around, I had my app deployed on dotCloud and wanted to share the newer process for getting a bare-bones Catalyst application up-and-running in the cloud in 10-minutes:
I’m going to start by assuming that you have Catalyst running properly on your local development computer. If you’re not at that stage yet, you should probably read the Catalyst::Manual or grab a copy of the rather excellent The Definitive Guide to Catalyst.
Once you’ve got that sorted, run
catalyst.pl App::Nameto create the scaffolding for your application. I used
Catalyst::Defaultfor this example application, and I’ll use that app name throughout. Catalyst will create the scaffolding in a directory called
App-Name– so, in my case, that’s
Change your working directory to the app that you’ve just created, in my case that’s
cd Catalyst-Defualt. Let’s call this your app’s root directory for convenience to this walk through.
Next, you’ll want to link your
root/staticdirectory from the app’s root directory, because that’s where dotCloud will look for static files. You can do this with a simple
ln -s root/static static.
Then you’ll want to set-up support for PSGI. To do that, you can simply:
- Now edit the ‘app.psgi’ file and add the line
use lib 'lib'after the
use warningsline. Here’s mine:
At this point, if you’re aiming to deploy a real application, you should update your Makefile.PL with the modules, plugins, and so on that are required by the application. By doing this, dotCloud is able to install all the required Perl modules from CPAN automatically. This is the most impressive part of dotCloud to me – it’s simply amazing to watch how it handles complex dependency chains without breaking a sweat.
If you’re just going to deploy the default Catalyst application that is built by the scaffolding to follow along, you’ll want to add
requires 'Catalyst::Engine::PSGI';to your Makefile.PL. Add that after the other lines that start with
Now you’re ready to run your Makefile.PL (
perl Makefile.PL). Without this step, dotCloud won’t be able to parse your Makefile.PL and you’ll be stuck updating the dotcloud.yml with your dependencies. Not the end of the world, but create unnecessary redundancy.
Now we’re ready to let dotCloud know about our application. First, you’ll need to download and install the dotCloud command-line client.
dotcloud create appnamecommand to create your app. In my case, I just used
dotcloud create catalyst. (dotCloud doens’t seem to like names with any special characters, so you’ll need to choose something like ‘catalystdefault’ or ‘catalystappname’.)
You’ll need a dotcloud.yml file to tell dotCloud about the service your app requires – e.g., Perl, Python, Ruby, etc. – so fire up your favourite editor and open up dotcloud.yml and add these lines:
- Save that file in the root directory of your app. At this point, your app’s root directory should look like so:
- Now you’re ready to deploy your application into the dotCloud cloud. Drum roll please…. So, to do that, simply run
dotcloud push appname ..
At this point, you’ll want to go grab a coffee or beer or something because, if you’ve done everything right, the dotCloud build system will review your Mekefile.PL for dependencies and start installing Catalyst in your cloud instance so that your app can run properly. If that’s happening, you should see something like:
At the end of the process, you should see this line:
Visit the URL that dotCloud provided in your browser and, if you’re lucky, you should see this.
If you get a 404 or some other page, there was a problem along the way. To troubleshoot, just run
dotcloud logs catalyst.www (replacing ‘catalyst’ with the name you gave your app on dotCloud) – the ‘www’ indicates the name of the service you created in your dotcloud.yml. (We’ll dig a bit more into the different services in the next post.)
Let me know in the comments if you have any questions, if anything above is unclear (or could be clearer), or if you run into any problems. I’m not a dotCloud expert by any means, but I am starting to get my head around it.
Next up: Setting up a PostgreSQL data service.
Feel free to comment here or on the original post</small>