sbtsbt-native-packagertypesafe-stacktypesafe-config

typesafe config cannot parse url with variable


I need to connect to a PostgreSQL server based on ENV variables. The ENV vars are set by Docker. I'm using sbt-native-packager to create a docker container of my akka/play project.

So i tried to add the variables to my conf:

db{
  default {
    host=${POSTGRES_PORT_5432_TCP_ADDR}
    driver=org.postgresql.Driver
    url=jdbc:postgresql://${host}:5432/mail_archive
    user=username
    password=password
  }
}

unfortunately the config file cannot be parsed anymore:

45: Expecting close brace } or a comma, got ':' (if you intended ':' to be part of the value for 'url', try enclosing the value in double quotes, or you may be able to rename the file .properties rather than .conf)

(where 45 is the url= line)

When using " around the url string, the ${host} variable is not being replaced anymore and the play application will throw a HostNotFoundException.

Does anybody have a suggestion how to include the ENV variable in the JDBC url used within the typesafe config?


Solution

  • Try the following:

    url="jdbc:postgresql://"${host}":5432/mail_archive"