aboutsummaryrefslogtreecommitdiff
path: root/lib/mix/tasks
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-01-18 16:55:33 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-01-18 17:14:50 +0300
commitefb8ef5abee1a8defa2bfba40ad1065db4c09ddf (patch)
tree92b14ebc386203dfc57864a1c2ec5375c03b20f1 /lib/mix/tasks
parente69986169095796f2845c4f859234d96f91bf9ff (diff)
downloadpleroma-efb8ef5abee1a8defa2bfba40ad1065db4c09ddf.tar.gz
releases support
Diffstat (limited to 'lib/mix/tasks')
-rw-r--r--lib/mix/tasks/pleroma/config.ex49
1 files changed, 33 insertions, 16 deletions
diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex
index 148d18141..715b72dbe 100644
--- a/lib/mix/tasks/pleroma/config.ex
+++ b/lib/mix/tasks/pleroma/config.ex
@@ -10,8 +10,6 @@ defmodule Mix.Tasks.Pleroma.Config do
alias Pleroma.ConfigDB
alias Pleroma.Repo
- require Logger
-
@shortdoc "Manages the location of the config"
@moduledoc File.read!("docs/administration/CLI_tasks/config.md")
@@ -32,10 +30,10 @@ defmodule Mix.Tasks.Pleroma.Config do
with {:active?, true} <-
{:active?, Pleroma.Config.get([:configurable_from_database])},
- env_path when is_binary(env_path) <- opts[:env],
- config_path <- "config/#{env_path}.exported_from_db.secret.exs",
+ env when is_binary(env) <- opts[:env] || "prod",
+ config_path <- config_path(env),
{:ok, file} <- File.open(config_path, [:write, :utf8]) do
- IO.write(file, "use Mix.Config\r\n")
+ IO.write(file, config_header())
ConfigDB
|> Repo.all()
@@ -45,31 +43,50 @@ defmodule Mix.Tasks.Pleroma.Config do
System.cmd("mix", ["format", config_path])
else
{:active?, false} ->
- Mix.shell().info(
- "migration is not allowed by config. You can change this behavior in instance settings."
+ shell_info(
+ "Migration is not allowed by config. You can change this behavior in instance settings."
)
error ->
- Mix.shell().info("error occuried while opening file. #{inspect(error)}")
+ shell_info("Error occuried while opening file. #{inspect(error)}")
end
end
+ defp config_path(env) do
+ path =
+ if Pleroma.Config.get(:release) do
+ :config_path
+ |> Pleroma.Config.get()
+ |> Path.dirname()
+ else
+ "config"
+ end
+
+ Path.join(path, "#{env}.exported_from_db.secret.exs")
+ end
+
@spec migrate_to_db(Path.t() | nil) :: any()
def migrate_to_db(file_path \\ nil) do
if Pleroma.Config.get([:configurable_from_database]) do
- # TODO: add support for releases
- config_file = file_path || "config/#{Pleroma.Config.get(:env)}.secret.exs"
+ user_config_file =
+ if Pleroma.Config.get(:release),
+ do: Pleroma.Config.get(:config_path),
+ else: "config/#{Pleroma.Config.get(:env)}.secret.exs"
+
+ config_file = file_path || user_config_file
do_migrate_to_db(config_file)
else
- Mix.shell().info(
- "migration is not allowed by config. You can change this behavior in instance settings."
+ shell_info(
+ "Migration is not allowed by config. You can change this behavior in instance settings."
)
end
end
if Code.ensure_loaded?(Config.Reader) do
+ defp config_header, do: "import Config\r\n\r\n"
defp read_file(config_file), do: Config.Reader.read_imports!(config_file)
else
+ defp config_header, do: "use Mix.Config\r\n\r\n"
defp read_file(config_file), do: Mix.Config.eval!(config_file)
end
@@ -81,7 +98,7 @@ defmodule Mix.Tasks.Pleroma.Config do
|> Keyword.keys()
|> Enum.each(&create(&1, custom_config[&1]))
else
- Logger.warn("to migrate settings, you must define custom settings in #{config_file}")
+ shell_info("To migrate settings, you must define custom settings in #{config_file}.")
end
end
@@ -94,10 +111,10 @@ defmodule Mix.Tasks.Pleroma.Config do
key = inspect(key)
{:ok, _} = ConfigDB.update_or_create(%{group: inspect(group), key: key, value: value})
- Mix.shell().info("settings for key #{key} migrated.")
+ shell_info("Settings for key #{key} migrated.")
end)
- Mix.shell().info("settings for group :#{group} migrated.")
+ shell_info("Settings for group :#{group} migrated.")
end
defp write_to_file_with_deletion(config, file, with_deletion) do
@@ -110,7 +127,7 @@ defmodule Mix.Tasks.Pleroma.Config do
if with_deletion do
{:ok, _} = Repo.delete(config)
- Mix.shell().info("#{config.key} deleted from DB.")
+ shell_info("#{config.key} deleted from DB.")
end
end
end