Marcin Świerczyński's blog

Cloud Foundry + Grails = lightning fast deployment

posted 27 Mar 2023 in Grails

The purpose of this article is to show how quickly and easily deploy Grails application to Cloud Foundry platform.

What is Cloud Foundry?

From cloudfoundry.com:

Cloud Foundry is an open platform as a service, providing a choice of clouds, developer frameworks and application services. Initiated by VMware, with broad industry support, Cloud Foundry makes it faster and easier to build, test, deploy and scale applications. It is an open source project and is available through a variety of private cloud distributions and public cloud instances, including CloudFoundry.com.

Prerequisites

To make a use of this article you’ll need to have Grails framework installed.

To check if Grails is properly installed, use

  grails -version

You should see something like

  Grails version: 2.0.0

If you haven’t, just follow the Grails Getting Started Guide.

Let’s the fun begin

The whole process is extraordinary simple! Just do the following steps.

1. Create Grails app

  grails create-app cloud_foundry_example

2. Change your working directory to a new application directory

  cd cloud_foundry_example

3. Install Cloud Foundry plug-in

  grails install-plugin cloud-foundry

4. Configure your Cloud Foundry credentials

You can configure it in both grails-app/conf/Config.groovy and in ~/.grails/settings.groovy. Since the file will contain sensitive, it’s not recommended to put it in source control. That’s why the second option is considered the best practice.

So, configure your credentials using

  grails.plugin.cloudfoundry.username = "<your_username>"
  grails.plugin.cloudfoundry.password = "<pass>"

5. Test your config

  grails cf-info

The output should look like

  VMware's Cloud Application Platform
  For support visit http://support.cloudfoundry.com
  Target:   http://api.cloudfoundry.com (v0.999)

  User:     <your_username>
  Usage:    Memory   (0B of 2.0G total)
            Services (0 of 16 total)
            Apps     (0 of 20 total)

6. Deploy your app!

  grails prod cf-push

You’ll be asked about the application URL, and also about some persistence services (in the time of writing: MySQL and PostgreSQL). I advise to accept default address and chose one of these services.

If you want to re-deploy after some changes, just do

  grails prod cf-update

That’s it!

The app is deployed and ready to work. A proof? PartyPlanner app.

In next part I’ll describe how to configure different services in Cloud Foundry.

Leave a comment