SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

GraalVM image is not able to run JS Plugins #463

Closed timia2109 closed 1 year ago

timia2109 commented 1 year ago

Hello, I've used the JS Plugin examples and try to get them to work using the 7.2.5-graalvm image. They failed to load with the log entry is not javascript

According to the docs:

RESTHeart running on the GraalVM that will let you JavaScript plugins

I've set up the images and mount the example path. After swapping the image from 7.2.5-graalvm to 7.2.5-native the plugins start working. Except the .ts File.

Log from 7.2.5-graalvm:

restheart-dev-restheart-1  | 19:29:01.593 [main] INFO  org.restheart.Bootstrapper - Starting RESTHeart instance default
restheart-dev-restheart-1  |  19:29:01.594 [main] INFO  org.restheart.Bootstrapper - Version 7.2.5
restheart-dev-restheart-1  |  19:29:01.620 [main] INFO  org.restheart.Bootstrapper - Logging to console with level INFO
restheart-dev-restheart-1  |  19:29:01.638 [main] INFO  o.r.configuration.Configuration - Overriding configuration from file: /opt/restheart/etc/conf-overrides.yaml
restheart-dev-restheart-1  |  19:29:01.640 [main] INFO  o.r.configuration.Configuration -       /mclient/connection-string -> mongodb://mongodb
restheart-dev-restheart-1  |  19:29:01.640 [main] INFO  o.r.configuration.Configuration -       /mongo/mongo-mounts[1] -> {what=/restheart, where=/}
restheart-dev-restheart-1  |  19:29:01.640 [main] INFO  o.r.configuration.Configuration -       /mongo/mongo-mounts[2] -> {what=/itevent, where=/itevent}
restheart-dev-restheart-1  |  19:29:01.641 [main] INFO  o.r.configuration.Configuration -       /jwtAuthenticationMechanism -> {audience=restheart, base64Encoded=false, rolesClaim=roles, usernameClaim=sub, enabled=true, key=SOME_PUBLIC_KEY, issuer=SOME_ISSUER, algorithm=RS256}
restheart-dev-restheart-1  |  19:29:01.641 [main] INFO  o.r.configuration.Configuration - Overriding configuration from environment variable RHO
restheart-dev-restheart-1  |  19:29:01.641 [main] INFO  o.r.configuration.Configuration -       /mclient/connection-string -> mongodb://mongodb
restheart-dev-restheart-1  |  19:29:01.641 [main] INFO  o.r.configuration.Configuration -       /http-listener/host -> 0.0.0.0
restheart-dev-restheart-1  |  19:29:01.661 [main] INFO  org.restheart.plugins.PluginsFactory - Found plugin jar file:/opt/restheart/plugins/restheart-mongoclient-provider.jar
restheart-dev-restheart-1  |  19:29:01.662 [main] INFO  org.restheart.plugins.PluginsFactory - Found plugin jar file:/opt/restheart/plugins/restheart-security.jar
restheart-dev-restheart-1  |  19:29:01.662 [main] INFO  org.restheart.plugins.PluginsFactory - Found plugin jar file:/opt/restheart/plugins/restheart-polyglot.jar
restheart-dev-restheart-1  |  19:29:01.662 [main] INFO  org.restheart.plugins.PluginsFactory - Found plugin jar file:/opt/restheart/plugins/restheart-mongodb.jar
restheart-dev-restheart-1  |  19:29:01.662 [main] INFO  org.restheart.plugins.PluginsFactory - Found plugin jar file:/opt/restheart/plugins/restheart-graphql.jar
restheart-dev-restheart-1  |  19:29:02.540 [main] INFO  o.r.mongodb.MongoClientSingleton - Connecting to MongoDB...
restheart-dev-restheart-1  |  19:29:06.668 [main] INFO  o.r.mongodb.MongoClientSingleton - MongoDB version 5.0.18
restheart-dev-restheart-1  |  19:29:06.672 [main] WARN  o.r.mongodb.MongoClientSingleton - MongoDB is a standalone instance.
restheart-dev-restheart-1  |  19:29:06.954 [main] INFO  o.r.polyglot.PolyglotDeployer - Found js plugin directory /opt/restheart/plugins/js-plugins
restheart-dev-restheart-1  |  19:29:06.967 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/hello.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.969 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/./sub/hello.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.970 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/require-module-service.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.972 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/mclient-service.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.973 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/http-client.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.974 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/test.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.975 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/test.ts is not javascript
restheart-dev-restheart-1  |  19:29:06.981 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/hello-interceptor.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.983 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/mongo-get-doc-interceptor.mjs is not javascript
restheart-dev-restheart-1  |  19:29:06.984 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/mongo-post-coll-interceptor.mjs is not javascript
restheart-dev-restheart-1  |  19:29:07.218 [main] INFO  org.restheart.mongodb.MongoService - URI / bound to MongoDB resource /restheart
restheart-dev-restheart-1  |  19:29:07.219 [main] INFO  org.restheart.mongodb.MongoService - URI /itevent bound to MongoDB resource /itevent
restheart-dev-restheart-1  |  19:29:07.255 [main] INFO  org.restheart.Bootstrapper - HTTP listener bound at 0.0.0.0:8080
restheart-dev-restheart-1  |  19:29:07.270 [main] INFO  org.restheart.Bootstrapper - URI / bound to service mongo, secured: true, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.270 [main] INFO  org.restheart.Bootstrapper - URI /graphql bound to service graphql, secured: true, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.271 [main] INFO  org.restheart.Bootstrapper - URI /ic bound to service cacheInvalidator, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.272 [main] INFO  org.restheart.Bootstrapper - URI /csv bound to service csvLoader, secured: true, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.272 [main] INFO  org.restheart.Bootstrapper - URI /tokens bound to service authTokenService, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.273 [main] INFO  org.restheart.Bootstrapper - URI /roles bound to service roles, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.273 [main] INFO  org.restheart.Bootstrapper - URI /ping bound to service ping, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:29:07.279 [main] INFO  org.restheart.Bootstrapper - Available processors: 12, IO threads (auto detected): 12, worker threads (auto detected): 96,
restheart-dev-restheart-1  |  19:29:07.457 [main] INFO  org.restheart.Bootstrapper - Pid file /var/run/restheart-0.pid
restheart-dev-restheart-1  |  19:29:07.459 [main] ERROR o.r.m.h.c.ChangeStreamsActivator - Cannot enable Change Streams: MongoDB is a standalone instance and Change Streams require a Replica Set.
restheart-dev-restheart-1  |  19:29:07.461 [main] ERROR o.r.m.h.sessions.TxnsActivator - Cannot enable Transactions: MongoDB is a standalone instance and Transactions require a Replica Set.
restheart-dev-restheart-1  |  19:29:07.461 [main] INFO  org.restheart.Bootstrapper - RESTHeart started

Log from 7.2.5-native:

restheart-dev-restheart-1  | 19:22:49.419 [main] INFO  org.restheart.Bootstrapper - Starting RESTHeart instance default
restheart-dev-restheart-1  |  19:22:49.419 [main] INFO  org.restheart.Bootstrapper - Version 7.2.5
restheart-dev-restheart-1  |  19:22:49.420 [main] INFO  org.restheart.Bootstrapper - Logging to console with level INFO
restheart-dev-restheart-1  |  19:22:49.423 [main] INFO  o.r.configuration.Configuration - Overriding configuration from file: /opt/restheart/etc/conf-overrides.yaml
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration -       /mclient/connection-string -> mongodb://mongodb
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration -       /mongo/mongo-mounts[1] -> {what=/restheart, where=/}
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration -       /mongo/mongo-mounts[2] -> {what=/itevent, where=/itevent}
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration -       /jwtAuthenticationMechanism -> {audience=restheart, base64Encoded=false, rolesClaim=roles, usernameClaim=sub, enabled=true, key=SOME_PUBLIC_KEY, issuer=https://SOME-ISSUER, algorithm=RS256}
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration - Overriding configuration from environment variable RHO
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration -       /mclient/connection-string -> mongodb://mongodb
restheart-dev-restheart-1  |  19:22:49.424 [main] INFO  o.r.configuration.Configuration -       /http-listener/host -> 0.0.0.0
restheart-dev-restheart-1  |  19:22:49.451 [main] INFO  o.r.mongodb.MongoClientSingleton - Connecting to MongoDB...
restheart-dev-restheart-1  |  19:22:49.457 [main] INFO  o.r.mongodb.MongoClientSingleton - MongoDB version 5.0.18
restheart-dev-restheart-1  |  19:22:49.457 [main] WARN  o.r.mongodb.MongoClientSingleton - MongoDB is a standalone instance.
restheart-dev-restheart-1  |  19:22:49.468 [main] INFO  o.r.polyglot.PolyglotDeployer - Found js plugin directory /opt/restheart/plugins/js-plugins
restheart-dev-restheart-1  |  19:22:49.478 [main] WARN  o.r.polyglot.PolyglotDeployer - /opt/restheart/plugins/js-plugins/test.ts is not javascript
restheart-dev-restheart-1  |  19:22:49.517 [main] INFO  o.r.polyglot.PolyglotDeployer - URI /hello bound to service helloWorldService, description: just another Hello World, secured: true, uri match EXACT
restheart-dev-restheart-1  |  19:22:49.617 [main] INFO  o.r.polyglot.PolyglotDeployer - URI /sub/hello bound to service anotherHelloWorldService, description: yet another Hello World, secured: false, uri match EXACT
restheart-dev-restheart-1  |  19:22:49.810 [main] INFO  o.r.polyglot.PolyglotDeployer - URI /requireModuleService bound to service requireModuleService, description: just an example JavaScript service that uses a CommonJS module , secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:22:49.836 [main] INFO  o.r.polyglot.PolyglotDeployer - URI /mclientService bound to service mclientService, description: just an example JavaScript service that uses the MongoClient, secured: true, uri match EXACT
restheart-dev-restheart-1  |  19:22:49.862 [main] INFO  o.r.polyglot.PolyglotDeployer - URI /httpClient bound to service httpClientService, description: a service that uses java.net.http.HttpClient to execute a GET request, secured: false, uri match EXACT
restheart-dev-restheart-1  |  19:22:49.889 [main] INFO  o.r.polyglot.PolyglotDeployer - URI /helloTS bound to service helloWorldTS, description: Test typescript, secured: false, uri match EXACT
restheart-dev-restheart-1  |  19:22:49.926 [main] INFO  o.r.polyglot.PolyglotDeployer - Added interceptor helloWorldInterceptor, description: modifies the response of helloWorldService
restheart-dev-restheart-1  |  19:22:49.962 [main] INFO  o.r.polyglot.PolyglotDeployer - Added interceptor mongoGetDocInteceptor, description: a js interceptor that modified the response of GET /coll/<docid>
restheart-dev-restheart-1  |  19:22:49.995 [main] INFO  o.r.polyglot.PolyglotDeployer - Added interceptor mongoPostCollInterceptor, description: modifies the content of POST requests adding a timestamp
restheart-dev-restheart-1  |  19:22:50.002 [main] INFO  org.restheart.mongodb.MongoService - URI / bound to MongoDB resource /restheart
restheart-dev-restheart-1  |  19:22:50.002 [main] INFO  org.restheart.mongodb.MongoService - URI /itevent bound to MongoDB resource /itevent
restheart-dev-restheart-1  |  19:22:50.002 [main] INFO  org.restheart.Bootstrapper - HTTP listener bound at 0.0.0.0:8080
restheart-dev-restheart-1  |  19:22:50.002 [main] INFO  org.restheart.Bootstrapper - URI / bound to service mongo, secured: true, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.003 [main] INFO  org.restheart.Bootstrapper - URI /graphql bound to service graphql, secured: true, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.003 [main] INFO  org.restheart.Bootstrapper - URI /ic bound to service cacheInvalidator, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.003 [main] INFO  org.restheart.Bootstrapper - URI /csv bound to service csvLoader, secured: true, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.003 [main] INFO  org.restheart.Bootstrapper - URI /tokens bound to service authTokenService, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.003 [main] INFO  org.restheart.Bootstrapper - URI /roles bound to service roles, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.003 [main] INFO  org.restheart.Bootstrapper - URI /ping bound to service ping, secured: false, uri match PREFIX
restheart-dev-restheart-1  |  19:22:50.004 [main] INFO  org.restheart.Bootstrapper - Available processors: 12, IO threads (auto detected): 12, worker threads (auto detected): 96,
restheart-dev-restheart-1  |  19:22:50.014 [main] INFO  org.restheart.Bootstrapper - Pid file /var/run/restheart-0.pid
restheart-dev-restheart-1  |  19:22:50.015 [main] ERROR o.r.m.h.c.ChangeStreamsActivator - Cannot enable Change Streams: MongoDB is a standalone instance and Change Streams require a Replica Set.
restheart-dev-restheart-1  |  19:22:50.015 [main] ERROR o.r.m.h.sessions.TxnsActivator - Cannot enable Transactions: MongoDB is a standalone instance and Transactions require a Replica Set.
restheart-dev-restheart-1  |  19:22:50.015 [main] INFO  org.restheart.Bootstrapper - RESTHeart started

Expected Behavior

The plugins load or docs should be corrected.

Current Behavior

Plugins are unable to load with the error they are not JavaScript

Context

Environment

docker-compose.yaml

version: "3"

services:
  restheart:
    image: softinstigate/restheart:7.2.5-graalvm
    restart: unless-stopped
    command: "-o etc/conf-overrides.yaml"
    environment:
      RHO: >
        /mclient/connection-string->"mongodb://mongodb"; /http-listener/host->"0.0.0.0";
    ports:
      - 8080:8080
    volumes:
      - ./restheart.yaml:/opt/restheart/etc/conf-overrides.yaml
      - ./js-plugin:/opt/restheart/plugins/js-plugins
    depends_on:
      - mongodb

  mongodb:
    image: mongo:5.0
    command: [ "--bind_ip_all" ]
    volumes: 
      - ./mongodata:/data/db

I've used the same compose only swapping the tag for the native image.

Hint: my config overrides are nothing special and I got the same behavior after removing it.

Plugin Path

image

Enviornment

Steps to Reproduce

  1. Set up a docker compose file using the GraalVM image
  2. Mount the example JavaScript files
  3. Start the containers
ujibang commented 1 year ago

Hello @timia2109

I figured out that the graalvm image used to run restheart https://github.com/softInstigate/graalvm-docker was missing the graalvm js package.

We updated it and fixed the latest graalvm image:

$ docker pull softinstigate/restheart:7.4.2-graalvm

Please upgrade your image and try again.

timia2109 commented 1 year ago

Works! Thank you :)