Updated config path to specify metadata storage path

This commit is contained in:
Kieran Eglin 2024-02-24 11:52:57 -08:00
parent e33a46bddc
commit 4644044bc6
No known key found for this signature in database
GPG key ID: 193984967FCF432D
6 changed files with 25 additions and 14 deletions

View file

@ -14,7 +14,9 @@ config :pinchflat,
yt_dlp_executable: System.find_executable("yt-dlp"), yt_dlp_executable: System.find_executable("yt-dlp"),
yt_dlp_runner: Pinchflat.MediaClient.Backends.YtDlp.CommandRunner, yt_dlp_runner: Pinchflat.MediaClient.Backends.YtDlp.CommandRunner,
media_directory: "/downloads", 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. # Setting AUTH_USERNAME and AUTH_PASSWORD implies you want to use basic auth.
# If either is unset, basic auth will not be used. # If either is unset, basic auth will not be used.
basic_auth_username: System.get_env("AUTH_USERNAME"), basic_auth_username: System.get_env("AUTH_USERNAME"),

View file

@ -2,7 +2,8 @@ import Config
config :pinchflat, config :pinchflat,
media_directory: Path.join([File.cwd!(), "tmp", "videos"]), 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 # Configure your database
config :pinchflat, Pinchflat.Repo, config :pinchflat, Pinchflat.Repo,

View file

@ -22,19 +22,24 @@ if System.get_env("PHX_SERVER") do
end end
if config_env() == :prod do if config_env() == :prod do
database_path = config_path =
System.get_env("DATABASE_PATH") || System.get_env("CONFIG_PATH") ||
raise """ raise """
environment variable DATABASE_PATH is missing. environment variable CONFIG_PATH is missing.
For example: /etc/pinchflat/pinchflat.db 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, config :pinchflat, Pinchflat.Repo,
database: database_path, database: db_path,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5") pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5")
# The secret key base is used to sign/encrypt cookies and other secrets. # The secret key base is used to sign/encrypt cookies and other secrets.
@ -63,8 +68,6 @@ if config_env() == :prod do
end end
end end
config :pinchflat, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
config :pinchflat, PinchflatWeb.Endpoint, config :pinchflat, PinchflatWeb.Endpoint,
http: [ http: [
# Enable IPv6 and bind on all interfaces. # Enable IPv6 and bind on all interfaces.

View file

@ -4,7 +4,8 @@ config :pinchflat,
# Specifying backend data here makes mocking and local testing SUPER easy # 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"]), yt_dlp_executable: Path.join([File.cwd!(), "/test/support/scripts/yt-dlp-mocks/repeater.sh"]),
media_directory: Path.join([System.tmp_dir!(), "test", "videos"]), 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 config :pinchflat, Oban, testing: :manual

View file

@ -99,8 +99,7 @@ RUN chown nobody /config /downloads
# set runner ENV # set runner ENV
ENV MIX_ENV="prod" ENV MIX_ENV="prod"
ENV DATABASE_PATH="/config/db/pinchflat.db" ENV CONFIG_PATH="/config"
ENV LOG_PATH="/config/logs/pinchflat.log"
ENV PORT=8945 ENV PORT=8945
ENV RUN_CONTEXT="selfhosted" ENV RUN_CONTEXT="selfhosted"

View file

@ -1,6 +1,9 @@
Mox.defmock(YtDlpRunnerMock, for: Pinchflat.MediaClient.Backends.BackendCommandRunner) Mox.defmock(YtDlpRunnerMock, for: Pinchflat.MediaClient.Backends.BackendCommandRunner)
Application.put_env(:pinchflat, :yt_dlp_runner, YtDlpRunnerMock) Application.put_env(:pinchflat, :yt_dlp_runner, YtDlpRunnerMock)
Mox.defmock(HTTPClientMock, for: Pinchflat.HTTP.HTTPBehaviour)
Application.put_env(:pinchflat, :http_client, HTTPClientMock)
ExUnit.start() ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual) Ecto.Adapters.SQL.Sandbox.mode(Pinchflat.Repo, :manual)
Faker.start() Faker.start()
@ -8,7 +11,9 @@ Faker.start()
ExUnit.after_suite(fn _ -> ExUnit.after_suite(fn _ ->
File.rm_rf!(Application.get_env(:pinchflat, :media_directory)) 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, :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, :media_directory))
File.mkdir_p!(Application.get_env(:pinchflat, :metadata_directory)) File.mkdir_p!(Application.get_env(:pinchflat, :metadata_directory))
File.mkdir_p!(Application.get_env(:pinchflat, :tmpfile_directory))
end) end)