2
votes

I have a Spring boot app running on Google Cloud Run, and I want to connect to a postgres instance running on Google Cloudsql. I am able to connect using Spring Cloud GCP starter project.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
</dependency>

But I don't want to add this dependency.

I was able to connect from my local app by using using the postgressql plugin and specifying spring.datasource.url=*** after creating a Cloud proxy.

But when I tried doing the same from cloud run after using gcloud beta run deploy --add-cloudsql-instances <INSTANCE-ID> it doesn't work. According to https://cloud.google.com/run/docs/configuring/connect-cloudsql, --add-cloudsql-instances automatically creates a Cloud proxy. So why doesn't it work?

Thanks.

1

1 Answers

0
votes

This doesn't work because Java doesn't support Unix domain sockets. The Spring Cloud GCP circumvents this by using the Cloud SQL JDBC Socket Factory.

You can use the Socket Factory directly by adding it your your pom (and updating your URL as specified in the README).