Skip to content

Commit

Permalink
Improve container image naming.
Browse files Browse the repository at this point in the history
Add nativePlugin profile.
spring-boot:build-image -Pnative should suffice.
  • Loading branch information
corneil committed Jul 31, 2024
1 parent 7fb4765 commit cb6c08c
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ public void execute() throws MojoFailureException, MojoExecutionException {
this.global.getApplication().getFunctionDefinition() : this.application.getFunctionDefinition();
app.setFunctionDefinition(applicationFunctionDefinition); //TODO is applicationFunctionDefinition required?

String appBootPluginConfiguration = StringUtils.hasText(this.application.getBootPluginConfiguration()) ?
this.application.getBootPluginConfiguration() : this.global.getApplication().getBootPluginConfiguration();
app.setBootPluginConfiguration(appBootPluginConfiguration);

String appBootExecution = StringUtils.hasText(this.application.getBootExecution()) ?
this.application.getBootExecution() : this.global.getApplication().getBootExecution();
app.setBootExecution(appBootExecution);

Boolean skipNativeTests = this.application.skipNativeTests != null ? this.application.skipNativeTests :
this.global.application.skipNativeTests != null ? this.global.application.skipNativeTests : Boolean.FALSE;
app.setSkipNativeTests(skipNativeTests);

String nativeConfiguration = StringUtils.hasText(this.application.getNativeConfiguration()) ? this.application.getNativeConfiguration() :
this.global.getApplication().getNativeConfiguration();
app.setNativeConfiguration(nativeConfiguration);

String metadataMavenPluginVersion = StringUtils.isEmpty(this.application.getMetadata().getMavenPluginVersion()) ?
this.global.getApplication().getMetadata().getMavenPluginVersion() : this.application.getMetadata().getMavenPluginVersion();
if (StringUtils.isEmpty(metadataMavenPluginVersion)) {
Expand Down Expand Up @@ -306,8 +322,6 @@ else if (StringUtils.hasText(this.global.getApplication().getContainerImage().ge
})
.collect(Collectors.toList());

app.setBootPluginConfiguration(this.application.getBootPluginConfiguration());

// ----------------------------------------------------------------------------------------------------------
// Project Generator
// ----------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -465,6 +479,9 @@ public static class Application {
private final Maven maven = new Maven();

private String bootPluginConfiguration;
private String bootExecution;
private Boolean skipNativeTests;
private String nativeConfiguration;

public String getBootPluginConfiguration() {
return bootPluginConfiguration;
Expand All @@ -474,6 +491,30 @@ public void setBootPluginConfiguration(String bootPluginConfiguration) {
this.bootPluginConfiguration = bootPluginConfiguration;
}

public String getBootExecution() {
return bootExecution;
}

public void setBootExecution(String bootExecution) {
this.bootExecution = bootExecution;
}

public Boolean getSkipNativeTests() {
return skipNativeTests;
}

public void setSkipNativeTests(Boolean skipNativeTests) {
this.skipNativeTests = skipNativeTests;
}

public String getNativeConfiguration() {
return nativeConfiguration;
}

public void setNativeConfiguration(String nativeConfiguration) {
this.nativeConfiguration = nativeConfiguration;
}

public Map<String, String> getProperties() {
return properties;
}
Expand Down Expand Up @@ -631,7 +672,7 @@ public static class ContainerImage {
/**
* Base images to be used by the target container image.
*/
private String baseImage;
private String baseImage = "${project.artifactId}";

/**
* Enable or disable the inclusion of application's metadata into the image's labels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,18 @@ public class AppDefinition {
* Application metadata related configurations to be applied for this App definition.
*/
private final Metadata metadata = new Metadata();

private String bootExecution;
private String bootPluginConfiguration;
private Boolean skipNativeTests;
private String nativeConfiguration;

public String getBootExecution() {
return bootExecution;
}

public void setBootExecution(String bootExecution) {
this.bootExecution = bootExecution;
}

public String getBootPluginConfiguration() {
return bootPluginConfiguration;
Expand All @@ -98,6 +108,22 @@ public void setBootPluginConfiguration(String bootPluginConfiguration) {
this.bootPluginConfiguration = bootPluginConfiguration;
}

public String getNativeConfiguration() {
return nativeConfiguration;
}

public void setNativeConfiguration(String nativeConfiguration) {
this.nativeConfiguration = nativeConfiguration;
}

public Boolean getSkipNativeTests() {
return skipNativeTests;
}

public void setSkipNativeTests(Boolean skipNativeTests) {
this.skipNativeTests = skipNativeTests;
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,24 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
{{#app.bootExecution}}
<executions>
<!-- bootExecution -->
{{this}}
</executions>
{{/app.bootExecution}}
<configuration>
<image>
<name>{{app.containerImage.orgName}}/${project.artifactId}:{{app.containerImage.tag}}</name>
</image>
{{#app.bootPluginConfiguration}}
{{this}}
<!-- bootPluginConfiguration -->
{{this}}
{{/app.bootPluginConfiguration}}
<image>
<name>{{app.containerImage.orgName}}/{{app.containerImage.baseImage}}:{{app.containerImage.tag}}</name>
</image>
</configuration>
</plugin>
{{#app.containerImage.enableMetadata}}
<!-- enableMetadata -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
Expand Down Expand Up @@ -176,15 +184,18 @@
<version>{{app.metadata.mavenPluginVersion}}</version>
<configuration>
{{#app.containerImage.enableMetadata}}
<!-- enableMetadata -->
<storeFilteredMetadata>true</storeFilteredMetadata>
<metadataFilter>
<names>
{{#app.metadataNameFilters}}
<!-- metadataNameFilters -->
<filter>{{this}}</filter>
{{/app.metadataNameFilters}}
</names>
<sourceTypes>
{{#app.metadata.sourceTypeFilters}}
<!-- sourceTypeFilters -->
<filter>{{this}}</filter>
{{/app.metadata.sourceTypeFilters}}
</sourceTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>{{app.version}}</version>
<packaging>pom</packaging>

<name>Apps Modules</name>
<name>{{app.name}}-{{app.type}}-apps</name>
<description>Parent project for generated apps project modules</description>
<url>http://spring.io/spring-cloud</url>
<licenses>
Expand Down Expand Up @@ -80,7 +80,11 @@
</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 @@ -87,7 +87,7 @@ public void testSomething() throws Exception {

Parent parent = pomModel.getParent();
assertThat(parent.getArtifactId()).isEqualTo("spring-boot-starter-parent");
assertThat(parent.getVersion()).isEqualTo("3.3.0");
assertThat(parent.getVersion()).isEqualTo("3.3.2");

assertThat(pomModel.getArtifactId()).isEqualTo("http-source-kafka");
assertThat(pomModel.getGroupId()).isEqualTo("org.springframework.cloud.stream.app.test");
Expand All @@ -106,8 +106,12 @@ public void testSomething() throws Exception {
assertThat(springBootPlugin.getConfiguration().toString()).containsPattern("\\<image\\>\\s*" +
"\\<name\\>.+/\\$\\{project.artifactId\\}:\\d+\\.\\d+\\.\\d+.*\\</name\\>\\s*" +
"\\</image\\>");
assertThat(pomModel.getRepositories().size()).isEqualTo(5);

List<String> executions = springBootPlugin.getExecutions().stream().map(pluginExecution -> pluginExecution.getId() + ":" + pluginExecution.getPhase() + ":" + pluginExecution.getGoals()).collect(Collectors.toList());
assertThat(executions).as("Expected executions").isNotEmpty();
assertThat(executions.toString()).contains("process-aot");

assertThat(pomModel.getRepositories().size()).isEqualTo(5);
assertThat(pomModel.getRepositories().stream().map(r -> r.getId()).collect(Collectors.toList()))
.contains("bintray-global", "bintray-application", "bintray-binder");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void before() throws NoSuchFieldException {

// BOM
application.setBootVersion("3.3.0");
application.getMetadata().setMavenPluginVersion("1.0.2.BUILD-SNAPSHOT");
application.getMetadata().setMavenPluginVersion("1.1.0-SNAPSHOT");

setMojoProperty("application", application);

Expand Down Expand Up @@ -142,23 +142,27 @@ public void testDefaultProjectCreationByPlugin() throws Exception {
}

@Test
public void testCustomBootMavenPluginConfiguration() throws Exception {
application.setBootPluginConfiguration("<![CDATA[\n" +
" <requiresUnpack>\n" +
" <dependency>\n" +
" <groupId>org.python</groupId>\n" +
" <artifactId>jython-standalone</artifactId>\n" +
" </dependency>\n" +
" </requiresUnpack>\n" +
" ]]>");

public void testCustomBootMavenExecutionsAndPluginConfiguration() throws Exception {
application.setBootPluginConfiguration("<requiresUnpack>" +
"<dependency>" +
"<groupId>org.python</groupId>" +
"<artifactId>jython-standalone</artifactId>" +
"</dependency>" +
"</requiresUnpack>");
application.setBootExecution("<execution><id>process-aot</id>" +
"<goals>" +
"<goal>process-aot</goal>" +
"</goals></execution>");
springCloudStreamAppMojo.execute();

Model pomModel = getModel(new File(projectHome.getRoot().getAbsolutePath()));
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();

assertThat(bootPlugin.get().getConfiguration().toString()).contains("requiresUnpack");
assertThat(bootPlugin.get().getExecutions()).as("Expected executions").isNotEmpty();
assertThat(bootPlugin.get().getExecutions().get(0).getGoals()).as("Expected goals").isNotEmpty();
assertThat(bootPlugin.get().getExecutions().get(0).getGoals().get(0)).isEqualTo("process-aot");
}

private void assertGeneratedPomXml(File rootPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<packaging>jar</packaging>

<properties>
<spring-boot.version>3.3.0</spring-boot.version>
<spring-boot.version>3.3.2</spring-boot.version>
<stream-apps-core.version>5.0.0-SNAPSHOT</stream-apps-core.version>
<java-cfenv-boot.version>2.4.1</java-cfenv-boot.version>
<app-metadata-maven-plugin-version>1.1.0-SNAPSHOT</app-metadata-maven-plugin-version>
Expand Down Expand Up @@ -43,6 +43,22 @@
<global>
<application>
<bootVersion>${spring-boot.version}</bootVersion>
<skipNativeTests>true</skipNativeTests>
<nativeConfiguration><![CDATA[
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<requiredVersion>22.1</requiredVersion>
]]>
</nativeConfiguration>
<bootExecution><![CDATA[
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
]]></bootExecution>
<metadata>
<mavenPluginVersion>3.3.0</mavenPluginVersion>
</metadata>
Expand Down Expand Up @@ -219,7 +235,7 @@
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-apps-generator-plugin</artifactId>
<version>${app-metadata-maven-plugin-version}</version>
<version>1.0.0-SNAPSHOT</version>

<configuration>
<generatedProjectHome>./target/apps</generatedProjectHome>
Expand Down

0 comments on commit cb6c08c

Please sign in to comment.