Gradle Plugin to push an application to Cloud Foundry
Clone or download

README.adoc

Yet another Gradle plugin to deploy an application to Cloud Foundry.

Build Status

The purpose of this plugin is to provide ways to manage the deployment of an application to a Cloud Foundry Environment - Be able to deploy, update, start/stop/restart application, attach/remove routes, create/bind services/CUPS.

"Yet another" because the authoritative source of Cloud Foundry Gradle plugin is expected to be with the CF-Java-Client project.

Using the Plugin

Start by looking at a sample project using the plugin here

Details

  • Add a buildscript dependency:

buildscript {
	ext {
		cfAppVersion = '2.3.0-rc.2'
	}
	repositories {
		mavenCentral()
		maven { url "https://oss.sonatype.org/content/repositories/releases" }
		maven { url "https://repo.spring.io/release" }
	}
	dependencies {
		classpath("com.github.pivotalservices:ya-cf-app-gradle-plugin:${cfAppVersion}")
	}
}

apply plugin: 'cf-app'

OR Via the new Gradle plugins mechanism:

plugins {
	id "com.github.pivotalservices.cf-app" version "2.3.0-rc.2"
}
  • Provide the Cloud Foundry connectivity and application details:

cfConfig {
	//CF Details
	ccHost = "api.local.pcfdev.io"
	ccUser = "admin"
	ccPassword = "admin"
	org = "pcfdev-org"
	space = "pcfdev-space"

	//Proxy settings (optional)
	cfProxySettings {
		proxyHost = "proxy.host"
		proxyPort = 1234
		proxyUser = "user"
		proxyPassword = "password"
	}

	//Manifest with defaults (only supports one application per manifest file)
	manifestFile = "manifest.yml"

	//App Details (will override manifest defaults)
	name = "cf-show-env"
	filePath = "build/libs/cf-show-env-0.1.2-SNAPSHOT.jar"
	routes = [ "cf-show-env.local.pcfdev.io", "another.domain.com" ]
	instances = 2
	memory = 512

	//Env and services
	buildpack = "https://github.com/cloudfoundry/java-buildpack.git"
	environment = ["JAVA_OPTS": "-Djava.security.egd=file:/dev/./urandom", "SPRING_PROFILES_ACTIVE": "cloud"]
	services  = ["mydb"]
}
  • Run the task(s):

./gradlew cf-push
  • Override the values using explicit gradle properties, they follow a cf.* pattern:

./gradlew cf-push -Pcf.name=Green -Pcf.host=demo-time-temp -Pcf.environment.SPRING_PROFILES_ACTIVE="cloud,dev"
  • User and Password can be overridden using environment variables:

export CF_CCUSER=admin
export CF_CCPASSWORD=admin
./gradlew cf-push
  • There is one task to retrieve the details of an application (cf-get-app-detail). You can use this task in the following way, say to retrieve the app url’s in a gradle task:

task showAppUrls(dependsOn: "cf-get-app-detail") << {
	print "${project.cfConfig.applicationDetail.urls}"
}

or if you want to run an acceptance test you can define a task alone these lines:

task acceptanceTest(type: Test, dependsOn: "cf-get-app-detail")  {
	doFirst() {
		systemProperty "url", "https://${project.cfConfig.applicationDetail.urls[0]}"
	}
	useJUnit {
		includeCategories 'test.AcceptanceTest'
	}
}
Note
A sample project demonstrating the plugin is availble here

Using the Plugin for a Blue-Green Application Deployment

The plugin natively understands how to perform the steps of a Blue-Green deploy. Just run the following and you should be set for a Blue-Green deploy:

./gradlew cf-push-blue-green

You may want to run smoke tests after a new version of the app with a new route is brought up before replacing the existing app, if so a smoke test dependency can be added in the build.gradle file the following way:

"cf-push-blue-green-1"{finalizedBy "test"}

and run

./gradlew cf-push-blue-green

Using the Plugin for a Autopilot equivalent deployment

The plugin natively understands how to perform the steps of an Autopilot based deploy. Just run the following on the command line:

./gradlew cf-push-autopilot

Creating services

Services can be created and automatically bound to the app in the targeted org and space by providing information the following way:

    cfService {
        name = "p-mysql"
        plan = "512mb"
        instanceName = "test-db"
    }

    cfService {
        name = "p-rabbitmq"
        plan = "standard"
        instanceName = "test-rabbitmq"
        tags = ["tag1", "tag2"]
    }

    cfService {
            name = "nfs"
            plan = "existing"
            instanceName = "test-nfs"
            parameters = [
                "share": "existing.nas.com/fileshare/test_nas"
            ]
        }

    cfUserProvidedService {
        instanceName = "mydb1"
        credentials = ["jdbcUri": "someuri1"]
    }

Usage behind a proxy

If you need to use the plugin behind a proxy you can configure it like this:

cfConfig {
    ...
    cfProxySettings {
        proxyHost = "proxy.host"
        proxyPort = 1234
        proxyUser = "user"
        proxyPassword = "password"
    }
}

Only proxyHost and proxyPort are mandatory, proxyUser and proxyPassword are optional and the need for them depends on your actual environment.

You can override any of these values from the command line, the pattern is cf.cfProxySettings.*.

List of all Tasks

Table 1. Tasks
Task Description

cf-create-services

Create a set of services

cf-push

Pushes an Application to Cloud Foundry

cf-delete-app

Delete an application from Cloud Foundry

cf-delete-route

Delete a route from Cloud Foundry

cf-get-app-detail

Get the application detail from Cloud Foundry

cf-map-route

Add a route for an application

cf-unmap-route

Remove an existing route for an application

cf-rename-app

Rename an applicaiton

cf-start-app

Start an Application

cf-stop-app

Stop an Application

cf-restage-app

Restage an Application

cf-restart-app

Restart an Application

cf-push-autopilot

Push with Autopilot steps

cf-push-blue-green

Push with Blue-Green steps