From 4644044bc6c0ae5e8894f54b5235b8484b71bb6d Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Sat, 24 Feb 2024 11:52:57 -0800 Subject: [PATCH] Updated config path to specify metadata storage path --- config/config.exs | 4 +++- config/dev.exs | 3 ++- config/runtime.exs | 21 ++++++++++++--------- config/test.exs | 3 ++- selfhosted.Dockerfile | 3 +-- test/test_helper.exs | 5 +++++ 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/config/config.exs b/config/config.exs index a8957b3..2551df6 100644 --- a/config/config.exs +++ b/config/config.exs @@ -14,7 +14,9 @@ config :pinchflat, yt_dlp_executable: System.find_executable("yt-dlp"), yt_dlp_runner: Pinchflat.MediaClient.Backends.YtDlp.CommandRunner, media_directory: "/downloads", - metadata_directory: Path.join([System.tmp_dir!(), "pinchflat", "metadata"]), + # The user may or may not store metadata for their needs, but the app will always store its copy + metadata_directory: "/config/metadata", + tmpfile_directory: Path.join([System.tmp_dir!(), "pinchflat", "data"]), # Setting AUTH_USERNAME and AUTH_PASSWORD implies you want to use basic auth. # If either is unset, basic auth will not be used. basic_auth_username: System.get_env("AUTH_USERNAME"), diff --git a/config/dev.exs b/config/dev.exs index 2dda9d9..2e1baae 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -2,7 +2,8 @@ import Config config :pinchflat, media_directory: Path.join([File.cwd!(), "tmp", "videos"]), - metadata_directory: Path.join([File.cwd!(), "tmp", "metadata"]) + metadata_directory: Path.join([File.cwd!(), "tmp", "metadata"]), + tmpfile_directory: Path.join([File.cwd!(), "tmp", "tmpfiles"]) # Configure your database config :pinchflat, Pinchflat.Repo, diff --git a/config/runtime.exs b/config/runtime.exs index 4086fc0..8fb0033 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -22,19 +22,24 @@ if System.get_env("PHX_SERVER") do end if config_env() == :prod do - database_path = - System.get_env("DATABASE_PATH") || + config_path = + System.get_env("CONFIG_PATH") || raise """ - environment variable DATABASE_PATH is missing. - For example: /etc/pinchflat/pinchflat.db + environment variable CONFIG_PATH is missing. + For example: /etc/pinchflat/config """ - log_path = System.get_env("LOG_PATH", "log/pinchflat.log") + db_path = System.get_env("DATABASE_PATH", Path.join([config_path, "db", "pinchflat.db"])) + log_path = System.get_env("LOG_PATH", Path.join([config_path, "logs", "pinchflat.log"])) + metadata_path = System.get_env("METADATA_PATH", Path.join([config_path, "metadata"])) - config :pinchflat, yt_dlp_executable: System.find_executable("yt-dlp") + config :pinchflat, + yt_dlp_executable: System.find_executable("yt-dlp"), + metadata_directory: metadata_path, + dns_cluster_query: System.get_env("DNS_CLUSTER_QUERY") config :pinchflat, Pinchflat.Repo, - database: database_path, + database: db_path, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5") # The secret key base is used to sign/encrypt cookies and other secrets. @@ -63,8 +68,6 @@ if config_env() == :prod do end end - config :pinchflat, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") - config :pinchflat, PinchflatWeb.Endpoint, http: [ # Enable IPv6 and bind on all interfaces. diff --git a/config/test.exs b/config/test.exs index e51fb69..005d72f 100644 --- a/config/test.exs +++ b/config/test.exs @@ -4,7 +4,8 @@ config :pinchflat, # Specifying backend data here makes mocking and local testing SUPER easy yt_dlp_executable: Path.join([File.cwd!(), "/test/support/scripts/yt-dlp-mocks/repeater.sh"]), media_directory: Path.join([System.tmp_dir!(), "test", "videos"]), - metadata_directory: Path.join([System.tmp_dir!(), "test", "metadata"]) + metadata_directory: Path.join([System.tmp_dir!(), "test", "metadata"]), + tmpfile_directory: Path.join([System.tmp_dir!(), "test", "tmpfiles"]) config :pinchflat, Oban, testing: :manual diff --git a/selfhosted.Dockerfile b/selfhosted.Dockerfile index ded2309..79ffaff 100644 --- a/selfhosted.Dockerfile +++ b/selfhosted.Dockerfile @@ -99,8 +99,7 @@ RUN chown nobody /config /downloads # set runner ENV ENV MIX_ENV="prod" -ENV DATABASE_PATH="/config/db/pinchflat.db" -ENV LOG_PATH="/config/logs/pinchflat.log" +ENV CONFIG_PATH="/config" ENV PORT=8945 ENV RUN_CONTEXT="selfhosted" diff --git a/test/test_helper.exs b/test/test_helper.exs index b0bcf23..00db531 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,6 +1,9 @@ Mox.defmock(YtDlpRunnerMock, for: Pinchflat.MediaClient.Backends.BackendCommandRunner) Application.put_env(:pinchflat, :yt_dlp_runner, YtDlpRunnerMock) +Mox.defmock(HTTPClientMock, for: Pinchflat.HTTP.HTTPBehaviour) +Application.put_env(:pinchflat, :http_client, HTTPClientMock) + ExUnit.start() Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual) Faker.start() @@ -8,7 +11,9 @@ Faker.start() ExUnit.after_suite(fn _ -> File.rm_rf!(Application.get_env(:pinchflat, :media_directory)) File.rm_rf!(Application.get_env(:pinchflat, :metadata_directory)) + File.rm_rf!(Application.get_env(:pinchflat, :tmpfile_directory)) File.mkdir_p!(Application.get_env(:pinchflat, :media_directory)) File.mkdir_p!(Application.get_env(:pinchflat, :metadata_directory)) + File.mkdir_p!(Application.get_env(:pinchflat, :tmpfile_directory)) end)