Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy sources from remote container when quarkus.native.debug.enabled=true #15288

Merged
merged 4 commits into from
Mar 2, 2021

Conversation

zakkak
Copy link
Contributor

@zakkak zakkak commented Feb 24, 2021

When using -Dquarkus.native.remote-container-build=true in combination with -Dquarkus.native.debug.enabled=true native image generation fails with:

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:build (default) on project quarkus-integration-test-main: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: java.lang.RuntimeException: Failed to build native image
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:209)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:920)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:834)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] Caused by: java.nio.file.NoSuchFileException: /home/zakkak/code/quarkus/integration-tests/main/target/quarkus-integration-test-main-999-SNAPSHOT-native-image-source-jar/sources
[ERROR]         at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
[ERROR]         at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
[ERROR]         at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
[ERROR]         at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
[ERROR]         at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:149)
[ERROR]         at java.base/sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
[ERROR]         at java.base/java.nio.file.Files.readAttributes(Files.java:1764)
[ERROR]         at java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:225)
[ERROR]         at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
[ERROR]         at java.base/java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)
[ERROR]         at java.base/java.nio.file.Files.walkFileTree(Files.java:2717)
[ERROR]         at io.quarkus.bootstrap.util.IoUtils.copy(IoUtils.java:126)
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:191)
[ERROR]         ... 10 more

This PR fixes this by copying the sources from the container back to the host.

@zakkak
Copy link
Contributor Author

zakkak commented Feb 24, 2021

\cc @jonathan-meier

Copy link
Contributor

@jonathan-meier jonathan-meier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, though I think we already missed copying some more artefacts, e.g. the dashboard dump:

if (nativeConfig.enableDashboardDump) {
nativeImageArgs.add("-H:DashboardDump=" + outputTargetBuildItem.getBaseName() + "_dashboard.dump");
nativeImageArgs.add("-H:+DashboardAll");
}
and the native sources for the native sources build:
outputDir = buildSystemTargetBuildItem.getOutputDirectory().resolve("native-sources");
So it might make sense to assemble a list of output artefacts in NativeImageBuildStep and hand that list over to the NativeImageBuildRunner.

Also, thanks for catching the issue with the user. I missed that because in my tests the local user had the same UID as the quarkus user in the container (UID 1001). Sorry about that!

@zakkak zakkak force-pushed the copy-sources-in-containerized-build branch from 7319acc to 7975a6b Compare February 24, 2021 12:11
Using them results in files being copied back to host to be owned by the
guest user instead of the host user.

e.g.
$ podman create --name temp --user 1000:1000 --userns=keep-id -it \
    quay.io/quarkus/ubi-quarkus-native-image:21.0.0-java11
$ podman cp temp:/opt/graalvm/bin/native-image remote-native-image
$ ls -la remote-native-image
-rwxr-xr-x. 1 100000 100000 14641161 Feb 14 03:28 remote-native-image*
$ id -u
1000
@zakkak zakkak force-pushed the copy-sources-in-containerized-build branch 2 times, most recently from b2904f0 to 63fec3d Compare February 24, 2021 13:56
@zakkak zakkak force-pushed the copy-sources-in-containerized-build branch from 63fec3d to bff39cf Compare February 25, 2021 11:13
@zakkak zakkak requested a review from geoand March 1, 2021 23:31
if (workingDirectory != null) {
processBuilder.directory(workingDirectory);
}
process = processBuilder.start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are you are not redirecting the output streams like ProcessUtil#launchProcess was doing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but that's how things where before (except for cleanupServer).

runCommand is used to run native-image --shutdown-server, docker rm container-name and docker cp src dest. IMO it's OK to not redirect output for these commands (as discussed in https://github.com/quarkusio/quarkus/pull/15288/files#r582745324). WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks George

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this

@geoand geoand merged commit 19e6436 into quarkusio:master Mar 2, 2021
@quarkus-bot quarkus-bot bot added this to the 1.13 - master milestone Mar 2, 2021
@zakkak zakkak deleted the copy-sources-in-containerized-build branch March 2, 2021 07:22
@jonathan-meier
Copy link
Contributor

I just realized that #14635 has been backported to 1.12.1. Would be nice if this PR could be backported as well, mainly because of the docker user fix on Linux.

@geoand
Copy link
Contributor

geoand commented Mar 2, 2021

I am pretty sure it would clash as #15233 is not backported, so we likely won't backport this unless it's necessary.
In that case @zakkak would likely need to do a new PR of this against the 1.12 branch

@jonathan-meier
Copy link
Contributor

Oh, you are right. Even though the conflicting changes in NativeImageBuildStep are tiny, it can't be rebased cleanly.

@jonathan-meier
Copy link
Contributor

Sorry to bring this up once more, it is actually enough to just cherry-pick the second commit of this PR (5d4f39d) onto 1.12. Without this fix, the remote container build is hardly usable on 1.12 as it is.

I opened PR #15420 against 1.12 with this change. If this is undesirable or goes against your backporting protocols, feel free to just close it!

@geoand
Copy link
Contributor

geoand commented Mar 2, 2021

It's up to @gsmet to decide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants