Support image building with Maven and war packaging
This commit updates the Maven image building goal to support building images from executable and non-executable war files. Fixes gh-23823
This commit is contained in:
@@ -68,6 +68,30 @@ public class BuildImageTests extends AbstractArchiveIntegrationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void whenBuildImageIsInvokedWithWarPackaging(MavenBuild mavenBuild) {
|
||||
mavenBuild.project("build-image-war-packaging").goals("package")
|
||||
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
|
||||
.prepare(this::writeLongNameResource).execute((project) -> {
|
||||
File war = new File(project, "target/build-image-war-packaging-0.0.1.BUILD-SNAPSHOT.war");
|
||||
assertThat(war).isFile();
|
||||
File original = new File(project,
|
||||
"target/build-image-war-packaging-0.0.1.BUILD-SNAPSHOT.war.original");
|
||||
assertThat(original).doesNotExist();
|
||||
assertThat(buildLog(project)).contains("Building image")
|
||||
.contains("docker.io/library/build-image-war-packaging:0.0.1.BUILD-SNAPSHOT")
|
||||
.contains("Successfully built image");
|
||||
ImageReference imageReference = ImageReference.of(ImageName.of("build-image-war-packaging"),
|
||||
"0.0.1.BUILD-SNAPSHOT");
|
||||
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
|
||||
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
|
||||
}
|
||||
finally {
|
||||
removeImage(imageReference);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) {
|
||||
mavenBuild.project("build-image-custom-name").goals("package")
|
||||
@@ -191,12 +215,6 @@ public class BuildImageTests extends AbstractArchiveIntegrationTests {
|
||||
.containsPattern("Builder lifecycle '.*' failed with status code"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void failsWithWarPackaging(MavenBuild mavenBuild) {
|
||||
mavenBuild.project("build-image-war-packaging").goals("package").executeAndFail(
|
||||
(project) -> assertThat(buildLog(project)).contains("Executable jar file required for building image"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void failsWithBuildpackNotInBuilder(MavenBuild mavenBuild) {
|
||||
mavenBuild.project("build-image-bad-buildpack").goals("package")
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.boot.maven.it</groupId>
|
||||
<artifactId>build-image-war</artifactId>
|
||||
<artifactId>build-image-war-packaging</artifactId>
|
||||
<version>0.0.1.BUILD-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<properties>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,10 @@ package org.test;
|
||||
public class SampleApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Launched");
|
||||
synchronized(args) {
|
||||
args.wait(); // Prevent exit"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user