Build & Config

Managing a Padrino application

Cloud 66 supports applications based on the Padrino framework, a light-weight web framework built upon Sinatra.

Custom commands

Given that Padrino applications can have different database frameworks, we allow you to specify custom commands which are run at specific points during deployment:

  • Custom build command — This command will run every time until the first build is successful. Example: bundle exec rake db:seed
  • Custom deploy command — This command will run on every deployment (including initial build). Example: bundle exec rake db:migrate

These commands can be set via Toolbelt,

$ cx settings set -s my_app custom.build.command "rake db:seed"

$ cx settings set -s my_app custom.deploy.command "rake db:migrate"

But also in your manifest file.

development:
    padrino:
        configuration:
            custom_build_command: rake db:seed
            custom_deploy_command: rake db:migrate

Connect to your database

If a database is detected, it will automatically be provisioned as required (including the database itself), and environment variables will be created. You will need to update your code with the environment variables you wish to use, for example MYSQL_URL.

Should you wish to change the database username/password after build, you will have to do this manually, which will involve recreating backup jobs to reflect the new values.

Examples of connecting to your database

Active Record

MySQL YML

production:
  adapter: mysql2
  username: <%= ENV['MYSQL_USERNAME'] %>
  password: <%= ENV['MYSQL_PASSWORD'] %>
  host: <%= ENV['MYSQL_ADDRESS'] %>
  database: <%= ENV['MYSQL_DATABASE'] %>

Postgres YML

production:
  adapter: postgresql
  username: <%= ENV['POSTGRESQL_USERNAME'] %>
  password: <%= ENV['POSTGRESQL_PASSWORD'] %>
  host: <%= ENV['POSTGRESQL_ADDRESS'] %>
  database: <%= ENV['POSTGRESQL_DATABASE'] %>

Declarative

ActiveRecord::Base.configurations[:development] = {
  :adapter   => 'mysql2',
  :encoding  => 'utf8',
  :reconnect => true,
  :database  => ENV['MYSQL_DATABASE'],
  :pool      => 5,
  :username  => ENV['MYSQL_USERNAME'],
  :password  => ENV['MYSQL_PASSWORD'],
  :host      => ENV['MYSQL_ADDRESS'],
}

DataMapper

DataMapper::setup(:default, "ENV['POSTGRESQL_URL']")

MongoMapper

MongoMapper.connection = Mongo::Connection.from_uri(ENV['MONGODB_URL'])

Mongoid

development:
  sessions:
    default:
      database: mongoid
      hosts: ["<%= ENV['MONGODB_ADDRESS']%>:27017"]

Check your YAML

You can use Yamllint.com to check your YAML syntax before committing.

Previous
Configuring for Multi-Tenancy