Converting POM using docker-maven-plugin to Gradle

(davidmichaelkarr) #1

These days I don’t get to use Gradle much, but I wanted to see how difficult it would be to convert a POM for building a Docker image into a Gradle build script.

It’s hard to tell exactly what plugin is recommended, but I guess it would be “com.palantir.docker”.

The POM for building the Docker image is part of a multiproject build including two other projects, each of which builds a WAR file. I found it pretty trivial to generate the Gradle build scripts for the other two projects, but the Docker one is a little harder. The examples on the “com.palantir.docker” plugin page don’t cover what I need to do.

In the existing POM, I specify the other two projects as dependencies using their GAV coordinates, including a JDBC driver jar. I use the Maven “copy-dependencies” task to get local copies of the dependencies that need to go into the image (stripping versions from the jar names), and I specify those artifacts in the configuration for the “docker-maven-plugin”.

The following is an excerpt of the current POM:
<dependencies> <dependency> <groupId>orderProcessingDashboard</groupId> <artifactId>ordersService</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency> <dependency> <groupId>orderProcessingDashboard</groupId> <artifactId>ordersGUI</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency> <dependency> <groupId>oracle</groupId> <artifactId>ojdbc6</artifactId> <version></version> </dependency> </dependencies> <repositories> <!-- Need this for the Oracle JDBC driver. --> <repository> ... repo info </repository> </repositories> <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <dockerDirectory>${basedir}/src/docker</dockerDirectory> <imageName>ssorderprocessingdashboard</imageName> <resources> <resource> <directory>${}/dependencies</directory> <includes> <include>ordersService.war</include> <include>ordersGUI.war</include> <include>ojdbc6.jar</include> </includes> </resource> </resources> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${}/dependencies</outputDirectory> <excludeTransitive>true</excludeTransitive> <includeArtifactIds>ordersService,ordersGUI,ojdbc6</includeArtifactIds> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin> </plugins> </build>

So far, my build.gradle for this project is just the following, as I have no idea how to manage getting dependencies into the image (so I haven’t bothered to specify the dependencies yet):
`apply plugin: java

plugins {
id ‘com.palantir.docker’ version ‘’

docker {
name 'ssorderprocessingdashboard’
dockerfile ‘src/docker/Dockerfile’

(davidmichaelkarr) #2

With help from “Steve973” on IRC, I’ve been able to resolve part of this, which is how to gather the three required dependencies into a single place, so I can later refer to them somehow in the docker plugin.

I now have the following, which at least produces the artifacts I need to include in the image:
`dependencies {
runtime project(":ordersService")
runtime project(":ordersGUI")
runtime “oracle:ojdbc6:”

task copyDependencies << {
.each { artifact ->
project.copy {
from artifact.file
into "${buildDir}/dependencies"
rename { “${}.${artifact.extension}” }

build.dependsOn copyDependencies`

Now that I have them in a single place, I have to have a “docker” config block something like this:
docker { name 'ssorderprocessingdashboard' dockerfile 'src/docker/Dockerfile' files "ordersService.war", "ordersGUI.war", "ojbdc6.jar" }

But this isn’t quite right, because those three files are in “${buildDir}/dependencies”, so this fails to find them. I could add that prefix to all three of the files, but that’s messy. I thought I could do something like this:
files ["ordersService.war", "ordersGUI.war", "ojbdc6.jar"].each { "$buildDir/dependencies/" + it }

But this just fails with “Could not get unknown property ‘files’ for object of type com.palantir.gradle.docker.DockerExtension.”

(davidmichaelkarr) #3

I’ve concluded that I’m not going to get much response on issues with “com.palantir.docker”, so I’m going to start over using Ben Muschko’s “gradle-docker-plugin”, so I’m going to abandon this line of inquiry for now.