e5e9d3dcd2c2a1019d990e76bfdaa9abb154e589
[akkoma] / lib / pleroma / config / release_runtime_provider.ex
1 defmodule Pleroma.Config.ReleaseRuntimeProvider do
2 @moduledoc """
3 Imports runtime config and `{env}.exported_from_db.secret.exs` for releases.
4 """
5 @behaviour Config.Provider
6
7 @impl true
8 def init(opts), do: opts
9
10 @impl true
11 def load(config, opts) do
12 with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
13
14 config_path =
15 opts[:config_path] || System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
16
17 with_runtime_config =
18 if File.exists?(config_path) do
19 runtime_config = Config.Reader.read!(config_path)
20
21 with_defaults
22 |> Config.Reader.merge(pleroma: [config_path: config_path])
23 |> Config.Reader.merge(runtime_config)
24 else
25 warning = [
26 IO.ANSI.red(),
27 IO.ANSI.bright(),
28 "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
29 IO.ANSI.reset()
30 ]
31
32 IO.puts(warning)
33 with_defaults
34 end
35
36 exported_config_path =
37 opts[:exported_config_path] ||
38 config_path
39 |> Path.dirname()
40 |> Path.join("#{Pleroma.Config.get(:env)}.exported_from_db.secret.exs")
41
42 with_exported =
43 if File.exists?(exported_config_path) do
44 exported_config = Config.Reader.read!(exported_config_path)
45 Config.Reader.merge(with_runtime_config, exported_config)
46 else
47 with_runtime_config
48 end
49
50 with_exported
51 end
52 end