quarkus: Driver does not support socket connection

Describe the bug I try to connect a projet, build in native mode and deploy on google cloud run, to google sql.

Expected behavior My app cannot reach google sql

Actual behavior I get an error : ERROR [org.hib.eng.jdb.spi.SqlExceptionHelper] (main) Driver does not support the provided URL: jdbc:postgres://[user]:[pwd]@/[db-name]?unix_sock=/cloudsql/[db-connection-name]" To Reproduce Steps to reproduce the behavior:

  1. Build image in native mode
  2. deploy on google run

Configuration Pom.xml

  <properties>
    <quarkus-plugin.version>1.5.1.Final</quarkus-plugin.version>
    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    <quarkus.platform.version>1.5.1.Final</quarkus.platform.version>
	<testcontainers.version>1.14.1</testcontainers.version>
    <surefire-plugin.version>2.22.1</surefire-plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<docker-plugin.version>0.28.0</docker-plugin.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

	<dependency>
		<groupId>io.quarkus</groupId>
		<artifactId>quarkus-hibernate-orm-panache</artifactId>
	</dependency>	
	<dependency>
		<groupId>io.quarkus</groupId>
		<artifactId>quarkus-jdbc-postgresql</artifactId>
	</dependency>   
	<!--dependency>
		<groupId>io.quarkus</groupId>
		<artifactId>quarkus-reactive-pg-client</artifactId>
	</dependency-->	
	<dependency>
		<groupId>com.google.cloud.sql</groupId>
		<artifactId>postgres-socket-factory</artifactId>
		<version>1.0.16</version>
	</dependency>	

application.properties

quarkus.datasource.db-kind=postgresql
quarkus.datasource.jdbc.url=jdbc:postgres://${DATASOURCE_USER}:${DATASOURCE_PWD}@/${DATASOURCE_DBNAME}?unix_sock=/cloudsql/${DATASOURCE_URL}

Where variables are environnements variables on google cloud run

Environment (please complete the following information):

  • Output of uname -a or ver:
  • Output of java -version:
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.5.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version):

Additional context Dockerfile.multistage

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/ubi-quarkus-native-image:19.3.1-java11 as nativebuilder
RUN mkdir -p /tmp/ssl \
  && cp /opt/graalvm/lib/security/cacerts /tmp/ssl/
  
FROM quay.io/quarkus/centos-quarkus-maven:19.3.1-java11 AS build
RUN mkdir -p /tmp/ssl \
  && cp /opt/graalvm/lib/security/cacerts /tmp/ssl/
COPY pom.xml /usr/src/app/
RUN mvn -f /usr/src/app/pom.xml -B de.qaware.maven:go-offline-maven-plugin:1.2.5:resolve-dependencies
COPY src /usr/src/app/src
USER root
RUN chown -R quarkus /usr/src/app
USER quarkus
RUN mvn -f /usr/src/app/pom.xml -Pnative clean package -DskipTests=true

## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY --from=nativebuilder /tmp/ssl/ /work/
COPY --from=build /usr/src/app/target/*-runner /work/application

# set up permissions for user `1001`
RUN chmod 775 /work /work/application \
  && chown -R 1001 /work \
  && chmod -R "g+rwX" /work \
  && chown -R 1001:root /work

EXPOSE 8080
USER 1001
ENV DISABLE_SIGNAL_HANDLERS true
CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Djavax.net.ssl.trustStore=/work/cacerts"]

Note : find this feature : https://github.com/jtama-op/quarkus/tree/18280ee018d82acef601fc022a5c6923bfb7a451/extensions/agroal

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (14 by maintainers)

Most upvoted comments

@compasspenguin I created a PR to add this to the documentation last week, you can check it here: https://github.com/quarkusio/quarkus/pull/20801/files

With the reactive client: no need for the socker factory lib, only the netty-transport-native-epoll library and without the version that is managed by Quarkus. The only configurations needed is to enable netty native transport and define the URL without host.

quarkus.datasource.reactive.url=postgresql://:5432/db-name?host=/cloudsql/project-id:zone:db-name
quarkus.vertx.prefer-native-transport=true

Be aware that this only works inside a Google managed runtime like Appengine.

Documentation for how to use Quarkus with Google Cloud SQL would be neat; especially because with a random web search and finding e.g. #5901 and #6634 and stumbling across related https://github.com/jtama-op/quarkus/commit/eb27113c050b2c98a0ef046a84d366484adf6e21, one could think this needs more work - when, actually, it does seem to work just fine using e.g. Quarkus 1.10.5 as-is, simply using a quarkus.datasource.jdbc.url=jdbc:mysql:///DB-NAME?ipTypes=PRIVATE&cloudSqlInstance=PROJECT-NAME:REGION:DB-INSTANCE&socketFactory=com.google.cloud.sql.mysql.SocketFactory (and an quarkus.datasource.db-kind=mysql and quarkus.datasource.username= & quarkus.datasource.password=, as always).

The trickiest part can be how to correctly set up all the required pre-requisites on GCP for this connection to work from a Quarkus service running on AppEngine Standard; see https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/375.

@lferna a map means you can put whatever key you want after quarkus.datasource.jdbc.additional-jdbc-properties and its value. So yes, this is correct.

@gsmet now that the PR for additinal JDBC properties is merged, I think we need to put inside our documentation how to configure the datasouce for Google Cloud SQL with the two needed properties. Where do you think we need to document this ? Inside our Datasource guide or inside our Deploy to Google Cloud Guide (or both) ?