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:
- A working PWS deployment
- Cloud Foundry CLI
- Cloud Foundry username and password with Space Developer permissions. See your Org Manager if you require permissions.
Run the following terminal command to create a local copy of the rails_sample_app.
$ git clone https://github.com/cloudfoundry-samples/rails_sample_appThe newly created directory contains a
manifest.ymlfile, which assists CF with deploying the app. See Deploying with Application Manifests for more information.
Run the following terminal command to log in and target the API endpoint of your deployment. Use
api.run.pivotal.ioas your API endpoint.
$ cf login -a YOUR-API-ENDPOINT
Use your credentials to log in, and to select a Space and Org.
Note: The API endpoint must be entered in the format
https://api.IP-ADDRESS, where IP-ADDRESS is the IP address of your API endpoint.
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
$ cf create-service elephantsql turtle rails-postgres Creating service rails-postgres in org YOUR-ORG / space development as email@example.com.... OK
The manifest for the rails_sample_app contains a
services sub-block in the
applications block. The Cloud Foundry Command Line Interface tool (cf CLI) binds the service to the app.
--- applications: - name: rails-sample memory: 256M instances: 1 path: . command: bundle exec rake db:migrate && bundle exec rails s -p $PORT services: - rails-postgres
Make sure you are in the
rails_sample_app directory. Run the following terminal command to deploy the app:
$ cf push rails_sample_app
cf push rails_sample_app creates a URL route to your application in the form HOST.DOMAIN. In this example, HOST is rails_sample_app. Administrators specify the DOMAIN. For example, for the DOMAIN
cf push rails_sample_app creates the URL
The example below shows the terminal output when deploying the
cf push uses the instructions in the manifest file to create the app, create and bind the route, and upload the app. It then binds the app to the
rails-postgres service and 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 rails_sample_app Using manifest file ~/workspace/rails_sample_app/manifest.yml Updating app rails_sample_app in org Cloud-Apps / space development as firstname.lastname@example.org... OK Using route rails_sample_app.cfapps.io Uploading rails_sample_app... Uploading app files from: ~/workspace/rails_sample_app Uploading 445.7K, 217 files OK Binding service rails-postgres to app rails_sample_app in org Cloud-Apps / space development as email@example.com... OK Starting app rails_sample_app in org Cloud-Apps / space development as firstname.lastname@example.org... OK ... 0 of 1 instances running, 1 starting 1 of 1 instances running App started Showing health and status for app rails_sample_app in org Cloud-Apps / space development as email@example.com... OK requested state: started instances: 1/1 usage: 256M x 1 instances urls: rails_sample_app.cfapps.io state since cpu memory disk #0 running 2014-08-25 03:32:10 PM 0.0% 68.4M of 256M 73.4M of 1G
Note: If you want to view log activity while the app deploys, launch a new terminal window and run
cf logs rails_sample_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
rails_sample_app.cfapps.io 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.