This is a 4 part series.
Don’t forget to grab the other parts as well:
- Beginning cloud development with cloudControl – Part 2 – MySQL
- Beginning cloud development with cloudControl – Part 3 – MongoDB
- Beginning cloud development with cloudControl – Part 4 – Memcache
So you’ve heard all about the cloud. In the current day and age, you’d have to be living under a rock to have not encountered it by now. Whether it’s the ads from Amazon, Rackspace or Microsoft, the extensions to your favourite framework, such as SimpleCloud in Zend Framework or iCloud from Apple – The Cloud is Everywhere!
But these aren’t the only options available to us as developers. In this series I want to introduce you to and help you get started with another cloud service – cloudControl. We’re going to build a simple user list application where we can add, edit, delete and list users for a small, company.
The application will use some of the cloudControl core features, including:
Through doing this we’re going to get a good overview of what it takes to build an application, how to work with the web interface and command line tools and to push and deploy our changes out and see them live. So with that, let’s get started with cloudControl.
To follow along with this series, you’re going to need the following tools:
- An ssh public key
This tutorial is being carried out under Mac OSX but will work equally well if you’re using Linux.
If you’re on Windows please have a look at the Windows setup page. You’ll need to download the Windows Installer and install the Microsoft Visual C++ 2008 Redistributable Package (x86) to get started.
What is cloudControl
cloudControl is a service that I came across recently and was pretty impressed with right from the get-go. Based out of Berlin, Germany, cloudControl is a service that allows you to develop and deploy to the cloud hassle free and when you need more power, autoscale accordingly.
More specifically, cloudControl is a Platform as a Service (PaaS). According to wikipedia, a PaaS is:
A category of cloud computing services that provide a computing platform and a solution stack as a service. In the classic layered model of cloud computing, the PaaS layer lies between the Software as a Service (SaaS) and the Infrastructure as a Service (IaaS) layers.
PaaS offerings facilitate the deployment of applications without the cost and complexity of buying and managing the underlying hardware and software and provisioning hosting capabilities, providing all of the facilities required to support the complete life cycle of building and delivering web applications and services entirely available from the internet.
Well that’s exactly what cloudControl allows us as developers to do. It provides the infrastructure and hosting provisioning capabilities that allow us to deploy our applications to the web with a minimum of hassle, effort and time.
In this introductory post on cloudControl, I’m going to give you a rapid overview on getting started with the service. By the time we’re finished, you’ll have your first, introductory, application developed and deployed to the cloud, ready for the world to use.
Pricing for the service is based on two key criteria:
- Number of boxes
- Number and type of add-ons
A box is what you would normally think of when hosting your web applications – they’re effectively a standard server or VPS, running your code, responding to HTTP requests. All accounts get one box free which can host unlimited applications and receive unlimited traffic. You can then nominate to have more than one box be available for autoscaling as needed to handle performance spikes as and when they occur – de-scaling when the load subsides.
One box will be sufficient for the purposes of this tutorial series. However, in later posts, we may look at scaling across multiple boxes to simulate how the service responds when needed.
Besides one ore more boxes, with cloudControl, you get the following optional add-ons:
- Cron – available for either hourly or daily jobs
- Workers – Allow you to perform extra work as required
- Xeround Cloud Database – an elastic, always-on cloud database that lets you run your MySQL applications in the cloud
- New Relic – The only tool you need to pinpoint and solve performance issues in your code – regardless of language.
With all these features, you can deploy pretty robust applications that expand and shrink as needed to meet your demand requirements and allow you to monitor performance intimately. Now, on to the getting started steps.
To determine the amount you’ll be paying per/month, consult the pricing calculator, which is very simple to use.
Creating the basic application
Step 1 – Signing Up for An Account
In your browser of choice, head on over to the sign-up page at http://cloudcontrol.com/sign-up/. When you’re there, enter your primary account details:
- email address
Once you’ve submitted this form, you’ll receive an account confirmation email to the email address that you entered and your account activation code. Clicking on the link will take you to the account activation form. Enter the activation code that you received and click ‘Activate‘ and your account is ready to use.
Step 2 – Login to your account
After you activate your account, you’re taken to the confirmation page which contains the login form. Login and you’ll see the details for your account.
Step 3 - Create a Local Project
Now, in the current iteration cloudControl involves a fair amount of command-line interaction. But this can be easily automated whether through shell scripts or when integrated with a CI server such as Hudson, Cruise Control or Webistrano. But for the remainder of this script, there’s going to be a bit of command-line work, so open up that terminal and let’s continue.
Open up the App Quickstart and install the base package. The commands are:
# install the cctrl application sudo easy_install cctrl # create a public key (if required) ssh-keygen -b 2048 # add the public key to the cloudControl account cctrluser key.add ~/.ssh/id_rsa.pub # add the public key to the user agent ssh-add
Now, in your project directory, create the file index.php with the following content:
<html> <head> <title>Malt Blue / Cloud Control :: Test Project</title> </head> <body> <h1>Malt Blue / Cloud Control :: Test Project</h1> <p>Hello World</p> </body> </html>
Now, with git, stage the file and then commit it to the project. The following commands will suffice:
git init git add index.php git commit -m 'First addition of the bootstrap file to the project'
You’ll see the file be staged and committed to your local repository. All being well, there were no errors. If there weren’t, continue along to step 4.
Step 4 – Commit the local changes
Ok, now that the base foundation is out of the way, cd to your local branch and run the following commands, where APP_NAME is the name of your application. For the purposes of this tutorial, it will be maltbluedev. So run the following commands:
# create the application in cloudControl cctrlapp <strong>maltbluedev</strong> create php
We’ve now configured our project to use cloudControl to deploy to.
Step 5 – Propogating & Deploying changes to cloudControl
Ok, we’re getting close to being done. Now we need to propagate the changes to cloudControl and then deploy the changes to our deployment environment. In the terminal, run the following two commands:
# pushes the changes to cloudControl cctrlapp maltbluedev/default push # deploys our latest changes to our live environment cctrlapp maltbluedev/default deploy
Step 6 – Viewing the running site
Now that the latest changes have been deployed, we’re ready to view our first site. To do that, go to: http://maltbluedev.cloudcontrolled.com. When you’re there, you’ll see a page just like the following:
The initial, or first deployment, is always called default, this is effectively your live environment. However, in normal development practice we have multiple environments, i.e., testing, staging etc. But how do you achieve this in a fluid manner with cloudControl.
To setup multiple environments, all you need to do is to create a branch in your repository for each environment that you require. Following that, you need to create a new deployment and propagate and push the changes out to it. After this, you’ll then have the respective environments ready to use. They’ll be available via the following URI syntax:
As a simple example, I’ve created a staging environment for our simple project. In the screenshots below, you can see that I’ve done the following:
- Created the new staging branch
- Switched to it
- Made a change to index.php
- Committed it to the repository
- Created a staging deployment
- Propagated the changes to cloudControl
The Staging Version
Only one thing to do – view the staging version of the site. In the final screenshot below, you can see the staging version of the site, with the slightly amended html. Now you can see the staging environment at: http://staging.maltbluedev.cloudcontrolled.com. Nothing could be simpler.
What could be simpler? Not much really. Now this has been a simple example, but it really shows the power of cloudControl.
- You don’t need to have all the infrastructure all the time
- You don’t need to be a master systems administrator nor have a dedicated staff of them
- You don’t need to know the ins and outs of all the latest technologies
- It’s painlessly simple to setup and deploy multiple environments
Through simple commands that are automatable with either a proper deployment script or continuous integration server, you can have what you need as you need it and autoscale as your needs demand.
Where to from here
I’m sure you’ll agree that this first example is pretty simple. So what about adding in a database backend? In part 2, we really start to put the application together – and we’re starting with MySQL.
This is a 4 part series.
Don’t forget to grab the other parts as well: