Fail on bootBuildImage with launch script
This commit adds a check to the support code for the Gradle plugin bootBuildImage task to ensure that the jar file that will be passed to a builder is readable and has a valid directory. This prevents a situation where the jar file cannot be read because it is prepended with a launch script, and the builder does not receive any files to process. Notes have also been added to the Gradle plugin documentation to warn against using a bootJar launchScript configuration and bootBuildImage together, as well as caveats about launchScript that match the Maven plugin documentation. Fixes gh-22223
This commit is contained in:
@@ -235,7 +235,6 @@ public class BuildRequest {
|
||||
* @return a new build request instance
|
||||
*/
|
||||
public static BuildRequest forJarFile(File jarFile) {
|
||||
assertJarFile(jarFile);
|
||||
return forJarFile(ImageReference.forJarFile(jarFile).inTaggedForm(), jarFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.util.StreamUtils;
|
||||
* Adapter class to convert a ZIP file to a {@link TarArchive}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class ZipFileTarArchive implements TarArchive {
|
||||
@@ -54,6 +55,7 @@ public class ZipFileTarArchive implements TarArchive {
|
||||
public ZipFileTarArchive(File zip, Owner owner) {
|
||||
Assert.notNull(zip, "Zip must not be null");
|
||||
Assert.notNull(owner, "Owner must not be null");
|
||||
assertArchiveHasEntries(zip);
|
||||
this.zip = zip;
|
||||
this.owner = owner;
|
||||
}
|
||||
@@ -72,6 +74,16 @@ public class ZipFileTarArchive implements TarArchive {
|
||||
tar.finish();
|
||||
}
|
||||
|
||||
private void assertArchiveHasEntries(File jarFile) {
|
||||
try (ZipFile zipFile = new ZipFile(jarFile)) {
|
||||
Assert.state(zipFile.getEntries().hasMoreElements(), "File '" + jarFile.toString()
|
||||
+ "' is not compatible with buildpacks; ensure jar file is valid and launch script is not enabled");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("File is not readable", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void copy(ZipArchiveEntry zipEntry, InputStream zip, TarArchiveOutputStream tar) throws IOException {
|
||||
TarArchiveEntry tarEntry = convert(zipEntry);
|
||||
tar.putArchiveEntry(tarEntry);
|
||||
|
||||
Reference in New Issue
Block a user