Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

* Add arbitrary build param support #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 @@ -92,6 +92,9 @@ public class BuildMojo extends AbstractDockerMojo {
@Parameter(property = "dockerfile.buildArgs")
private Map<String,String> buildArgs;

@Parameter(property = "dockerfile.buildParams")
private Map<String,String> buildParams;

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

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

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

Expand All @@ -156,7 +160,11 @@ static String buildImage(@Nonnull DockerClient dockerClient,
if (noCache) {
buildParameters.add(DockerClient.BuildParam.noCache());
}

if (buildParams != null) {
for (Map.Entry<String,String> e: buildParams.entrySet()) {
buildParameters.add(DockerClient.BuildParam.create(e.getKey(),e.getValue()));
}
}
if (buildArgs != null && !buildArgs.isEmpty()) {
try {
final String encodedBuildArgs = URLEncoder.encode(new Gson().toJson(buildArgs), "utf-8");
Expand Down