Skip to content

Commit

Permalink
Add ability to send --rm param on build (seems needed for CircleCI)
Browse files Browse the repository at this point in the history
  • Loading branch information
John W committed Sep 2, 2016
1 parent b47a9d4 commit 49dedf7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/spotify/docker/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public class BuildMojo extends AbstractDockerMojo {
@Parameter(property = "noCache", defaultValue = "false")
private boolean noCache;

/** Set to false to pass the `--rm` flag to the Docker daemon when building an image. */
@Parameter(property = "rm", defaultValue = "true")
private boolean rm;

/** Flag to push image after it is built. Defaults to false. */
@Parameter(property = "pushImage", defaultValue = "false")
private boolean pushImage;
Expand Down Expand Up @@ -799,6 +803,9 @@ private DockerClient.BuildParam[] buildParams()
if (noCache) {
buildParams.add(DockerClient.BuildParam.noCache());
}
if (!rm) {
buildParams.add(DockerClient.BuildParam.rm(false));
}
if (!buildArgs.isEmpty()) {
buildParams.add(DockerClient.BuildParam.create("buildargs",
URLEncoder.encode(OBJECT_MAPPER.writeValueAsString(buildArgs), "UTF-8")));
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/spotify/docker/BuildMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,18 @@ public void testNoCache() throws Exception {
eq(BuildParam.noCache()));
}

public void testRmFalse() throws Exception {
final BuildMojo mojo = setupMojo(getPom("/pom-build-rm-false.xml"));
final DockerClient docker = mock(DockerClient.class);

mojo.execute(docker);

verify(docker).build(any(Path.class),
anyString(),
any(ProgressHandler.class),
eq(BuildParam.rm(false)));
}

public void testBuildWithSkipDockerBuild() throws Exception {
final BuildMojo mojo = setupMojo(getPom("/pom-build-skip-build.xml"));
assertThat(mojo.isSkipDockerBuild()).isTrue();
Expand Down
29 changes: 29 additions & 0 deletions src/test/resources/pom-build-rm-false.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>Docker Maven Plugin Test Pom</name>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.1-SNAPSHOT</version>
<configuration>
<dockerHost>http://host:2375</dockerHost>
<dockerDirectory>src/test/resources/dockerDirectory</dockerDirectory>
<imageName>busybox</imageName>

<rm>false</rm>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 49dedf7

Please sign in to comment.