xolstice / protobuf-maven-plugin

Maven Plugin that executes the Protocol Buffers (protoc) compiler
https://www.xolstice.org/protobuf-maven-plugin/
Other
242 stars 79 forks source link

Protoc Plugin fails when build runs in Alpine container #23

Closed jamisonhyatt closed 7 years ago

jamisonhyatt commented 7 years ago

This may not be an issue with this plugin, however if alpine is not supported I believe the plugin should be more explicit. Changing the image to ubuntu fixes the issue. This may be a musl libc vs glibc issue, but I thought I'd open it here so it's more obvious for users if running the plugin on an unsupported OS.

OS Detection log:

[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: linux
[INFO] os.detected.arch: x86_64
[INFO] os.detected.release: alpine
[INFO] os.detected.release.version: 3.4.4
[INFO] os.detected.release.like.alpine: true
[INFO] os.detected.classifier: linux-x86_64
[INFO]                                                                         

Gives:

[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.5.0:compile (default) on project grpc-project: An error occurred while invoking protoc. Error while executing process. Cannot run program "/root/grpc-project/target/protoc-plugins/protoc-3.1.0-linux-x86_64.exe": error=2, No such file or directory -> [Help 1]

Repro:

  1. Build an image with the following dockerfile below.
  2. clone your repo with the plugin config below.
  3. run the appropriate maven goal to trigger code generation

used the following Dockerfile:

FROM openjdk:8-jdk-alpine

RUN apk add --update bash bash-doc bash-completion curl git

RUN MAVEN_VERSION=3.3.9 \
 && cd /usr/share \
 && curl -s http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar xzf - \
 && mv apache-maven-$MAVEN_VERSION /usr/share/maven \
 && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven
ENV M2_HOME /usr/share/maven

and plugin config:

<plugin>
  <groupId>org.xolstice.maven.plugins</groupId>
  <artifactId>protobuf-maven-plugin</artifactId>
  <version>0.5.0</version>
  <configuration>
    <protocArtifact>com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}</protocArtifact>
    <pluginId>grpc-java</pluginId>
    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>compile-custom</goal>
      </goals>
    </execution>
  </executions>
</plugin>
sergei-ivanov commented 7 years ago

Is it the problem same as was reported in #12 ? Are you able to locate that binary target/protoc-plugins/protoc-3.1.0-linux-x86_64.exe and run it from command line?

jamisonhyatt commented 7 years ago

Actually, I don't think it's the same issue. The binary is downloaded successfully Here is some output.

Initial Run:

[INFO] Compiling 2 proto file(s) to /root/grpc-project/target/generated-sources/protobuf/java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:36 min
[INFO] Finished at: 2016-12-09T02:02:00+00:00
[INFO] Final Memory: 14M/189M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.5.0:compile (default) on project grpc-project: An error occurred while invoking protoc. Error while executing process. Cannot run program "/root/grpc-project/target/protoc-plugins/protoc-3.1.0-linux-x86_64.exe": error=2, No such file or directory -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Showing the file exists (downloaded without execute permissions)

~/grpc-project # ls
grpc-project.iml  pom.xml        src            target
~/grpc-project # cd target/protoc-plugins/
~/grpc-project/target/protoc-plugins # ls -la
total 4028
drwxr-xr-x    2 root     root          4096 Dec  9 02:01 .
drwxr-xr-x    5 root     root          4096 Dec  9 02:01 ..
-rwxr--r--    1 root     root       4114152 Dec  9 02:01 protoc-3.1.0-linux-x86_64.exe
~/grpc-project/target/protoc-plugins # chmod +x protoc-3.1.0-linux-x86_64.exe 
~/grpc-project/target/protoc-plugins # ls -la
total 4028
drwxr-xr-x    2 root     root          4096 Dec  9 02:01 .
drwxr-xr-x    5 root     root          4096 Dec  9 02:01 ..
-rwxr-xr-x    1 root     root       4114152 Dec  9 02:01 protoc-3.1.0-linux-x86_64.exe

2nd run after modifying execute permissions

~/grpc-project/target/protoc-plugins # cd ../..
~/grpc-project # mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: linux
[INFO] os.detected.arch: x86_64
[INFO] os.detected.release: alpine
[INFO] os.detected.release.version: 3.4.4
[INFO] os.detected.release.like.alpine: true
[INFO] os.detected.classifier: linux-x86_64
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building grpc-project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- protobuf-maven-plugin:0.5.0:compile (default) @ grpc-project ---
[INFO] Compiling 2 proto file(s) to /root/grpc-project/target/generated-sources/protobuf/java
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.935 s
[INFO] Finished at: 2016-12-09T02:05:16+00:00
[INFO] Final Memory: 12M/138M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.5.0:compile (default) on project grpc-project: An error occurred while invoking protoc. Error while executing process. Cannot run program "/root/grpc-project/target/protoc-plugins/protoc-3.1.0-linux-x86_64.exe": error=2, No such file or directory -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Again, showing permissions didn't revert after mvn goal:

~/grpc-project # ls -la target/protoc-plugins/
total 4028
drwxr-xr-x    2 root     root          4096 Dec  9 02:01 .
drwxr-xr-x    5 root     root          4096 Dec  9 02:01 ..
-rwxr-xr-x    1 root     root       4114152 Dec  9 02:05 protoc-3.1.0-linux-x86_64.exe

Attempting to execute the binary manually:

/grpc-project # cd target/protoc-plugins/
~/grpc-project/target/protoc-plugins # ./protoc-3.1.0-linux-x86_64.exe 
/bin/ash: ./protoc-3.1.0-linux-x86_64.exe: not found
jamisonhyatt commented 7 years ago

I fixed the issue, and it is what I suggested. The musl libc included with alpine is not compatible with the protoc binary built by google.

I added the install instructions included here to my alpine Dockerfile and now the build is successful.

jamisonhyatt commented 7 years ago

Closing, as I believe it's definitely not an issue with the plugin but it is an error message that may send a user down a long path.

marcellodesales commented 5 years ago

Just hit the same problem... Switched to Amazon Corretto...

$ docker run -it --rm --name my-maven-project 
      -v "$(pwd)":/usr/src/mymaven 
      -w /usr/src/mymaven 
       maven:3.5.4-jdk-8-alpine mvn -s settings.xml test
...
...
Caused by: java.io.IOException: Cannot run program "/usr/src/mymaven/my-protoc-test/target/protoc-plugins/protoc-3.9.1-linux-x86_64.exe": error=2, No such file or directory
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
    at java.lang.Runtime.exec (Runtime.java:620)
    at org.codehaus.plexus.util.cli.Commandline.execute (Commandline.java:660)
    at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLineAsCallable (CommandLineUtils.java:136)
    at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLine (CommandLineUtils.java:106)
    at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLine (CommandLineUtils.java:89)
    at org.xolstice.maven.plugin.protobuf.Protoc.execute (Protoc.java:242)
    at org.xolstice.maven.plugin.protobuf.AbstractProtocMojo.execute (AbstractProtocMojo.java:569)
    at org.xolstice.maven.plugin.protobuf.AbstractProtocTestCompileMojo.execute (AbstractProtocTestCompileMojo.java:32)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec (Native Method)
    at java.lang.UNIXProcess.<init> (UNIXProcess.java:247)
    at java.lang.ProcessImpl.start (ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1029)
    at java.lang.Runtime.exec (Runtime.java:620)
    at org.codehaus.plexus.util.cli.Commandline.execute (Commandline.java:660)
    at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLineAsCallable (CommandLineUtils.java:136)
    at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLine (CommandLineUtils.java:106)
    at org.codehaus.plexus.util.cli.CommandLineUtils.executeCommandLine (CommandLineUtils.java:89)
    at org.xolstice.maven.plugin.protobuf.Protoc.execute (Protoc.java:242)
    at org.xolstice.maven.plugin.protobuf.AbstractProtocMojo.execute (AbstractProtocMojo.java:569)
    at org.xolstice.maven.plugin.protobuf.AbstractProtocTestCompileMojo.execute (AbstractProtocTestCompileMojo.java:32)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my-protoc-plugin-parent 1.0.0-SNAPSHOT ........... SUCCESS [01:52 min]
[INFO] my-protoc-plugin ................................. SUCCESS [01:18 min]
[INFO] my-protoc-plugin-test 1.0.0-SNAPSHOT ............. FAILURE [ 17.538 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:17 min
[INFO] Finished at: 2019-11-15T07:48:56Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.6.1:test-compile (protoc-my) on project my-protoc-plugin-test: An error occurred while invoking protoc: Error while executing process.: Cannot run program "/usr/src/mymaven/my-protoc-test/target/protoc-plugins/protoc-3.9.1-linux-x86_64.exe": error=2, No such file or directory -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :my-protoc-plugin-test