DATABASE_URL is not compatible with JDBC in auto devops
Summary
When using Auto Devops, with Postgres generation enabled, the variable DATABASE_URL is created and passed to the application container. But the format postgres://user:password@postgres-host:postgres-port/postgres-database
is not compatible with JDBC driver, that expects something like:
jdbc:postgres://user:password@postgres-host:postgres-port/postgres-database
I think the most obviously solution is to export 4 different variables to the application container:
POSTGRES_USER
POSTGRES_PASSWORD
POSTGRES_DB
POSTGRES_HOST
Note that the first 3 variables can be already defined and are used to control the generation of the postgres container. The last can be auto generated with the service name of Postgres.
For more information, please read: https://gitlab.com/gitlab-com/support-forum/-/issues/4146
Steps to reproduce
Create a new spring boot project, with the database connection defined like this:
spring.datasource.url=${DATABASE_URL}
Example Project
Working on it.
What is the current bug behavior?
The application can't connect to Postgres
What is the expected correct behavior?
With the new variables, it would be possible to connect like this:
spring.datasource.url=jdbc:postgresql://${POSTGRES_HOST}:5432/${POSTGRES_DB}?useSSL=false&requireSSL=false
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}