diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java index 0e282fbd4eb48..a506922338610 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java @@ -1,7 +1,5 @@ package io.quarkus.deployment.pkg.steps; -import static io.quarkus.deployment.pkg.steps.LinuxIDUtil.getLinuxID; - import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; @@ -12,7 +10,6 @@ import java.util.function.Function; import java.util.stream.Stream; -import org.apache.commons.lang3.SystemUtils; import org.jboss.logging.Logger; import io.quarkus.deployment.pkg.NativeConfig; @@ -33,23 +30,10 @@ public NativeImageBuildContainerRunner(NativeConfig nativeConfig, Path outputDir containerRuntime = nativeConfig.containerRuntime.orElseGet(NativeImageBuildContainerRunner::detectContainerRuntime); log.infof("Using %s to run the native image builder", containerRuntime.getExecutableName()); - List containerRuntimeArgs = new ArrayList<>(); - Collections.addAll(containerRuntimeArgs, "--env", "LANG=C"); + this.baseContainerRuntimeArgs = new String[] { "--env", "LANG=C" }; outputPath = outputDir == null ? null : outputDir.toAbsolutePath().toString(); - if (SystemUtils.IS_OS_LINUX) { - String uid = getLinuxID("-ur"); - String gid = getLinuxID("-gr"); - if (uid != null && gid != null && !uid.isEmpty() && !gid.isEmpty()) { - Collections.addAll(containerRuntimeArgs, "--user", uid + ":" + gid); - if (containerRuntime == NativeConfig.ContainerRuntime.PODMAN) { - // Needed to avoid AccessDeniedExceptions - containerRuntimeArgs.add("--userns=keep-id"); - } - } - } - this.baseContainerRuntimeArgs = containerRuntimeArgs.toArray(new String[0]); } @Override diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java index 301ff34d40e2f..ec8e6ee6cb4e2 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java @@ -1,5 +1,7 @@ package io.quarkus.deployment.pkg.steps; +import static io.quarkus.deployment.pkg.steps.LinuxIDUtil.getLinuxID; + import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -21,7 +23,18 @@ protected List getContainerRuntimeBuildArgs() { String volumeOutputPath = outputPath; if (SystemUtils.IS_OS_WINDOWS) { volumeOutputPath = FileUtil.translateToVolumePath(volumeOutputPath); + } else if (SystemUtils.IS_OS_LINUX) { + String uid = getLinuxID("-ur"); + String gid = getLinuxID("-gr"); + if (uid != null && gid != null && !uid.isEmpty() && !gid.isEmpty()) { + Collections.addAll(containerRuntimeArgs, "--user", uid + ":" + gid); + if (containerRuntime == NativeConfig.ContainerRuntime.PODMAN) { + // Needed to avoid AccessDeniedExceptions + containerRuntimeArgs.add("--userns=keep-id"); + } + } } + Collections.addAll(containerRuntimeArgs, "--rm", "-v", volumeOutputPath + ":" + NativeImageBuildStep.CONTAINER_BUILD_VOLUME_PATH + ":z"); return containerRuntimeArgs;