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

Add support for supplying build-args, fixes #22 #41

Merged
merged 2 commits into from
Jul 10, 2017
Merged

Add support for supplying build-args, fixes #22 #41

merged 2 commits into from
Jul 10, 2017

Conversation

glindstedt
Copy link
Contributor

This fixes issue #22. I took inspiration from the comments there and used the format below, let me know if you prefer another format.

<configuration>
  <buildArgs>
    <key>value</key>
  </buildArgs>
</configuration>

Copy link
Member

@mattnworb mattnworb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Thanks for the contribution! I like the format for the pom configuration, and the way the test checks that the ARG is replaced is pretty smart 👍

Before merging though I'd be curious to hear what @dflemstr thinks of this functionality?

@@ -93,7 +103,7 @@ public void execute(DockerClient dockerClient)
}

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

@mattnworb mattnworb Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildArgs is now the seventh argument passed to this method that is an instance variable, perhaps it is time to make buildImage non-static so we don't have to have so many parameters passed to a method in the same class (which is never used by outside callers).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea. If you want I could give it a go, unless you think it's outside the PR scope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either option works for me

@@ -145,6 +156,15 @@ static String buildImage(@Nonnull DockerClient dockerClient,
buildParameters.add(DockerClient.BuildParam.noCache());
}

if (buildArgs != null && !buildArgs.isEmpty()) {
try {
final String encodedBuildArgs = URLEncoder.encode(new Gson().toJson(buildArgs), "utf-8");
Copy link
Member

@mattnworb mattnworb Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but I think Jersey (used by docker-client) encodes the name/value of the BuildParam as query params before they are passed to the Docker Remote API. Are you sure the encoding is needed here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised by this as well but without the encoding it complains about " in the request:

[INFO] [ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.2-ooyala-build-args:build (default) on project basic-with-build-args: Execution default of goal com.spotify:dockerfile-maven-plugin:1.3.2-ooyala-build-args:build failed: Illegal character """ at position 21 is not allowed as a start of a name in a path template "pull=true&buildargs={"IMAGE_VERSION":"0.0.1"}". -> [Help 1]

<dependencies>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>docker-client</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed as a dependency of maven-invoker-plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invoker-plugin executes the verify.groovy scripts which don't seem to inherit the dependencies in the pom. I had to add it here to be able to use the DefaultDockerClient in the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense, thanks for the clarification

@mattnworb mattnworb requested a review from dflemstr July 7, 2017 00:48

ARG IMAGE_VERSION

LABEL version=${IMAGE_VERSION}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: missing trailing newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've amended the commit and added a newline

@mattnworb mattnworb merged commit 644d1aa into spotify:master Jul 10, 2017
@mattnworb
Copy link
Member

I released version 1.3.3 of the plugin a few minutes ago with this change in it.

@glindstedt
Copy link
Contributor Author

Awesome, thanks! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants