Skip to content

Commit

Permalink
Remove jib from apps-generator plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
corneil committed Jun 4, 2024
1 parent b2800d3 commit 80e57eb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,46 +141,21 @@
{{#app.bootPluginConfiguration}}
<configuration>
{{this}}
{{#app.containerImage.enableMetadata}}
<image>
<name>{{app.containerImage.orgName}}/${project.artifactId}:{{app.containerImage.tag}}</name>
</image>
{{/app.containerImage.enableMetadata}}
</configuration>
{{/app.bootPluginConfiguration}}
</plugin>

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<from>
<image>{{app.containerImage.baseImage}}</image>
</from>
<to>
<image>{{app.containerImage.orgName}}/${project.artifactId}:{{app.containerImage.tag}}</image>
</to>
<container>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
<format>{{app.containerImage.format}}</format>
{{#app.containerImage.enableMetadata}}
<labels>
<org.springframework.cloud.dataflow.spring-configuration-metadata.json>
${org.springframework.cloud.dataflow.spring.configuration.metadata.json}
</org.springframework.cloud.dataflow.spring-configuration-metadata.json>
<application.name>${project.artifactId}</application.name>
<application.version>${project.version}</application.version>
</labels>
{{/app.containerImage.enableMetadata}}
</container>
</configuration>
</plugin>

{{#app.containerImage.enableMetadata}}
<!--
Use of properties-maven-plugin to load the encoded metadata properties created by the jib-maven-plugin
Use: Use: ./mvnw clean install jib:dockerBuild or ./mvnw clean install jib:build
-->

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-classes</phase>
Expand Down Expand Up @@ -232,7 +207,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<version>3.2.5</version>
<configuration>
<threadCount>1</threadCount>
<forkCount>1</forkCount>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.3.0</version>
</plugin>

</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,8 @@ public void testSomething() throws Exception {

assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("spring-boot-maven-plugin")).count()).isEqualTo(1);
assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("properties-maven-plugin")).count()).isEqualTo(1);
assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("jib-maven-plugin")).count()).isEqualTo(1);

Plugin jibPlugin = plugins.stream().filter(p -> p.getArtifactId().equals("jib-maven-plugin")).findFirst().get();
assertThat(jibPlugin.getConfiguration().toString())
.contains("<org.springframework.cloud.dataflow.spring-configuration-metadata.json>" +
"${org.springframework.cloud.dataflow.spring.configuration.metadata.json}" +
"</org.springframework.cloud.dataflow.spring-configuration-metadata.json>");
assertThat(jibPlugin.getConfiguration().toString()).contains("<image>testspringcloud/${project.artifactId}:3.0.0.BUILD-SNAPSHOT</image>");
assertThat(jibPlugin.getConfiguration().toString()).contains("<image>globalBaseImage</image>");


assertThat(pomModel.getRepositories().size()).isEqualTo(5);

assertThat(pomModel.getRepositories().stream().map(r -> r.getId()).collect(Collectors.toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -128,13 +127,6 @@ public void testWithDisabledContainerMetadata() throws Exception {
// The properties-maven-plugin should not be defined if the container metadata is not enabled.
assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("properties-maven-plugin")).count()).isEqualTo(0);

assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("jib-maven-plugin")).count()).isEqualTo(1);

Plugin jibPlugin = plugins.stream().filter(p -> p.getArtifactId().equals("jib-maven-plugin")).findFirst().get();
assertThat(jibPlugin.getConfiguration().toString())
.doesNotContain("<org.springframework.cloud.dataflow.spring-configuration-metadata.json>" +
"${org.springframework.cloud.dataflow.spring.configuration.metadata.json}" +
"</org.springframework.cloud.dataflow.spring-configuration-metadata.json>");
}

@Test
Expand Down Expand Up @@ -166,11 +158,7 @@ public void testCustomBootMavenPluginConfiguration() throws Exception {
List<Plugin> plugins = pomModel.getBuild().getPlugins();
final Optional<Plugin> bootPlugin = plugins.stream().filter(p -> p.getArtifactId().equals("spring-boot-maven-plugin")).findFirst();
assertThat(bootPlugin.isPresent()).isTrue();
final Plugin plugin = bootPlugin.get();
final Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
assertThat(configuration.getValue().contains("<requiresUnpack>")).isTrue();
assertThat(configuration.getValue().contains("jython-standalone")).isTrue();
assertThat(configuration.getValue().contains("</requiresUnpack>")).isTrue();

}

private void assertGeneratedPomXml(File rootPath) {
Expand Down Expand Up @@ -199,14 +187,7 @@ private void assertGeneratedPomXml(File rootPath) {
List<Plugin> plugins = pomModel.getBuild().getPlugins();
assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("spring-boot-maven-plugin")).count()).isEqualTo(1);
assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("properties-maven-plugin")).count()).isEqualTo(1);
assertThat(plugins.stream().filter(p -> p.getArtifactId().equals("jib-maven-plugin")).count()).isEqualTo(1);

Plugin jibPlugin = plugins.stream().filter(p -> p.getArtifactId().equals("jib-maven-plugin")).findFirst().get();
assertThat(jibPlugin.getConfiguration().toString())
.contains("<org.springframework.cloud.dataflow.spring-configuration-metadata.json>" +
"${org.springframework.cloud.dataflow.spring.configuration.metadata.json}" +
"</org.springframework.cloud.dataflow.spring-configuration-metadata.json>");
assertThat(jibPlugin.getConfiguration().toString()).contains("<image>base/image</image>");


assertThat(pomModel.getRepositories().size()).isEqualTo(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void storeFilteredMetadata() throws MojoExecutionException {
new File(projectMetaInfFolder, "spring-configuration-metadata-encoded.properties"))) {
ConfigurationMetadata metadata = gatherConfigurationMetadata(metadataFilter);
String escapedJson = StringEscapeUtils.escapeJson(toJson(metadata));
fileWriter.write("org.springframework.cloud.dataflow.spring.configuration.metadata.json=" + escapedJson);
fileWriter.write("org.springframework.cloud.dataflow.spring.configuration.metadata.json=\"" + escapedJson + "\"");
}
catch (IOException e) {
throw new MojoExecutionException("Error creating file ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ cd applications/sink/log-sink/apps/log-sink-rabbit
----

==== Building a Docker image
The apps use the https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin[Jib Maven Plugin] to build and publish the Docker image.

[source,shell]
----
./mvnw spring-boot:build-image
----

If you have made some changes to an app, you may want to build the image and test it locally.

NOTE: If you plan to use the image with minikube, run the following command before building the image:
Expand All @@ -132,17 +137,19 @@ To build the image in your local registry:

[source,shell]
----
./mvnw clean package jib:dockerBuild
./mvnw clean package spring-boot:build-image
----

To publish the image to a remote registry:

[source,shell]
----
./mvnw jib:build \
-Djib.to.image=myregistry/myimage:latest \
-Djib.to.auth.username=$USERNAME \
-Djib.to.auth.password=$PASSWORD
./mvnw spring-boot:build-image \
-Ddocker.publishRegistry.username=registry-user \
-Ddocker.publishRegistry.password=registry-secret \
-Ddocker.publishRegistry.url=docker.private-registry.com \
-Dspring-boot.build-image.publish=true \
-Dspring-boot.build-image.imageName=docker.private-registry.com/library/my-app:v1
----

== Patching Pre-built Applications
Expand Down Expand Up @@ -240,7 +247,7 @@ For example, if we have to update Spring Cloud Stream to `3.2.4-SNAPSHOT`, this
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-dependencies</artifactId>
<version>4.0.3</version>
<version>4.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down

0 comments on commit 80e57eb

Please sign in to comment.