I'm installing ejabberd as a dependency (ref: https://blog.process-one.net/how-to-use-ejabberd-as-an-elixir-application-dependency/ ) and I've been recently trying to bundle it into a docker container.
First problem I've encountered was a static configuration file in yaml. I'd like some parameters to be passed as environment variables (like database credentials). I thought it could be solved with bit of Erlang magic, but unfortunately only terms are supported. Following snipped placed in ejabberd.yml:
sql_password: "> os:getenv(\"DB_PASS\", \"defaultpassword\")."
results in:
** (MatchError) no match of right hand side value: {:error, {1, :erl_parse, 'bad term'}}
Maybe I'm missing something, but is there any way to inject configuration parameters from env vars?
BTW: if not, this is a nice example on how it could work in ideal world: https://www.elastic.co/guide/en/beats/winlogbeat/current/using-environ-vars.html
Maybe it sounds like a good feature idea? 馃
So, you already have environment variables. And you expect ejabberd to accept them somehow. The reality is that ejabberd reads configuration from a config file.
Have you tried to produce the config file immediately before you start ejabberd?
For example, in your ejabberd.yml you could add those lines:
sql_type: mysql
sql_server: "localhost"
include_config_file:
"/tmp/ejabberd-database.yml":
allow_only:
- sql_database
- sql_username
- sql_password
Then, write a small script that produces a small config file /tmp/ejabberd-database.yml like this using your evironment variables:
sql_database: "ejabberd_test_db"
sql_username: "myuser11"
sql_password: "somepass66"
Then, first call that script to produce that small file, and then start ejabberd.
Yup, I'm approaching this issue exactly like this this right now, but with dockerize (https://github.com/jwilder/dockerize), so my config looks like this:
sql_type: mysql
sql_server: "{{ default .Env.DB_HOST "localhost" }}"
sql_database: "{{ default .Env.DB_NAME "ejabberd" }}"
However, my thought was that since ejabberd config already has some flexibility (it evaluates Erlang terms), adding such a feature out of the box would be really valuable (as the would no longer be a necessity to use third party tools).
it evaluates Erlang terms
This was a dirty hack, because some developers are too lazy to update their configuration to support YAML. I consider this as a very bad practice.
i'll close this issue. Add ejabberd ability to get config from from environment is bad idea.
ejabberdctl script is already a wrapper which allows to get environment from ejabberdctl.cfg file to override some default, likely at lower level than ejabberd itself. All ejabberd setup is read from yaml configuration file.
For dynamic config stuff like db setup, use of generated config (like you did on dockerize) with use of include_config_file in ejabberd.yml is recommended way. Such simple config can be generated the way it's simpler for you, and can even be generated by a script reading environment variables. But such level of configurability is custom: It should be part of packaging, not of the product itself.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
i'll close this issue. Add ejabberd ability to get config from from environment is bad idea.
ejabberdctl script is already a wrapper which allows to get environment from ejabberdctl.cfg file to override some default, likely at lower level than ejabberd itself. All ejabberd setup is read from yaml configuration file.
For dynamic config stuff like db setup, use of generated config (like you did on dockerize) with use of include_config_file in ejabberd.yml is recommended way. Such simple config can be generated the way it's simpler for you, and can even be generated by a script reading environment variables. But such level of configurability is custom: It should be part of packaging, not of the product itself.