How can I set dynamic environment variables for Docker on Heroku?

Viewed 435

I have a Ktor app deployed as a container on Heroku and want to set database properties through environment variables as discussed here rather than putting the parsing logic in my app code since it seems very Heroku-specific. Since I deploy the app as a container the JDBC variables (JDBC_DATABASE_URL, JDBC_DATABASE_USER and JDBC_DATABASE_PASSWORD) are not defined for me.

Is it possible to parse DATABASE_URL to environment variables in my Dockerfile or heroku.yml? A bash script for extracting them could look like this:

#! /bin/bash
regex="postgres://([^:]+):([^@]+)@(.+)"

if [[ $DATABASE_URL =~ $regex ]]
then
    export JDBC_DATABASE_USER="${BASH_REMATCH[1]}"
    export JDBC_DATABASE_PASSWORD="${BASH_REMATCH[2]}"
    export JDBC_DATABASE_URL="jdbc:postgresql://${BASH_REMATCH[3]}"
fi

but what do I have to do to make them available as environment variables in my app?

0 Answers
Related