Deploying Ratpack Applications to Cloud Foundry with no custom buildpack

Instead of using the Heroku buildpack, we can easily deploy ratpack applications into Cloud Foundry using the built-in java 7 support.

Since the Gradle application plugin builds a complete Java application, we can simply upload this application to Cloud Foundry and run it.

The one difference between this approach and a buildpack-based one is that you build the application in your local machine and deploy the files to Cloud Foundry instead of trying to do it all remotely.

Steps.

1. Install cloud foundry command line tool.

gem install cf

2. Obtain a Cloud Foundry account

Either at http://www.anynines.com (instantly) or http://www.cloudfoundry.com (takes a long time)

3. Build your ratpack application using the gradle task.

Assuming you built your application via the lazybones template

./gradlew iA

In my case, this creates a gradle application at build/install/server

4. Login to your Cloud Foundry account

For anynines

cf target https://api.de.a9s.eu
cf login --email myemail --password mypassword
cf create-space development
cf switch-space development

For Cloud Foundry.com

cf target api.run.pivotal.io
cf login --email myemail --password mypassword
cf switch-space development

5. Push your application

The gradle installApp command builds a full java application for you. All you need to do is tell Cloud Foundry about the proper start command.

cf push --command="export JAVA_OPTS='-Dratpack.port=\$PORT' && build/install/server/bin/server"

Fill in the rest of the template and you should see your application deployed.

Here are the options I selected for my application:

Name> ratmongo

Instances> 1

1: 128M
2: 256M
3: 512M
4: 1G
Memory Limit> 1G

Creating ratmongo... OK

1: ratmongo
2: none
Subdomain> ratmongo

1: cfapps.io
2: none
Domain> cfapps.io

Binding ratmongo.cfapps.io to ratmongo... OK

Create services for application?> n

Save configuration?> y

Saving to manifest.yml... OK
Uploading ratmongo... OK
Preparing to start ratmongo... OK
-----> Downloaded app package (29M)
Downloading JDK...
Copying openjdk-1.7.0_25.tar.gz from the buildpack cache ...
Unpacking JDK to .jdk
-----> Uploading droplet (58M)
Checking status of app 'ratmongo'..........
1 of 1 instances running (1 running)
Push successful! App 'ratmongo' available at http://ratmongo.cfapps.io

And I see my ratpack application running correctly at http://ratmongo.cfapps.io

Since I have saved my manifest.yml file, subsequent updates only involve me calling


cf push

I run my builds on Nitrous.io so that they are on Amazon’s US East and the uploads to CloudFoundry.com are pretty fast.

3 thoughts on “Deploying Ratpack Applications to Cloud Foundry with no custom buildpack

  1. Andy Piper

    Thanks for this post! Just a couple of notes:
    – cloudfoundry.com -> run.pivotal.io… which is a Pivotal-operated instance of the Cloud Foundry code. cloudfoundry.com is now the project home rather than a hosted version of the runtime.
    – sorry for the delays in approving new accounts on run.pivotal.io. We have been bringing new accounts on in batches (we have been seeing huge demand, and wanted to ensure that our v1 users from the old service were happy first). Hopefully this will speed up over time🙂

    Reply
  2. Guillaume Laforge (@glaforge)

    Have you tried recently to deploy a Ratpack app on CloudFoundry?

    I think the steps in this article needs at least a small update with the launch command, which seems to be following a different convention now, so the command build/install/server/bin/server needs to have the “server” part replaced with the name of the project root dir, or the project name if one has specified it in settings.gradle with rootProject.name = ‘myappname’

    Anyhow, I invariable get the infamous message:
    Application failed to stage

    Any hint?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s