keeganwitt / docker-gradle

Docker images with Gradle
https://hub.docker.com/_/gradle/
Apache License 2.0
143 stars 73 forks source link

Add images with GraalVM installed (closes #253) #254

Closed keeganwitt closed 1 year ago

keeganwitt commented 1 year ago

Since there are no official images for GraalVM, the only option I can think of for this feature is to install it manually. This unfortunately does mean I'll have to update the images myself whenever there is a new GraalVM release.

keeganwitt commented 1 year ago

I originally was going to add GraalVM as a second JVM, but then decided it'd be better to have it be the only JVM (https://github.com/keeganwitt/docker-gradle/compare/5981ff55b9c364bc10a0b5f5cf1c68d3f8319de6..9ad43556146e796ab9cade489c9c0dca9523bbff).

XhstormR commented 1 year ago

In order for the native image tools to work we need to install the gcc tools: apt-get install build-essential libz-dev zlib1g-dev

https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites

keeganwitt commented 1 year ago

In order for the native image tools to work we need to install the gcc tools: apt-get install build-essential libz-dev zlib1g-dev

https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites

Thank you! Added.

keeganwitt commented 1 year ago

Some early feedback I got on the PR is that I should add the packages under build-essential directly rather than add a dependency on that since that package is meant for building Debian packages. For example, it adds a dependency on dpkg-dev which installs things that aren't required for this use case.

keeganwitt commented 1 year ago

Folks from Docker Library confirmed that there shouldn't be an issue installing GraalVM even though Graal folks weren't supportive of the idea of making an official image.

keeganwitt commented 1 year ago

This isn't working yet.

* What went wrong:
Gradle could not start your build.
> Could not initialize native services.
   > Failed to load native library 'libnative-platform.so' for Linux amd64.
XhstormR commented 1 year ago

Failed to load native library 'libnative-platform.so' for Linux amd64

It seems to be a folder permission error: https://github.com/gradle/gradle/issues/8107 https://github.com/gradle/gradle/issues/8913

XhstormR commented 1 year ago

BTW I use the image built by jdk17-graal/Dockerfile, gradle and native-image programs can work normally.

gradle test:

$ mkdir abc && cd abc
$ gradle init
$ gradle build
$ gradle run

native-image test:

$ javac HelloWorld.java
$ native-image HelloWorld
$ ./helloworld 

HelloWorld.java:

public class HelloWorld {
    static class Greeter {
        static {
            System.out.println("Greeter is getting ready!");
        }

        public static void greet() {
          System.out.println("Hello, World!");
        }
    }

  public static void main(String[] args) {
    Greeter.greet();
  }
}
keeganwitt commented 1 year ago

This isn't working yet.

* What went wrong:
Gradle could not start your build.
> Could not initialize native services.
   > Failed to load native library 'libnative-platform.so' for Linux amd64.

Actually, this only happens when not running as root for some reason. docker run --rm -v "${pwd}:/root/project" -w /root/project gradle:17-graal gradle build

keeganwitt commented 1 year ago

FIxed

This isn't working yet.

* What went wrong:
Gradle could not start your build.
> Could not initialize native services.
   > Failed to load native library 'libnative-platform.so' for Linux amd64.

Actually, this only happens when not running as root for some reason. docker run --rm -v "${pwd}:/root/project" -w /root/project gradle:17-graal gradle build

Fixed by moving chown.

keeganwitt commented 1 year ago

BTW I use the image built by jdk17-graal/Dockerfile, gradle and native-image programs can work normally.

gradle test:

$ mkdir abc && cd abc
$ gradle init
$ gradle build
$ gradle run

native-image test:

$ javac HelloWorld.java
$ native-image HelloWorld
$ ./helloworld 

HelloWorld.java:

public class HelloWorld {
    static class Greeter {
        static {
            System.out.println("Greeter is getting ready!");
        }

        public static void greet() {
          System.out.println("Hello, World!");
        }
    }

  public static void main(String[] args) {
    Greeter.greet();
  }
}

Thanks for testing this!