2015-05-26 by Axel Fontaine
Here are CloudCaptain we pride ourselves for providing you with the easiest solution to produce minimal and secure images for your JVM-apps that can then be deployed unchanged on VirtualBox and AWS.
As shown in our three part article on creating a Continuous Deployment pipeline for Dropwizard-based unikernels from GitHub to AWS, we relied on Travis CI and the CloudCaptain Maven plugin to fuse and run the images.
We always strongly believed in direct build tool integration. That's also the reason why we've had Maven support from the get go. However these days a large number of you favor Gradle and its small and readable build files to build your projects. Today we are happy to announce the release of the CloudCaptain Gradle plugin. You can now use all CloudCaptain commands directly from within your Gradle build.
You can use the CloudCaptain Gradle plugin in a number of ways.
The easiest is to simply include the CloudCaptain plugin in build.gradle
and
add some basic configuration to the CloudCaptain extension:
buildscript { repositories { // https is disabled until https://issues.gradle.org/browse/GRADLE-3250 is fixed maven { url 'https://files.cloudcaptain.sh' } } dependencies { classpath "com.boxfuse.client:boxfuse-gradle-plugin:1.33.0.1460" } } apply plugin: 'boxfuse' boxfuse { user='your-boxfuse-client-user' secret='your-boxfuse-client-secret' }
You can now execute all CloudCaptain commands as Gradle tasks directly from the command-line:
> gradle build boxfuseRun -info
As you can see there is no need to manually specify the payload as CloudCaptain will automatically default to use the project artifact. It also automatically uses the project name and version for the image.
Tip: If you do not want to store your CloudCaptain credentials directly
in your build file, you can also simply store them in the
BOXFUSE_USER
and BOXFUSE_SECRET
environment variables and they will be picked up automatically.
Where CloudCaptain really shines, is when you integrate it directly into your build. You can then:
How can you achieve all this with CloudCaptain and Gradle? All you need is this simple configuration:
buildscript { repositories { // https is disabled until https://issues.gradle.org/browse/GRADLE-3250 is fixed maven { url 'https://files.cloudcaptain.sh' } } dependencies { classpath "com.boxfuse.client:boxfuse-gradle-plugin:1.33.0.1460" } } apply plugin: 'boxfuse' apply plugin: 'java' //Omitted dependencies, repositories, ... //Run deploy & run integration tests in test environment boxfuse { env='test' } task boxfuseRunTest( type: com.boxfuse.client.gradle.task.RunTask ) task boxfuseKillTest( type: com.boxfuse.client.gradle.task.KillTask ) //Pass the url of the newly launched instance to the tests task testConfig (dependsOn: boxfuseRunTest) << { project.tasks.test.systemProperty 'instanceUrl', boxfuse.instancesResult[0].url } test.dependsOn(testConfig) //Always kill the test instance, even if the tests fail test.finalizedBy(boxfuseKillTest) //Deploy with zero-downtime on prod environment extensions.create('boxfuseProd', com.boxfuse.client.gradle.CloudCaptainExtension) boxfuseProd { env='prod' } //Ensure we deploy the same image to prod as the one we just tested task boxfuseProdConfig (dependsOn: boxfuseKillTest) << { project.tasks.boxfuseRunProd.extension = boxfuseProd boxfuseProd.image=boxfuse.image } task boxfuseRunProd( type: com.boxfuse.client.gradle.task.RunTask, dependsOn: boxfuseProdConfig ) check.dependsOn(boxfuseRunProd)
And now all you need to do is issue
> gradle build -info
And there you have it! CloudCaptain will fuse an image, run and kill instances in multiple environments and more, all while integrated directly in your Gradle build.
As you can see, you can pass boxfuse.instancesResult[0].url
as a system property to your tests, so they know where the instance under test is running.
CloudCaptain dynamically sets this and others properties after it launches an instance to
make it easy for you to interact with your new instance.
Tip: We extended our
Dropwizard sample project with
a build.gradle
file so you can see it
all in action and easily play with it for yourself.
In this post we looked at the CloudCaptain Gradle plugin and how it makes it a breeze to fuse images and run instances directly from your Gradle build.
You can find more information in the docs for the CloudCaptain Gradle plugin.
Have fun! And if you haven't already, sign up for your CloudCaptain account today. All you need is a GitHub user and you'll be up and running in no time. The CloudCaptain free plan aligns perfectly with the AWS free tier, so you can deploy your application to the cloud completely free.