Skip to content
This repository was archived by the owner on Mar 31, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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