Getting Started Deploying Ruby on Rails Apps
Page last updated:
This guide walks you through deploying a Ruby on Rails (RoR) app to Elastic Runtime. To deploy a sample RoR app, refer to the Deploy a Sample Ruby on Rails App topic.
Note: Ensure that your RoR app runs locally before continuing with this procedure.
- A Rails 4.x app that runs locally
- Bundler configured on your workstation
- Intermediate to advanced RoR knowledge
- The Cloud Foundry Command Line Interface (cf CLI)
This section describes using the CLI to configure a PostgreSQL managed service instance for an app. For more information about creating and using service instances, refer to the Services Overview topic.
Create a Service Instance
cf marketplace to view managed and user-provided services and plans available to you.
cf create-service SERVICE PLAN SERVICE_INSTANCE to create a service instance for your app. Choose a SERVICE and PLAN from the list, and provide a unique name for the SERVICE_INSTANCE.
Bind a Service Instance
When you bind an app to a service instance, Elastic Runtime writes information about the service instance to the VCAP_SERVICES app environment variable. The app can use this information to integrate with the service instance.
Most services support bindable service instances. Refer to your service provider’s documentation to confirm whether they support this functionality.
To bind a service to an application, run
cf bind-service APPLICATION SERVICE_INSTANCE.
Configure the Deployment Manifest
You can specify app deployment options in a manifest that the
cf push command uses. For more information about application manifests and supported attributes, refer to the Deploying with Application Manifests topic.
Configure a Production Server
Elastic Runtime uses the default standard Ruby web server library, WEBrick, for Ruby and RoR apps. However, Elastic Runtime can support a more robust production web server, such as Phusion Passenger, Puma, Thin, or Unicorn. If your app requires a more robust web server, refer to the Configuring a Production Server topic for help configuring a server other than WEBrick.
For Rails versions 4.0.0 and earlier, the Ruby buildpack overwrites the
config/database.yml file using the contents of the
DATABASE_URL environment variable. This variable can be set by the user or will be automatically set
based on bound service instances.
For Rails versions 4.1.0 and later, the Ruby buildpack will not modify the
When the app starts, the standard Rails behavior for
cf login -a API_ENDPOINT, enter your login credentials, and select a space and org. The API endpoint is the URL of the Cloud Controller in your Elastic Runtime instance.
From the root directory of your application, run
cf push APP-NAME --random-route to deploy your application.
cf push APP-NAME creates a URL route to your application in the form HOST.DOMAIN, where HOST is your APP-NAME and DOMAIN is specified by your administrator. Your DOMAIN is
shared-domain.example.com. For example:
cf push my-app creates the URL
The URL for your app must be unique from other apps that Elastic Runtime hosts or the push will fail. Use the following options to help create a unique URL:
-nto assign a different HOST name for the app.
--random-routeto create a URL that includes the app name and random words.
cf help pushto view other options for this command.
To view log activity while the app deploys, launch a new terminal window and run
cf logs APP-NAME.
In the terminal output of the
cf push command, the
urls field of the
App started block contains the app URL. This is the
HOST_NAME you specified with the
-n flag plus the domain
shared-domain.example.com. Once your app deploys, use this URL to access the app online.
You’ve deployed an app to Elastic Runtime! Consult the sections below for information about what to do next.
Test a Deployed App
Use the cf CLI or the Apps Manager to review information and administer your app and your Elastic Runtime account. For example, you could edit the
manifest.yml to increase the number of app instances from 1 to 3, and redeploy the app with a new app name and host name.
Manage Your Application with the cf CLI
cf help to view a complete list of commands, grouped by task categories, and run
cf help COMMAND for detailed information about a specific command. For more information about using the cf CLI, refer to the Cloud Foundry Command Line Interface (cf CLI) topics, especially the Getting Started with cf CLI v6 topic.
If your application fails to start, verify that the application starts in your local environment. Refer to the Troubleshooting Application Deployment and Health topic to learn more about troubleshooting.