-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
[Draft] Native image #174
[Draft] Native image #174
Conversation
Should we really make it either native or not? I am thinking of micronaut launch which creates an additional configuration to package it as a native image either via docker or Graal directly. Having this would be good in order not to move too far away from micronaut launch/CLI. |
@atomfrede Yes, I agree that would be best. That's in fact how I started working on mn-native image a couple of days ago, but... I run into the same issue as above, so I tried, maybe different approach could change results, but it's the same. So at the end I will revert that and add dockerfile with build-docker.sh like mn generates, but I need to fix that hibernate error first. Posting this for visibility and feedback like yours. |
Sounds good. I just manage to create a default mn application without jpa for now with native image support but didn't had much time to have closer look. |
@JasonTypesCodes could you please advice on the liquibase error? It seems to be coming from micronaut dependency |
@agilob I'll ask around. I don't have experience building native images with GraalVM myself, but I think we can work through it :) |
Are these related? https://liquibase.jira.com/browse/CORE-3470 |
@atomfrede might be, but liquibase seems to be working with quarkus native-image |
@agilob It seems like that class is getting loaded dynamically. This may be resolved by providing some reflection configurations. There is some guidance on doing that in this guide: https://guides.micronaut.io/micronaut-security-session/guide/index.html#graalreflectjson |
This is a possible solution, haven't looked much into it yet, but I found one problem: reflect-config.json could be added directly in dependency jar, like hibernate and others do it, it would be more future proof than generated by us for every project. It also seems to reflect file must be regenerated (or combined with preexisting) for each created |
@agilob Micronaut generates |
I've made some progress today:
I've only tried so far with postgresql without cache, I know ehcache didnt work due to graal-reflection issues. All resources from native-image load in sub-millisecond Still can't login due to liquibase issue, that I'll be working on next. You can try it with: |
Reflection config is currently provided for example purposes so it contains psql and jwt dependencies. Depending on configuration, or number of options, might have to leave generation of this file to end users https://guides.micronaut.io/micronaut-security-session/guide/index.html#graalreflectjson I would be a lot of maintenance less for us and safer for users. |
@agilob Please keep in mind that I don't know how JHispter works so maybe what I'm going to say doesn't make sense: In this commit 15ae0af you have added:
|
webpack frontend is generated from src/main/webapp and generated to
This part is absolutely necessary for frontend to be linked in native-image file, but not for liquibase (which lives in
I'll be likely reducing this file, but so far it is required for liquibase to compile with native-image, but still doesn't fix starup problem. |
Fixed liquibase startup issue, now postgres doesn't connect :D one step at a time
|
@agilob Whats the current status of this ticket? Can I help testing something? We could mark this feature as experimental in case there are cases/configurations it doesn't work yet. Would be cool to have it in the 1.0 release (e.g. the micronaut gradle plugin). |
I look at this every weekend. Last time I migrated config from .properties file to gradle to use the micronaut gradle plugin. It currently is unable to create a hibernate session on start. I have example projects where Session works, but was unable to successfully migrate that config to mhipster. |
@agilob If you are still having issues with micronaut-projects/micronaut-core#4155 , you may have better luck with Micronaut 2.2.0 |
I forgot to mention that we included GraalVM support for Liquibase in micronaut-liquibase 3.0.0. It also includes the upgrade to Liquibase 4.2.0. You may need to adjust the GraalVM configuration because now everything it's included in Micronaut. |
@agilob Can you try to fix the conflicts? Maybe we can integrate it into the 1.0.0 release as preview or just document known issues/combinations not working. |
I'll check this over the weekend @atomfrede |
Still can't get micronaut-liquibase to run initial migration... no idea about it. Any tips @ilopmar? hibernate connects to PSQL database, datasource bean is created, liquibase doesn't start, no columns are created |
@agilob This is the GraalVM test application we use for Micronaut, Liquibase, GraalVM and Postgres: https://github.com/micronaut-graal-tests/micronaut-liquibase-graal/tree/2.4.x_postgres |
Brilliant, found out that adding:
causes startup exception:
I've got something to work with now, thanks @ilopmar |
That flag is to generated "mostly" static images by default. We've changed our plugins to not doing that by default because that's the same default as in GraalVM, I mean, generate dynamic native images by default. |
Any updates on this? |
I will try to have a look at this, but time is rare at the moment, would at least like to get gradle enterprise in the main generator, which is pending way too long. |
Ignore changes in this PR, most likely this needs to be started from new, as there are too many merge conflicts with this branch. |
Closing based on comments from @agilob. |
This is a draft and WIP as the native image is quite problematic with so many dependencies. I found ehcache and logstash being hard to use without a few native-image generator flags.
To try it out:
Closes #115
metrics issue
``` 16:35:30.183 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type [javax.sql.DataSource]: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type [javax.sql.DataSource]: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1540) at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:220) at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2768) at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:228) at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:166) at io.micronaut.runtime.Micronaut.start(Micronaut.java:64) at com.mycompany.myapp.Mhip2App.main(Mhip2App.java:59) Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [javax.sql.DataSource]: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1918) at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2635) at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2621) at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2163) at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1538) ... 6 common frames omitted Caused by: java.lang.IllegalArgumentException: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry at com.zaxxer.hikari.HikariConfig.setMetricRegistry(HikariConfig.java:667) at com.zaxxer.hikari.HikariDataSource.setMetricRegistry(HikariDataSource.java:237) at io.micronaut.configuration.jdbc.hikari.DatasourceFactory.addMeterRegistry(DatasourceFactory.java:79) at io.micronaut.configuration.jdbc.hikari.DatasourceFactory.dataSource(DatasourceFactory.java:67) at io.micronaut.configuration.jdbc.hikari.$DatasourceFactory$DataSource0Definition.build(Unknown Source) at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:143) at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889) ... 10 common frames omitted ```