I'm trying to deploy my Quarkus-app on Heroku. It works fine, but I needed to specify the datasource-parameters with fix values. Because Heroku might rotate this parameters, this is not a really good idea.
In Quarkus, I need this 3 parameters in application.properties
:
quarkus.datasource.username
quarkus.datasource.password
quarkus.datasource.jdbc.url
Heroku only gives me 1 environment variable (DATABASE_URL
), which defines a connection-string in the following manner:
postgres://user:pass@server:port/db-name
I know I can use environment variables like so:
quarkus.datasource.jdbc.url = jdbc:${DATABASE_URL}
But I need to split up the variable to extract user and password and to change prefix (postgresql instead of postgres).
Does anyone have an idea how to achieve this?
The dev database is meant for testing purposes. For a production application you must use one of the Heroku Postgres databases or SQL add-ons. Once you have provisioned a relational database to your application. The application reads the database connection information from the DATABASE_URL config variable. It is formatted like this:
The first variant uses the Quarkus Maven build to create the quarkus-app application structure containing the runnable "fast-jar" as well as all libraries needed inside Heroku’s build infrastructure and then deploying that result, the other one uses a local build process to create an optimized container.
If you prefer using a reactive datasource, Quarkus offers DB2, MySQL/MariaDB, and PostgreSQL reactive clients. Depending on which database you want to use, add the corresponding extension:
As mentioned above Quarkus supports a feature called Dev Services that allows you to create datasources without any config.
You can use the JDBC_DATABASE_URL
, JDBC_DATABASE_USERNAME
and JDBC_DATABASE_PASSWORD
environment variables for your use-case.
For more details, you can find the documentation here: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-jdbc_database_url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With