Sinatra, Getting Started
Cloud Foundry provides support for Sinatra applications. Work through this guide to create a sample application and deploy it to Cloud Foundry.
To complete this quickstart guide, you need to fulfill the following prerequisites;
Create a folder for your Rack application and create a basic application structure.
$ mkdir sinatra_hello_world $ cd sinatra_hello_world $ touch hello_world.rb config.ru Gemfile
Initialise both files as follows;
require 'sinatra/base' class HelloWorld < Sinatra::Base get "/" do "Hello, World!" end end
require './hello_world' run HelloWorld.new
source 'https://rubygems.org' gem 'sinatra'
Install the required Sinatra gem using Bundler;
$ bundle install
You should be able to run the application locally by using Rackup;
$ rackup >> Thin web server (v1.4.1 codename Chromeo) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:9292, CTRL+C to stop
View your application at http://localhost:9292
Push the application with CF;
$ cf push Name> sinatra-hello-world Instances> 1 1: 64M 2: 128M 3: 256M 4: 512M 5: 1G 6: 2G 7: 4G 8: 8G 9: 16G Memory Limit> 128M Creating rack-test... OK 1: sinatra-hello-world.cloudfoundry.com 2: none URL> sinatra-hello-world.cloudfoundry.com Updating rack-test... OK Create services for application?> n Bind other services to application?> n Save configuration?> n Uploading sinatra-hello-world... OK Starting sinatra-hello-world... OK Checking sinatra-hello-world... OK
Once this is deployed, you should be able to view the application on Cloud Foundry at the URL you chose during the push.
Binding and using a service with Ruby is covered here