Ruby on Rails + MySQL on CloudControl

CloudControl is a pretty cool StartUp from Berlin. It is a PaaS Solution like Heroku.  CloudControl is hosting on AWS in Ireland. They are more flexible than Heroku. Beside the number of web processes you can choose how much RAM each instance should have. This is a cool features what you don’t get on Heroku. And you can have different environments on CloudControl for 1 single app. Check out their page: https://www.cloudcontrol.com/

Cloud-Control-logo-centered

I want to show here how you get started with your Ruby on Rails on CloudControl. First of all you have to sign up at CloudControl:  https://console.cloudcontrolled.com/

I assume you are familiar with GIT, Ruby and Linux/Mac OS X. First of all you have to install the CloudControl command line tool.

$ sudo easy_install pip
$ sudo pip install cctrl

The command line tool will be installed via pip, the python package manager. the CloudControl command line tool works similar to the Heroku command line tool. Let’s add your public SSH Key:

cctrluser key.add

In that way you don’t have to enter every time your credentials.

As next switch to the app root directory of your Rails App you want to deploy on CloudControl. Create an app on CloudControl:

cctrlapp APP_NAME create ruby

And now push your code to CloudControl:

cctrlapp APP_NAME push

The command above pushes your code but it doesn’t deploy it. Use this command to make a deployment:

cctrlapp APP_NAME deploy

Now check your app on :

http[s]://APP_NAME.cloudcontrolled.com

It is very likely that it is not running :-) No problem. You have to make some small changes to your Rails App. First of all, if you create an app on CloudControl it is without any database. That is a big difference to Heroku. Of course you can add a MySQL or Postgres DB as AddOn. Let’s add a MySQL:

cctrlapp APP_NAME/default addon.add mysqls.free

Don’t forget to add the “mysql2” GEM to your Gemfile. This is the driver for MySQL.

Now you have to customise your database.yml like this:

production:
  adapter: mysql2
  encoding: utf8
  database: <%= "'#{ ENV['MYSQLS_DATABASE'] }'" %>
  host: <%= "'#{ ENV['MYSQLS_HOSTNAME'] }'" %>
  port: <%= ENV["MYSQLS_PORT"] %>
  username: <%= "'#{ ENV['MYSQLS_USERNAME'] }'" %>
  password: <%= "'#{ ENV['MYSQLS_PASSWORD'] }'" %>
  pool: 100
  timeout: 5000

All right. One more step. You have to have a “Procfile” in the root of your Rails App with this content:

web: bundle exec rails s -p $PORT

That’s it. Now try again:

cctrlapp APP_NAME push
cctrlapp APP_NAME deploy

And check the URL :

http[s]://APP_NAME.cloudcontrolled.com

For me it worked quiet well. Let me know how it works for you.

One thought on “Ruby on Rails + MySQL on CloudControl

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s