Hello Gradle!

Here are Boxfuse 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 Boxfuse 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 Boxfuse Gradle plugin. You can now use all Boxfuse commands directly from within your Gradle build.

Gradle plugin

How does it work?

You can use the Boxfuse Gradle plugin in a number of ways. The easiest is to simply include the Boxfuse plugin in build.gradle and add some basic configuration to the Boxfuse extension:

buildscript {
    repositories {
        // https is disabled until https://issues.gradle.org/browse/GRADLE-3250 is fixed
        maven { url 'http://files.boxfuse.com' }
    }
    dependencies {
        classpath "com.boxfuse.client:boxfuse-gradle-plugin:1.28.4.1381"
    }
}

apply plugin: 'boxfuse'

boxfuse {
    user='your-boxfuse-client-user'
    secret='your-boxfuse-client-secret'
}

You can now execute all Boxfuse 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 Boxfuse 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 Boxfuse 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.

Build integration

Where Boxfuse really shines, is when you integrate it directly into your build. You can then:

  • fuse your artifact into a new image
  • launch an instance of that image on VirtualBox or your Boxfuse test environment on EC2
  • execute your integration tests against it
  • shut it down
  • and if successful deploy the same image unchanged to your production environment on AWS

How can you achieve all this with Boxfuse 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 'http://files.boxfuse.com' }
    }
    dependencies {
        classpath "com.boxfuse.client:boxfuse-gradle-plugin:1.28.4.1381"
    }
}

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.BoxfuseExtension)
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! Boxfuse 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. Boxfuse 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.

Summary

In this post we looked at the Boxfuse 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 Boxfuse Gradle plugin.

Have fun! And if you haven't already, sign up for your Boxfuse account today. All you need is a GitHub user and you'll be up and running in no time. The Boxfuse free plan aligns perfectly with the AWS free tier, so you can deploy your application to the cloud completely free.

Join us and stay updated about Boxfuse and Immutable Infrastructure

Interesting posts with low frequency. Unsubscribe at any time.

« Logging for Cloud Native Apps
Deploying Spring Boot Apps on EC2 »
Recent posts