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.
Start by looking at a sample project using the plugin here
-
Add a buildscript dependency:
buildscript {
ext {
cfAppVersion = '2.1.0'
}
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.1.0"
}
-
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"
//App Details
name = "cf-show-env"
host = "cf-show-env"
filePath = "build/libs/cf-show-env-0.1.2-SNAPSHOT.jar"
path = ""
domain = "local.pcfdev.io"
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
-
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
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"]
}
cfUserProvidedService {
instanceName = "mydb1"
credentials = ["jdbcUri": "someuri1"]
}
Task | Description |
---|---|
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 |
cf-create-services |
Create a set of services |