Gradle plugin that wraps your JVM application to a new Docker image. The image has standard labels derived from the build environment (environment variables, Git). Almost all the logic on Dockerfile generation is in this file.
The plugin takes product of distTar
task (added by the application plugin) and wraps it to Docker image.
Only image
parameter is mandatory - it's name of the resulting image.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'cz.augi:gradle-docker-java:putCurrentVersionHere'
}
}
apply plugin: 'docker-java'
dockerJava {
image = "myorg/my-app:$version" // name of the resulting Docker image; mandatory
alternativeImages = ["myorg/my-app:latest"] // array of alternative image names; default is empty
ports = [80] // list of exposed ports; default: empty
labels = ['mylabel':'mylabelvalue'] // additonal labels of Dockerfile; default: empty
volumes = ['/my-folder'] // list of volumes; default: empty
baseImage = 'my-org/our-base-image:1.2.3' // default: automatically choosed the best based on current Docker platform and Java version
javaVersion = JavaVersion.VERSION_1_8 // Java version used to choose appropriate base Docker image; default: project.targetCompatibility
dockerfileLines = ['RUN apt-get ...'] // additional lines to include to Dockerfile; default: empty
arguments = ['--server'] // arguments to be passed to your application; default: empty
dockerBuildDirectory = project.file('my-directory') // directory where Dockerfile is created; default: "$buildDir/dockerJava"
customDockerfile = file('Dockerfile') // path to a custom Dockerfile - then all of the previous options (except image and alternativeImages) are ignored; default: null
filesToCopy = [project.file('my-file-txt')] // list of files to copy to the Docker working directory (so these file can be copied to the image using COPY or ADD directives)
buildArgs = ['version=1.2.3'] // build arguments to be send to 'docker build' command when using custom Dockerfile; default: empty
// username and password are used if the Docker Registry requires credentials for pushing
username = 'registry-username'
password = System.getenv('DOCKER_REGISTRY_PASSWORD')
registry = 'docker.company.com' // Docker registry used to login; default: tries to extract it from 'image'
removeImage = false // indicates if the image should be removed after publishing, default is true
}
The plugin can be also applied using the new Gradle syntax:
plugins {
id 'cz.augi.docker-java' version 'putCurrentVersionHere'
}
The plugin provides following tasks:
distDocker
- creates temporary Dockerfile and build it to a new Docker imagedockerPush
- pushes the Docker image to Docker Registry
The plugin executes docker
command under the hood, so it supposes that Docker Engine is installed and available in PATH
.
Almost all the JVM-based applications have the same Dockerfile so why to copy or write the same Dockerfile again and again?