beyond-all-reason / teiserver

Middleware server for online gaming
https://www.beyondallreason.info/
MIT License
47 stars 47 forks source link

Move config to runtime #278

Closed geekingfrog closed 2 months ago

geekingfrog commented 3 months ago

Remove config/prod.secret.exs and instead use config.runtime.exs. This address https://github.com/beyond-all-reason/teiserver/issues/236 Now, most of the server can be configured through this file that is loaded at runtime. Changing it and restarting the server is enough. Sensitive values like secrets are loaded through the environment. I provided an example for an EnvironmentFile.

I split up the changes in many small commits so hopefully it should be easy to review and make sure I haven't missed anything. I based my work on the provided example production secret file.

There are still some things like cipher config in config/prod.exs that are baked into the compiled bytecode since they are unlikely to change.

@p2004a This is difficult to test that locally since I have no idea what the actual production secret file looks like. Feel free to amend this new runtime file as needed.

In the original issue there was some mention of reloading the config without having to restart the server. That seems considerably more involved so I skipped this bit. Theses changes should already make the deploys easier.

geekingfrog commented 3 months ago

I've added some commits so that the configuration now matches what you linked me. You shouldn't need to template the configuration anymore and should be able to achieve the same result purely through environment variables that you can pass to the docker container now.

AdamChlupacek commented 3 months ago

@geekingfrog Do you think it would be possible to make ports, on which the server listens (tcp, tls, tachyon), configurable as well? I am currently running into an issue where I have to change the values in config locally since I have some other services running on these ports. It would be nice to be able to change the ports via config/environment and not having to have to change code every time.

geekingfrog commented 3 months ago

@AdamChlupacek Done in f7be2eec3a78d6fe506bdd458b7a6daa777f8958 (also rebased https://github.com/beyond-all-reason/teiserver/pull/281)

geekingfrog commented 2 months ago

I've pushed a few more changes. Thanks for the pointer to the discord (and smtp) guide. I managed to build the application and run it locally with the updated example env file and everything seems to work, I even got the email setup working.

MIX_ENV=prod mix release --overwrite
set -o allexport; source documents/prod_files/example-environment-file; set +o allexport
./_build/prod/rel/teiserver/bin/teiserver start