I've set up a prod configuration for my datasource to connect to a GCP MySQL instance, basically following this tutorial: https://quarkus.io/guides/deploying-to-google-cloud#using-cloud-sql
Configuration is:
%prod.quarkus.datasource.db-kind=other
%prod.quarkus.datasource.jdbc.url=jdbc:mysql:///dbname
%prod.quarkus.datasource.jdbc.driver=com.mysql.cj.jdbc.Driver
%prod.quarkus.hibernate-orm.dialect=org.hibernate.dialect.MySQL5Dialect
%prod.quarkus.datasource.jdbc.additional-jdbc-properties.cloudSqlInstance=my:gcloudconnection:string
%prod.quarkus.datasource.jdbc.additional-jdbc-properties.socketFactory=com.google.cloud.sql.mysql.SocketFactory
Also I added it to maven:
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>
Then I build my container with
./mvnw package -Dquarkus.container-image.build=true -Dquarkus.native.container-build=true -Dmaven.test.skip
Then I push the image to my GCP registry and start it from GoogleRun.
This part works fine!
The point is, I want a native image to be used, so I add -Pnative
to the maven command.
From there, the first problem is that the MySQL factory lib isn't imported by graal because there is no explicit reference to it. So I have to register manually within quarkus:
@RegisterForReflection(targets = arrayOf(com.google.cloud.sql.mysql.SocketFactory::class))
class MyReflectionConfiguration {}
Now the error is
2021-11-10 11:14:08.027 HNEC
2021-11-10 10:14:08,025 WARN [org.hib.eng.jdb.env.int.JdbcEnvironmentInitiator] (JPA Startup Thread: <default>) HHH000342: Could not obtain connection to query metadata: java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
2021-11-10 11:14:08.027 HNEC
at com.google.api.client.util.SecurityUtils.loadKeyStore(SecurityUtils.java:82)
Caused by: java.lang.NullPointerException
2021-11-10 11:14:08.027 HNEC
at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:86)
So it refers to google-http-client not being compatible with a native image. The line itself in the lib is
InputStream keyStoreStream = GoogleUtils.class.getResourceAsStream("google.p12");
(so it means that GoogleUtils class is included in the native image, but not the google.p12
file).
I could import this file explicitly in my app (I tried to ;-) with no success) but I am sure there is a better way to handle it?