Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'args' parameter to Maven plugin #361

Merged
merged 12 commits into from
Jun 4, 2018
1 change: 1 addition & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- `jib:buildDocker` maven goal to build straight to Docker daemon ([#266](https://github.com/GoogleContainerTools/jib/pull/266))
- `mainClass` is inferred by searching through class files if configuration is missing ([#278](https://github.com/GoogleContainerTools/jib/pull/278))
- Can now specify target image with `-Dimage` ([#328](https://github.com/GoogleContainerTools/jib/issues/328))
- `args` parameter to define default main args ([#346](https://github.com/GoogleContainerTools/jib/issues/346))

### Changed
- Removed `enableReproducibleBuilds` parameter - application layers will always be reproducible ([#245](https://github.com/GoogleContainerTools/jib/pull/245))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void execute() throws MojoExecutionException {
.setKnownBaseRegistryCredentials(knownBaseRegistryCredentials)
.setTargetImage(targetImage)
.setMainClass(mainClass)
.setJavaArguments(getArgs())
.setJvmFlags(getJvmFlags())
.setEnvironment(getEnvironment())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.setTargetImageCredentialHelperName(getTargetImageCredentialHelperName())
.setKnownTargetRegistryCredentials(knownTargetRegistryCredentials)
.setMainClass(mainClass)
.setJavaArguments(getArgs())
.setJvmFlags(getJvmFlags())
.setEnvironment(getEnvironment())
.setTargetFormat(ImageFormat.valueOf(getFormat()).getManifestTemplateClass())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.setBaseImage(getBaseImage())
.setJvmFlags(getJvmFlags())
.setMainClass(mainClass)
.setJavaArguments(getArgs())
.generate(Paths.get(targetDir));

mavenBuildLogger.info("Created Docker context at " + targetDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ static ImageReference parseTargetImageReference(String to) {

@Nullable @Parameter private String mainClass;

@Parameter private List<String> args = Collections.emptyList();

@Nullable
@Parameter(defaultValue = "Docker", required = true)
private String format;
Expand Down Expand Up @@ -140,6 +142,10 @@ String getMainClass() {
return mainClass;
}

List<String> getArgs() {
return args;
}

String getFormat() {
return Preconditions.checkNotNull(format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static String buildToDockerDaemonAndRun(Path projectRoot, String imageRe
@Test
public void testExecute_simple() throws VerificationException, IOException, InterruptedException {
Assert.assertEquals(
"Hello, world\n",
"Hello, world. An argument.\n",
buildToDockerDaemonAndRun(
simpleTestProject.getProjectRoot(),
"gcr.io/jib-integration-testing/simpleimage:maven"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testExecute_simple() throws VerificationException, IOException, Inte
}

Assert.assertEquals(
"Hello, world\n",
"Hello, world. An argument.\n",
buildAndRun(
simpleTestProject.getProjectRoot(),
"gcr.io/jib-integration-testing/simpleimage:maven"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void testExecute() throws VerificationException, IOException, Interrupted

String imageName = "jib/integration-test";
new Command("docker", "build", "-t", imageName, dockerContextDirectory.toString()).run();
Assert.assertEquals("Hello, world\n", new Command("docker", "run", imageName).run());
Assert.assertEquals(
"Hello, world. An argument.\n", new Command("docker", "run", imageName).run());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<to>
<image>gcr.io/jib-integration-testing/simpleimage:maven</image>
</to>
<args>An argument.</args>
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't know you could actually put it like this.

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 didn't either, it was an accident but it worked haha.

<!-- Does not have tests use user-level cache for base image layers. -->
<useOnlyProjectCache>true</useOnlyProjectCache>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public static void main(String[] args) throws IOException, URISyntaxException {
Path worldFile = Paths.get(classLoader.getResource("world").toURI());
String world = new String(Files.readAllBytes(worldFile), StandardCharsets.UTF_8);

System.out.println(greeting + ", " + world);
System.out.println(greeting + ", " + world + ". " + (args.length > 0 ? args[0] : ""));
}
}