Deploy your Padrino app on anynines in 3 steps

Matthias Günther (@wikimatze) runs vimberlin, a gathering for Vim-enthusiasts and is currently writing on his Padrino Book. As such he teamed up with our support team to write a How-to guide for Padrino deployments on anynines.

Padrino is a Ruby framework built upon the Sinatra web library, created to make it easy to code more advanced web applications while still sticking to what makes Sinatra great (like its simplicity). Think: creating a standard library of tools, helpers and functions that ready your Sinatra apps for increasingly complex requirements.

Fun fact: one of the teams applying to Rails Girls Summer of Code this year, proposed to work on Padrino over the course of the summer.

1. Get started with Padrino

To get started with Padrino, run the following commands:
$ gem install padrino
$ padrino g project padrino-hello-world-anynines
$ cd padrino-hello-world-anynines
$ bundle
$ padrino start

Yep, that’s it. The next part is to create a route in app/app.rb:
module PadrinoHelloWorldAnynines
class App < Padrino::Application
...
get "/" do
"Hello Padrino on anynines"
end
end
end

In case you can’t wait to see some code for a ‘Hello World’ program, check out my example app (with MySQL support) on GitHub. You can see the running app on padrino-hello-world-anynines-mysql.de.a9sapp.eu.

2. Get started with anynines

Let’s fetch the example app and deploy it to anynines, shall we?
$ git clone https://github.com/matthias-guenther/padrino-hello-world-anynines-mysql.git
$ cd padrino-hello-world-anynines-mysql/

Before you start it’s necessary to install Ruby 1.9.3 (or higher) and the a9s gem. After you’ve installed Ruby, go to your command line and install the a9s gem which downloads the needed gems for interacting with the anynines system:
$ gem install a9s

Next you will need to select the anynines api endpoint as target and authenticate with the auth service using your user credentials:
$ cf target https://api.de.a9s.eu
$ cf login --email [your@email] --password [yourpassword]

Push the application and follow the CLI to define your project space(s) and services – MySQL in our case:
$ cf push

anynines needs to have a Gemfile.lock for Padrino projects.

3. Use MySQL for your app

Make sure MySQL is in $PATH. If it isn’t, you will need to install a proper MySQL client like mysql-client-5.5 for Ubuntu.

Define the port in database.rb:

ActiveRecord::Base.configurations[:production] = {
:adapter => 'mysql2',
:encoding => 'utf8',
:reconnect => true,
:database => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['name'],
:pool => 5,
:username => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['username'],
:password => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['password'],
:host => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['hostname'],
:port => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['port']
}

Run your migrations:

cf push --command 'RACK_ENV=production bundle exec rake ar:migrate'

Finally, run the start command:

cf push --command 'RACK_ENV=production bundle exec padrino start -p $PORT -h $VCAP_APP_HOST'

If you now call padrino-hello-world-anynines-mysql.de.a9sapp.eu/ you can see the “Hello Matthias Günther, I know your email: matthias@wikimatze.de” in your browser. Scary, I know.

Enjoy developing with Padrino!

Leave a Reply

Your email address will not be published.