micronaut-projects / micronaut-aws

Projects specific to integrating Micronaut and Amazon Web Services (AWS)
Apache License 2.0
87 stars 80 forks source link

GraalVM docker-native mutliple runtime java.lang.NoSuchMethodException: io.micronaut.http.netty.* #1199

Open archenroot opened 3 years ago

archenroot commented 3 years ago

Expected Behavior

No response

Actual Behaviour

There is dozen of errors during docker run of docker-native image, sample here: java.lang.NoSuchMethodException: io.micronaut.http.netty.stream.HttpStreamsHandler$2.channelWritabilityChanged or io.micronaut.http.server.netty.RoutingInBoundHandler.channelRead etc..

all seem related to netty.stream package.

Steps To Reproduce

My class is super simple as I have everything implemented in application class to be run as cloud run function only:

package org.auto_accountant.fnc.save_image;

import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import io.micronaut.http.annotation.QueryValue;
import io.micronaut.runtime.Micronaut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Controller(value="/storage")
public class Application {

    public static void main(String[] args) {
        Micronaut.run(Application.class, args);
    }

    private static final Logger logger
            = LoggerFactory.getLogger(Application.class);
    @Post(
            value = "/save-image",
            consumes = MediaType.ALL)
    public void persistImage(
            @QueryValue String bucketKey,
            @Body byte[] content) {
        Storage storageClient = StorageOptions.getDefaultInstance().getService();
        BlobId blobId = BlobId.of("prokyon-systems-auto-accountant-eu-documents",
                bucketKey);
        BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
        storageClient.create(blobInfo, content);
    }
}

This is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.auto_accountant</groupId>
  <artifactId>save-image-fnc</artifactId>
  <version>0.1</version>
  <packaging>${packaging}</packaging>

  <parent>
    <groupId>io.micronaut</groupId>
    <artifactId>micronaut-parent</artifactId>
    <version>3.0.2</version>
  </parent>

  <properties>
    <packaging>jar</packaging>
    <jdk.version>11</jdk.version>
    <release.version>11</release.version>
    <micronaut.version>3.0.2</micronaut.version>
    <exec.mainClass>org.auto_accountant.fnc.save_image.Application</exec.mainClass>
    <micronaut.runtime>netty</micronaut.runtime>
  </properties>

  <repositories>
    <repository>
      <id>central</id>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>libraries-bom</artifactId>
        <version>22.0.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-inject</artifactId>
<!--      <scope>compile</scope>-->
    </dependency>
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-validation</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.micronaut.test</groupId>
      <artifactId>micronaut-test-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-http-client</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-http-server-netty</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-runtime</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.annotation</groupId>
      <artifactId>javax.annotation-api</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>native-image-support</artifactId>
      <version>0.8.0</version>
    </dependency>

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId>
    </dependency>

    <dependency>
      <groupId>io.micronaut.gcp</groupId>
      <artifactId>micronaut-gcp-common</artifactId>
      <version>4.0.0</version>
    </dependency>
    <dependency>
      <groupId>io.micronaut.gcp</groupId>
      <artifactId>micronaut-gcp-logging</artifactId>
      <version>4.0.0</version>
    </dependency>
    <!-- Service to Service account auth -->
    <dependency>
      <groupId>io.micronaut.gcp</groupId>
      <artifactId>micronaut-gcp-http-client</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>io.micronaut.build</groupId>
        <artifactId>micronaut-maven-plugin</artifactId>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <!-- Uncomment to enable incremental compilation -->
          <!-- <useIncrementalCompilation>false</useIncrementalCompilation> -->

          <annotationProcessorPaths combine.children="append">
            <path>
              <groupId>io.micronaut</groupId>
              <artifactId>micronaut-graal</artifactId>
              <version>${micronaut.version}</version>
            </path>
            <path>
              <groupId>io.micronaut</groupId>
              <artifactId>micronaut-inject-java</artifactId>
              <version>${micronaut.version}</version>
            </path>
            <path>
              <groupId>io.micronaut</groupId>
              <artifactId>micronaut-http-validation</artifactId>
              <version>${micronaut.version}</version>
            </path>
          </annotationProcessorPaths>
          <compilerArgs>
            <arg>-Amicronaut.processing.group=org.auto_accountant</arg>
            <arg>-Amicronaut.processing.module=save-image-fnc</arg>
          </compilerArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

Environment Information

Gentoo x86_64 openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08) OpenJDK 64-Bit Server VM GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08, mixed mode, sharing)

Example Application

No response

Version

3.0.2

archenroot commented 3 years ago

I will add also my local docker file for completeness:

FROM ghcr.io/graalvm/graalvm-ce:java11-21.2.0 AS builder
RUN echo "BUILDING WITH DOCKER!!!"

RUN gu install native-image
WORKDIR /home/app

COPY classes /home/app/classes
COPY dependency/* /home/app/libs/
RUN native-image -H:Class=org.auto_accountant.fnc.save_image.Application -H:Name=application --no-fallback -cp "/home/app/libs/*:/home/app/classes/"

FROM frolvlad/alpine-glibc:alpine-3.12
RUN echo "BUILDING WITH DOCKER!!!"

RUN apk update && apk add libstdc++

COPY --from=builder /home/app/application /app/application
#COPY auto-accountant-3e24cb383cb7.json /app/
#ENV GOOGLE_APPLICATION_CREDENTIALS=/app/auto-accountant-3e24cb383cb7.json

EXPOSE 8080
ENTRYPOINT ["/app/application"]

From here on I use: ./mvnw package -Dpackaging=docker docker ps -a | grep save-image-fnc | awk '{print $1}' | xargs docker rm docker run --name save-image-fnc -p 8080:8080 save-image-fnc

NOTE: The application actually works when I call it, it creates a file at google cloud storage bucket, but prints out large amount of errors for netty. Also I don't have such errors when running only mvn package && java -jar target/save-image-fnc-version.jar