Skip to content

Commit

Permalink
Merge pull request spotify#248 from matthyx/master
Browse files Browse the repository at this point in the history
Add support for --squash experimental build option
  • Loading branch information
davidxia authored Nov 19, 2018
2 parents 45404b5 + 498560b commit 230dd09
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## upcoming release
- Add support for --squash experimental build option ([248][])

[248]: https://github.com/spotify/dockerfile-maven/pull/248

## 1.4.9 (released October 25 2018)
- Upgrade docker-client dep from 8.14.2 to 8.14.3 to fix spotify/docker-client#1100

Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ mvn clean package -Ddockerfile.skip
| `dockerfile.build.noCache` | Do not use cache when building the image. | no | false |
| `dockerfile.build.cacheFrom` | Docker image used as cache-from. Pulled in advance if not exist locally or `pullNewerImage` is `false` | no | none |
| `dockerfile.buildArgs` | Custom build arguments. | no | none |
| `dockerfile.build.squash` | Squash newly built layers into a single new layer (experimental API 1.25+). | no | false |
12 changes: 10 additions & 2 deletions plugin/src/main/java/com/spotify/plugin/dockerfile/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public class BuildMojo extends AbstractDockerMojo {
@Parameter(property = "dockerfile.build.cacheFrom")
private List<String> cacheFrom;

@Parameter(property = "dockerfile.build.squash", defaultValue = "false")
private boolean squash;

@Override
public void execute(DockerClient dockerClient)
throws MojoExecutionException, MojoFailureException {
Expand All @@ -109,7 +112,7 @@ public void execute(DockerClient dockerClient)

final String imageId = buildImage(
dockerClient, log, verbose, contextDirectory, repository, tag, pullNewerImage, noCache,
buildArgs, cacheFrom);
buildArgs, cacheFrom, squash);

if (imageId == null) {
log.warn("Docker build was successful, but no image was built");
Expand Down Expand Up @@ -142,7 +145,8 @@ static String buildImage(@Nonnull DockerClient dockerClient,
boolean pullNewerImage,
boolean noCache,
@Nullable Map<String,String> buildArgs,
@Nullable List<String> cacheFrom)
@Nullable List<String> cacheFrom,
boolean squash)
throws MojoExecutionException, MojoFailureException {

log.info(MessageFormat.format("Building Docker context {0}", contextDirectory));
Expand Down Expand Up @@ -189,6 +193,10 @@ static String buildImage(@Nonnull DockerClient dockerClient,
}
}

if (squash) {
buildParameters.add(new DockerClient.BuildParam("squash", encodeBuildParam(squash)));
}

final DockerClient.BuildParam[] buildParametersArray =
buildParameters.toArray(new DockerClient.BuildParam[buildParameters.size()]);

Expand Down

0 comments on commit 230dd09

Please sign in to comment.