Permalink
Fetching contributors…
Cannot retrieve contributors at this time
147 lines (98 sloc) 6.6 KB
---
title: Getting Started Deploying Ruby on Rails Apps
owner: Buildpacks
---
<strong><%= modified_date %></strong>
This guide walks you through deploying a Ruby on Rails app to <%=vars.first_product_name%>.
##<a id='prerequisites'></a>Prerequisites
In order to deploy a sample Ruby on Rails app, you must have the following:
- A Cloud Foundry deployment or a Pivotal Web Services account
- The [Cloud Foundry Command Line Interface](../../cf-cli/install-go-cli.html)
- A Cloud Foundry username and password with **Space Developer** [permissions](../../concepts/roles.html#roles). See your [Org Manager](../../concepts/roles.html#roles) if you require permissions.
##<a id='clone'></a>Step 1: Clone the App ##
Run the following terminal command to create a local copy of the cf-sample-app-rails.
<pre class='terminal'>
$ git clone <span>https</span>://github.com/cloudfoundry-samples/cf-sample-app-rails.git
</pre>
The newly created directory contains a `manifest.yml` file, which assists CF with deploying the app. See [Deploying with Application Manifests](../../devguide/deploy-apps/manifest.html#minimal-manifest) for more information.
##<a id='login'></a>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. <%= vars.api_endpoint_book %>
<pre class='terminal'>$ cf login -a YOUR-API-ENDPOINT</pre>
1. Use your credentials to log in, and to select a [Space and Org](../../concepts/roles.html).
##<a id='service'></a>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`](http://www.elephantsql.com/) service and the `turtle` plan.
<pre class="terminal">
$ cf create-service elephantsql turtle rails-postgres
Creating service rails-postgres in org YOUR-ORG / space development as clouduser<span>@</span>example.com....
OK</pre>
##<a id='deploy'></a>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:
<pre class='terminal'>$ cf push cf-sample-app-rails</pre>
`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 `<%=vars.app_domain%>`, running `cf push cf-sample-app-rails` creates the URL `cf-sample-app-rails.<%=vars.app_domain%>`.
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.
<pre class="terminal">
$ 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 clouduser@example.com...
OK
Creating route cf-sample-app-rails.cfapps.io...
OK
Binding cf-sample-app-rails.cfapps.io to cf-sample-app-rails...
OK
Uploading cf-sample-app-rails...
Uploading app files from: ~/workspace/cf-sample-app-rails
Uploading 746.6K, 136 files
Done uploading
OK
Starting app cf-sample-app-rails in org my-org / space dev as clouduser@example.com...
. . .
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
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 clouduser@example.com...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: cf-sample-app-rails.cfapps.io
last uploaded: Fri Dec 22 18:08:32 UTC 2017
stack: cflinuxfs3
buildpack: ruby
state since cpu memory disk details
#0 running 2018-8-17 10:09:57 AM 0.0% 20.7M of 512M 186.8M of 1G
</pre>
<p class='note'><strong>Note</strong>: If you want to view log activity while the app deploys, launch a new terminal window and run <code>cf logs cf-sample-app-rails</code>.
##<a id='bind'></a>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.
<pre class="terminal">
$ 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
OK
TIP: Use 'cf restage cf-sample-app-rails' to ensure your env variable changes take effect
</pre>
1. Run the following command to restage the sample app.
<pre class="terminal">
$ cf restage cf-sample-app-rails
</pre>
1. Run the following command to verify the service instance is bound to the sample app.
<pre class="terminal">
$ cf services
Getting services in org my-org / space dev
OK
name service plan bound apps last operation
rails-postgres elephantsql turtle cf-sample-app-rails create succeeded
</pre>
##<a id='verify'></a>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 `cf-sample-app-rails.<%=vars.app_domain%>` verifies that the app is running.
You've now pushed an app to <%=vars.product_short%>! For more information about this topic, see the [Deploy an Application](../../devguide/deploy-apps/deploy-app.html) topic.
##<a id="next"></a>What to Do Next
You have deployed an app to <%=vars.product_name%>. Consult the sections below for information about what to do next.
### Test a Deployed App
Use the cf <%=vars.dev_console_2%> to review information and administer your app and your <%=vars.product_name%> account. For example, you could edit the `manifest.yml` file to increase the number of app instances from 1 to 3 or redeploy the app with a new app name.
### Manage Your App with the cf CLI
Run `cf help` to view a complete list of commands and run `cf help COMMAND` for detailed information about a specific command. For more information about using the cf CLI, refer to the cf CLI topics, especially the <%=vars.cli_v6%> topic.
### Troubleshooting
If your app fails to start, verify that the app starts in your local environment. Refer to the [Troubleshooting Application Deployment and Health](./../../devguide/deploy-apps/troubleshoot-app-health.html) topic to learn more about troubleshooting.