Build, tag & publish

Stackwork can be used as an opinionated convention over configuration plugin to build images using Gradle.

To make this work, include a Dockerfile in your projects home directory. Also, specify that your project delivers a Docker image in the build.gradle.

// build.gradle

version = '1.0'
stackwork {
  imageName = ''

The Gradle tasks of interest are:

These tasks are respectively dependent, so gradle pushImage will run all three. See the reference for the task details.

The imageName will be tagged with the version. Our own practice is to use the nebula release plugin to generate the version automatically. To push images to the Docker Hub, you need to include a name space in the image name. To push to your own repository, you add the domain as in the example. Under the hood, a docker push is executed, so you can follow the rules you know.

Use artifacts from a Nexus repository

When building a docker image, the docker project directory is uploaded to the Docker daemon. Stackwork makes sure your artifacts are available for the build, in the build/stackwork-deps/ directory.

// build.gradle

dependencies {
  // dependencies for image builds use the stackwork configuration:
  stackwork group: 'GROUP', name: 'NAME', version: 'VERSION'
# Dockerfile

FROM scratch
COPY build/stackwork-deps/NAME-VERSION.ext /

Use artifacts from your build

Often, a project produces an artifact that should be copied into the final Docker image. In such a case, simply make sure that the buildImage tasks depends on the gradle tasks that produce the artifact by configuring this in the build file. Note that the artifact must be in the same directory as the Dockerfile, or a subdirectory of that.