Can't start a Elixir Phoenix as a mix release

前端 未结 1 1039
死守一世寂寞
死守一世寂寞 2020-12-21 09:23

I\'m not able to start my project from a mix release. But it works fine if I run mix phx.server

I\'m able to recreate this problem from an

相关标签:
1条回答
  • 2020-12-21 09:48

    First of all when it comes to configs, in new releases of distillery there is a new feature, called runtime configs, witch are favored instead of the ones at compile time, you can read more about them here.

    The basic idea behind this feature is that you can fetch environment variables when the server is run, when compared to the old config you had to provide all the configuration at build time, this comes really handy when working with containers and in general is more flexible.

    The steps for making runtime config are the following:

    1. Inside config folder create releases.exs file;
    2. Copy all the config you have provided in prod.exs or at least the parts you want to override;
    3. Use System.fetch_env!\1 to get the data from environment variables;

    You should remember that runtime config overrides the previous config, so if for example you provide prod.exs config at compile time, everything new in releases.exs will override the old config.

    An example of a part of such config is:

    config :tachocard_api, TachocardApi.Repo,
           username: System.fetch_env!("PGUSER"),
           password: System.fetch_env!("PGPASSWORD"),
           database: System.fetch_env!("PGDATABASE"),
           hostname: System.fetch_env!("PGHOST"),
           pool_size: 10
    

    Then in your deploy environment you set those environment variables to the values you need. System.fetch_env!/1 bang version is recommended, since it will throw an error if the environment variable is not set.

    0 讨论(0)
提交回复
热议问题