From 190f57d2eee40cd530974158ff10195b011c5975 Mon Sep 17 00:00:00 2001 From: Michal Karm Babacek Date: Mon, 4 Sep 2023 15:10:59 +0200 Subject: [PATCH] Packs libraries alongside executable in function.zip --- .../pkg/steps/NativeImageBuildStep.java | 2 +- .../deployment/FunctionZipProcessor.java | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 1995c8d6b0533..325775bcae23a 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -1004,7 +1004,7 @@ private void handleAdditionalProperties(List command) { + CONTAINER_BUILD_VOLUME_PATH + "/" + MOVED_TRUST_STORE_NAME); } catch (IOException e) { throw new UncheckedIOException("Unable to copy trustStore file '" + configuredTrustStorePath - + "' to volume root directory '" + outputDir.toAbsolutePath().toString() + "'", e); + + "' to volume root directory '" + outputDir.toAbsolutePath() + "'", e); } } } else { diff --git a/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java b/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java index 809103a0c0c07..257aaa9e92c91 100644 --- a/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java +++ b/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java @@ -2,7 +2,9 @@ import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -21,8 +23,10 @@ import io.quarkus.deployment.pkg.builditem.JarBuildItem; import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem; import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem; +import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem; import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem; import io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem; +import io.quarkus.deployment.pkg.steps.GraalVM; import io.quarkus.deployment.pkg.steps.NativeBuild; /** @@ -106,7 +110,8 @@ public void jvmZip(OutputTargetBuildItem target, public void nativeZip(OutputTargetBuildItem target, Optional upxCompressed, // used to ensure that we work with the compressed native binary if compression was enabled BuildProducer artifactResultProducer, - NativeImageBuildItem nativeImage) throws Exception { + NativeImageBuildItem nativeImage, + NativeImageRunnerBuildItem nativeImageRunner) throws Exception { Path zipDir = findNativeZipDir(target.getOutputDirectory()); Path zipPath = target.getOutputDirectory().resolve("function.zip"); @@ -137,8 +142,26 @@ public void nativeZip(OutputTargetBuildItem target, } } addZipEntry(zip, nativeImage.getPath(), executableName, 0755); + + final GraalVM.Version graalVMVersion = nativeImageRunner.getBuildRunner().getGraalVMVersion(); + if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) { + // See https://github.com/oracle/graal/issues/4921 + try (DirectoryStream sharedLibs = Files.newDirectoryStream(nativeImage.getPath().getParent(), + "*.{so,dll}")) { + sharedLibs.forEach(src -> { + try { + // In this use case, we can force all libs to be non-executable. + addZipEntry(zip, src, src.getFileName().toString(), 0644); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } catch (IOException e) { + log.errorf("Could not list files in directory %s. Continuing. Error: %s", nativeImage.getPath().getParent(), + e); + } + } } - ; } private void copyZipEntry(ZipArchiveOutputStream zip, InputStream zinput, ZipArchiveEntry from) throws Exception {