Change everything for releases

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-02-01 14:57:58 +01:00
parent 1c3f607eb5
commit 496debd6f3
13 changed files with 143 additions and 52 deletions

34
lib/config_provider.ex Normal file
View File

@@ -0,0 +1,34 @@
defmodule Mobilizon.ConfigProvider do
@moduledoc """
Module to provide configuration from a custom file
"""
@behaviour Config.Provider
def init(path) when is_binary(path), do: path
def load(config, path) do
config_path = System.get_env("MOBILIZON_CONFIG_PATH") || path
cond do
File.exists?(config_path) ->
runtime_config = Config.Reader.read!(config_path)
Config.Reader.merge(config, runtime_config)
is_nil(System.get_env("MOBILIZON_DOCKER")) ->
warning = [
IO.ANSI.red(),
IO.ANSI.bright(),
"!!! #{config_path} not found! Please ensure it exists and that MOBILIZON_CONFIG_PATH is unset or points to an existing file",
IO.ANSI.reset()
]
IO.puts(warning)
config
true ->
IO.puts("No runtime config file found, but using environment variables for Docker")
config
end
end
end

View File

@@ -61,7 +61,7 @@ defmodule Mix.Tasks.Mobilizon.Instance do
paths =
[config_path, psql_path] = [
Keyword.get(options, :output, "config/prod.secret.exs"),
Keyword.get(options, :output, "config/runtime.exs"),
Keyword.get(options, :output_psql, "setup_db.psql")
]
@@ -146,7 +146,6 @@ defmodule Mix.Tasks.Mobilizon.Instance do
database_port: Keyword.get(options, :dbport, 5432),
database_username: dbuser,
database_password: dbpass,
version: Mobilizon.Mixfile.project() |> Keyword.get(:version),
instance_secret: instance_secret,
auth_secret: auth_secret,
listen_port: listen_port
@@ -160,22 +159,22 @@ defmodule Mix.Tasks.Mobilizon.Instance do
database_password: dbpass
)
shell_info("Writing config to #{config_path}.")
File.write(config_path, result_config)
shell_info("Writing #{psql_path}.")
File.write(psql_path, result_psql)
shell_info(
"\n" <>
"""
To get started:
1. Check the contents of the generated files.
2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)} && rm #{
escape_sh_path(psql_path)
}`.
"""
)
with :ok <- write_config(config_path, result_config),
:ok <- write_psql(psql_path, result_psql) do
shell_info(
"\n" <>
"""
To get started:
1. Check the contents of the generated files.
2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)} && rm #{
escape_sh_path(psql_path)
}`.
"""
)
else
{:error, err} -> exit(err)
_ -> exit(:unknown_error)
end
else
shell_error(
"The task would have overwritten the following files:\n" <>
@@ -184,4 +183,36 @@ defmodule Mix.Tasks.Mobilizon.Instance do
)
end
end
defp write_config(config_path, result_config) do
shell_info("Writing config to #{config_path}.")
case File.write(config_path, result_config) do
:ok ->
:ok
{:error, err} ->
shell_error(
"\nERROR: Unable to write config file to #{config_path}. Make sure you have permissions on the destination.\n"
)
{:error, err}
end
end
defp write_psql(psql_path, result_psql) do
shell_info("Writing #{psql_path}.")
case File.write(psql_path, result_psql) do
:ok ->
:ok
{:error, err} ->
shell_error(
"\nERROR: Unable to write psql file to #{psql_path}. Make sure you have permissions on the destination.\n"
)
{:error, err}
end
end
end

View File

@@ -11,6 +11,6 @@ defmodule Mobilizon.Storage.Repo do
Dynamically loads the repository url from the DATABASE_URL environment variable.
"""
def init(_, opts) do
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
{:ok, opts}
end
end