Deploy a Sample Ruby on Rails Application
Page last updated:
This topic guides the reader through deploying a sample Ruby on Rails app to Elastic Runtime .
In order to deploy a sample Ruby on Rails app, you must have the following:
- A working PCF 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.
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. For more information, see the Identifying the API Endpoint for your Elastic Runtime Instance topic.
$ 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 firstname.lastname@example.org.... 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 email@example.com... OK Using route rails_sample_app.shared-domain.example.com 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 firstname.lastname@example.org... OK Starting app rails_sample_app in org Cloud-Apps / space development as email@example.com... 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 firstname.lastname@example.org... OK requested state: started instances: 1/1 usage: 256M x 1 instances urls: rails_sample_app.shared-domain.example.com 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.shared-domain.example.com verifies that the app is running.
You’ve now pushed an app to Elastic Runtime! For more information about this topic, see the Deploy an Application topic.