pleroma-docker/docker-config.exs

72 lines
2.2 KiB
Elixir
Raw Normal View History

2018-04-08 14:15:44 +00:00
use Mix.Config
2018-04-08 15:04:06 +00:00
defmodule Docker do
2018-08-21 01:19:42 +00:00
def env(shortname, verbatim \\ false) do
# Get var
name = ((if verbatim, do: "", else: "pleroma_") <> Atom.to_string(shortname)) |> String.upcase()
raw_var = System.get_env(name)
2018-04-08 15:04:06 +00:00
2018-08-21 01:19:42 +00:00
if raw_var == nil do
raise "Could not find #{name} in environment. Please define it and try again."
2018-04-08 15:04:06 +00:00
end
2018-08-21 01:19:42 +00:00
# Match type and cast if needed
if String.contains?(raw_var, ":") do
var_parts = String.split(raw_var, ":", parts: 2)
type = Enum.at(var_parts, 0)
var = Enum.at(var_parts, 1)
func = case type do
"int" -> fn(x) -> Integer.parse(x) |> elem(0) end
"bool" -> fn(x) -> x == "true" end
"string" -> fn(x) -> x end
_ -> if verbatim do
fn(x) -> x end
else
raise "Unknown type #{type} used in variable #{raw_var}."
end
end
func.(var)
else
raw_var
end
2018-04-08 15:04:06 +00:00
end
2018-04-08 14:15:44 +00:00
end
2018-06-07 10:37:17 +00:00
config :logger, level: String.to_atom(Docker.env(:loglevel) || "info")
2018-04-08 14:15:44 +00:00
config :pleroma, Pleroma.Web.Endpoint,
url: [
2018-04-08 15:04:06 +00:00
host: Docker.env(:url),
scheme: Docker.env(:scheme),
2018-06-03 23:48:35 +00:00
port: Docker.env(:port)
2018-04-08 14:15:44 +00:00
],
2018-04-08 15:04:06 +00:00
secret_key_base: Docker.env(:secret_key_base)
2018-04-08 14:15:44 +00:00
2018-04-08 22:33:52 +00:00
config :pleroma, Pleroma.Upload,
uploads: Docker.env(:uploads_path)
config :pleroma, :chat,
enabled: Docker.env(:chat_enabled)
2018-04-08 14:15:44 +00:00
config :pleroma, :instance,
2018-04-08 22:33:52 +00:00
name: Docker.env(:name),
email: Docker.env(:admin_email),
limit: Docker.env(:max_notice_chars),
2018-04-08 22:33:52 +00:00
registrations_open: Docker.env(:registrations_open)
2018-04-08 14:15:44 +00:00
config :pleroma, :media_proxy,
2018-04-08 22:33:52 +00:00
enabled: Docker.env(:media_proxy_enabled),
redirect_on_failure: Docker.env(:media_proxy_redirect_on_failure),
base_url: Docker.env(:media_proxy_url)
2018-04-08 14:15:44 +00:00
config :pleroma, Pleroma.Repo,
2018-04-08 22:33:52 +00:00
adapter: Ecto.Adapters.Postgres,
username: Docker.env(:postgres_user, true),
password: Docker.env(:postgres_password, true),
database: Docker.env(:postgres_db, true),
hostname: Docker.env(:postgres_ip, true),
pool_size: Docker.env(:db_pool_size)