Deploy a Sample Ruby on Rails Application

Page last updated:

This topic guides the reader through deploying a sample Ruby on Rails app to Pivotal Web Services (PWS) .


In order to deploy a sample Ruby on Rails app, you must have the following:

Step 1: Clone the App

Run the following terminal command to create a local copy of the cf-sample-app-rails.

$ git clone
The newly created directory contains a manifest.yml file, which assists CF with deploying the app. See Deploying with Application Manifests for more information.

Step 2: Log in and Target the API Endpoint

  1. Run the following terminal command to log in and target the API endpoint of your deployment. Use as your API endpoint.

    $ cf login -a YOUR-API-ENDPOINT
  2. Use your credentials to log in, and to select a Space and Org.

Step 3: Create a Service Instance

Run the following terminal command to create a PostgreSQL service instance for the sample app. Our service instance is rails-postgres. It uses the elephantsql service and the turtle plan.

  $ cf create-service elephantsql turtle rails-postgres
  Creating service rails-postgres in org YOUR-ORG / space development as

Step 4: Deploy the App

Make sure you are in the cf-sample-app-rails directory. Run the following terminal command to deploy the app:

$ cf push cf-sample-app-rails

cf push cf-sample-app-rails creates a URL route to your application in the form HOST.DOMAIN. In this example, HOST is cf-sample-app-rails. Administrators specify the DOMAIN. For example, for the DOMAIN, running cf push cf-sample-app-rails creates the URL

The example below shows the terminal output when deploying the cf-sample-app-rails. cf push uses the instructions in the manifest file to create the app, create and bind the route, and upload the app. It then follows the information in the manifest to start one instance of the app with 256M of RAM. After the app starts, the output displays the health and status of the app.

$ cf push cf-sample-app-rails
Using manifest file ~/workspace/cf-sample-app-rails/manifest.yml

Creating app cf-sample-app-rails in org my-rog / space dev as

Creating route

Binding to cf-sample-app-rails...

Uploading cf-sample-app-rails...
Uploading app files from: ~/workspace/cf-sample-app-rails
Uploading 746.6K, 136 files
Done uploading

Starting app cf-sample-app-rails in org my-org  / space dev as
. . .
0 of 1 instances running, 1 starting
1 of 1 instances running

App started


App cf-sample-app-rails was started using this command `bundle exec rails server -p $PORT`

Showing health and status for app cf-sample-app-rails in org my-org / space dev as

requested state: started
instances: 1/1
usage: 512M x 1 instances
last uploaded: Fri Dec 22 18:08:32 UTC 2017
stack: cflinuxfs2
buildpack: ruby

     state     since                    cpu    memory          disk           details
#0   running   2017-12-22 10:09:57 AM   0.0%   20.7M of 512M   186.8M of 1G

Note: If you want to view log activity while the app deploys, launch a new terminal window and run cf logs cf-sample-app-rails.

Step 5: Bind the Service Instance

  1. Run the command below to bind the service instance to the sample app. Once bound, environment variables are stored that allow the app to connect to the service after a cf push, cf restage, or cf restart command.

    $ cf bind-service cf-sample-app-rails rails-postgres
    Binding service rails-postgres to app cf-sample-app-rails in org my-org / space dev
    TIP: Use 'cf restage cf-sample-app-rails' to ensure your env variable changes take effect

  2. Run the following command to restage the sample app.

    $ cf restage cf-sample-app-rails

  3. Run the following command to verify the service instance is bound to the sample app.

    $ cf services
    Getting services in org my-org / space dev
    name service plan bound apps last operation rails-postgres elephantsql turtle cf-sample-app-rails create succeeded

Step 6: Verify the App

Verify that the app is running by browsing to the URL generated in the output of the previous step. In this example, navigating to verifies that the app is running.

You’ve now pushed an app to PWS! For more information about this topic, see the Deploy an Application topic.

Create a pull request or raise an issue on the source for this page in GitHub