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

Support for build args with space #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions plugin/src/it/basic-with-build-args/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ FROM hello-world
MAINTAINER David Flemström <dflemstr@spotify.com>

ARG IMAGE_VERSION
ARG ARG_WITH_SPACE
ARG ARG_WITH_PLUS

LABEL version=${IMAGE_VERSION}
LABEL arg_with_space=${ARG_WITH_SPACE}
LABEL arg_with_plus=${ARG_WITH_PLUS}
2 changes: 2 additions & 0 deletions plugin/src/it/basic-with-build-args/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
<configuration>
<buildArgs>
<IMAGE_VERSION>0.0.1</IMAGE_VERSION>
<ARG_WITH_SPACE>arg with space</ARG_WITH_SPACE>
<ARG_WITH_PLUS>arg+with+plus</ARG_WITH_PLUS>
</buildArgs>
</configuration>
</plugin>
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/it/basic-with-build-args/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ DefaultDockerClient dockerClient = DefaultDockerClient.fromEnv().build()
imageInfo = dockerClient.inspectImage(imageId)

assert imageInfo.config().labels().get("version") == "0.0.1"
assert imageInfo.config().labels().get("arg_with_space") == "arg with space"
assert imageInfo.config().labels().get("arg_with_plus") == "arg+with+plus"
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
Expand Down Expand Up @@ -290,7 +291,9 @@ private static void requireValidDockerFilePath(@Nonnull Log log,

private static String encodeBuildParam(Object buildParam) throws MojoExecutionException {
try {
return URLEncoder.encode(new Gson().toJson(buildParam), "utf-8");
return URLEncoder.encode(
new Gson().toJson(buildParam), StandardCharsets.UTF_8.toString()
).replace('+', ' ');
} catch (UnsupportedEncodingException e) {
throw new MojoExecutionException("Could not build image", e);
}
Expand Down