Skip to content
Snippets Groups Projects
Unverified Commit 6c8ae24a authored by Uku Taht's avatar Uku Taht Committed by GitHub
Browse files

New config (#595)

* Use Config instead of Mix.Config

* Use new config/runtime.exs to reduce duplication
parent e786af64
Branches
No related tags found
No related merge requests found
BASE_URL=http://localhost:8000
DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/plausible_dev
CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_dev
SECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcg
DISABLE_SUBSCRIPTION=false
ENVIRONMENT=dev
MAILER_ADAPTER=Bamboo.LocalAdapter
LOG_LEVEL=debug
use Mix.Config import Config
base_url =
System.get_env("BASE_URL", "http://localhost:8000")
|> URI.parse()
config :plausible, config :plausible,
admin_user: System.get_env("ADMIN_USER_NAME", "admin"), ecto_repos: [Plausible.Repo, Plausible.ClickhouseRepo]
admin_email: System.get_env("ADMIN_USER_EMAIL", "admin@plausible.local"),
mailer_email: System.get_env("MAILER_EMAIL", "hello@plausible.local"),
admin_pwd: System.get_env("ADMIN_USER_PWD", "!@d3in"),
ecto_repos: [Plausible.Repo, Plausible.ClickhouseRepo],
environment: System.get_env("ENVIRONMENT", "dev"),
admin_emails: [System.get_env("ADMIN_EMAIL")]
disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false"))
config :plausible, :selfhost,
disable_authentication: disable_auth,
disable_subscription: String.to_existing_atom(System.get_env("DISABLE_SUBSCRIPTION", "false")),
disable_registration:
if(disable_auth,
do: true,
else: String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false"))
)
# Configures the endpoint
config :plausible, PlausibleWeb.Endpoint,
url: [
host: base_url.host,
scheme: base_url.scheme,
port: base_url.port
],
http: [
port: String.to_integer(System.get_env("PORT", "8000"))
],
secret_key_base:
System.get_env(
"SECRET_KEY_BASE",
"/NJrhNtbyCVAsTyvtk1ZYCwfm981Vpo/0XrVwjJvemDaKC/vsvBRevLwsc6u8RCg"
),
render_errors: [
view: PlausibleWeb.ErrorView,
accepts: ~w(html json)
],
pubsub_server: Plausible.PubSub
config :sentry, config :plausible, PlausibleWeb.Endpoint, pubsub_server: Plausible.PubSub
dsn: System.get_env("SENTRY_DSN"),
included_environments: [:prod, :staging],
environment_name: String.to_atom(System.get_env("ENVIRONMENT", "dev")),
enable_source_code_context: true,
root_source_code_path: File.cwd!(),
tags: %{app_version: System.get_env("APP_VERSION", "0.0.1")},
context_lines: 5
# Configures Elixir's Logger # Configures Elixir's Logger
config :logger, :console, config :logger, :console,
...@@ -77,142 +28,20 @@ config :plausible, ...@@ -77,142 +28,20 @@ config :plausible,
session_timeout: 1000 * 60 * 30, session_timeout: 1000 * 60 * 30,
session_length_minutes: 30 session_length_minutes: 30
config :plausible, :paddle, config :plausible, :paddle, vendor_id: "49430"
vendor_id: "49430",
vendor_auth_code: System.get_env("PADDLE_VENDOR_AUTH_CODE")
config :plausible, Plausible.ClickhouseRepo, config :plausible, Plausible.ClickhouseRepo, loggers: [Ecto.LogEntry]
loggers: [Ecto.LogEntry],
url:
System.get_env(
"CLICKHOUSE_DATABASE_URL",
"http://127.0.0.1:8123/plausible_dev"
)
config :plausible, config :plausible, Plausible.Repo,
Plausible.Repo,
timeout: 300_000, timeout: 300_000,
connect_timeout: 300_000, connect_timeout: 300_000,
handshake_timeout: 300_000, handshake_timeout: 300_000,
url: adapter: Ecto.Adapters.Postgres
System.get_env(
"DATABASE_URL",
"postgres://postgres:postgres@127.0.0.1:5432/plausible_dev?currentSchema=default"
)
cron_enabled = String.to_existing_atom(System.get_env("CRON_ENABLED", "false"))
base_cron = [
# Daily at midnight
{"0 0 * * *", Plausible.Workers.RotateSalts}
]
extra_cron = [
# hourly
{"0 * * * *", Plausible.Workers.SendSiteSetupEmails},
# hourly
{"0 * * * *", Plausible.Workers.ScheduleEmailReports},
# Daily at midnight
{"0 0 * * *", Plausible.Workers.FetchTweets},
# Daily at midday
{"0 12 * * *", Plausible.Workers.SendTrialNotifications},
# Daily at midday
{"0 12 * * *", Plausible.Workers.SendCheckStatsEmails},
# Every 10 minutes
{"*/10 * * * *", Plausible.Workers.ProvisionSslCertificates},
# Every 15 minutes
{"*/15 * * * *", Plausible.Workers.SpikeNotifier},
# Every day at midnight
{"0 0 * * *", Plausible.Workers.CleanEmailVerificationCodes}
]
base_queues = [rotate_salts: 1]
extra_queues = [
provision_ssl_certificates: 1,
fetch_tweets: 1,
check_stats_emails: 1,
site_setup_emails: 1,
trial_notification_emails: 1,
schedule_email_reports: 1,
send_email_reports: 1,
spike_notifications: 1,
clean_email_verification_codes: 1
]
config :plausible, Oban,
repo: Plausible.Repo,
queues: if(cron_enabled, do: base_queues ++ extra_queues, else: base_queues),
crontab: if(cron_enabled, do: base_cron ++ extra_cron, else: base_cron)
config :plausible, :google,
client_id: System.get_env("GOOGLE_CLIENT_ID"),
client_secret: System.get_env("GOOGLE_CLIENT_SECRET")
config :plausible, :slack, webhook: System.get_env("SLACK_WEBHOOK")
mailer_adapter = System.get_env("MAILER_ADAPTER", "Bamboo.LocalAdapter")
case mailer_adapter do
"Bamboo.PostmarkAdapter" ->
config :plausible, Plausible.Mailer,
adapter: :"Elixir.#{mailer_adapter}",
request_options: [recv_timeout: 10_000],
api_key: System.get_env("POSTMARK_API_KEY")
"Bamboo.SMTPAdapter" ->
config :plausible, Plausible.Mailer,
adapter: :"Elixir.#{mailer_adapter}",
server: System.fetch_env!("SMTP_HOST_ADDR"),
hostname: System.get_env("HOST", "localhost"),
port: System.fetch_env!("SMTP_HOST_PORT"),
username: System.fetch_env!("SMTP_USER_NAME"),
password: System.fetch_env!("SMTP_USER_PWD"),
tls: :if_available,
allowed_tls_versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"],
ssl: System.get_env("SMTP_HOST_SSL_ENABLED") || false,
retries: System.get_env("SMTP_RETRIES") || 2,
no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true,
auth: :if_available
"Bamboo.LocalAdapter" ->
config :plausible, Plausible.Mailer, adapter: :"Elixir.#{mailer_adapter}"
_ ->
raise "Unknown mailer_adapter; expected SMTPAdapter or PostmarkAdapter"
end
config :plausible, :twitter,
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET"),
token: System.get_env("TWITTER_ACCESS_TOKEN"),
token_secret: System.get_env("TWITTER_ACCESS_TOKEN_SECRET")
config :plausible, :custom_domain_server,
user: System.get_env("CUSTOM_DOMAIN_SERVER_USER"),
password: System.get_env("CUSTOM_DOMAIN_SERVER_PASSWORD"),
ip: System.get_env("CUSTOM_DOMAIN_SERVER_IP")
config :plausible, PlausibleWeb.Firewall,
blocklist: System.get_env("IP_BLOCKLIST", "") |> String.split(",") |> Enum.map(&String.trim/1)
config :plausible, :hcaptcha,
sitekey: System.get_env("HCAPTCHA_SITEKEY"),
secret: System.get_env("HCAPTCHA_SECRET")
config :plausible, :user_agent_cache, config :plausible, :user_agent_cache,
limit: 1000, limit: 1000,
stats: false stats: false
config :geolix,
databases: [
%{
id: :country,
adapter: Geolix.Adapter.MMDB2,
source: "priv/geolix/GeoLite2-Country.mmdb"
}
]
config :kaffy, config :kaffy,
otp_app: :plausible, otp_app: :plausible,
ecto_repo: Plausible.Repo, ecto_repo: Plausible.Repo,
...@@ -231,6 +60,4 @@ config :kaffy, ...@@ -231,6 +60,4 @@ config :kaffy,
] ]
] ]
# Import environment specific config. This must remain at the bottom import_config "#{config_env()}.exs"
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
use Mix.Config import Config
config :plausible, PlausibleWeb.Endpoint, config :plausible, PlausibleWeb.Endpoint,
server: true, server: true,
...@@ -16,6 +16,10 @@ config :plausible, PlausibleWeb.Endpoint, ...@@ -16,6 +16,10 @@ config :plausible, PlausibleWeb.Endpoint,
] ]
config :plausible, PlausibleWeb.Endpoint, config :plausible, PlausibleWeb.Endpoint,
render_errors: [
view: PlausibleWeb.ErrorView,
accepts: ~w(html json)
],
live_reload: [ live_reload: [
patterns: [ patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
...@@ -30,9 +34,3 @@ config :plausible, PlausibleWeb.Endpoint, ...@@ -30,9 +34,3 @@ config :plausible, PlausibleWeb.Endpoint,
config :logger, :console, format: "[$level] $message\n" config :logger, :console, format: "[$level] $message\n"
config :phoenix, :stacktrace_depth, 20 config :phoenix, :stacktrace_depth, 20
config :phoenix, :plug_init_mode, :runtime config :phoenix, :plug_init_mode, :runtime
if File.exists?("config/dev.secret.exs") do
import_config "dev.secret.exs"
end
config :logger, level: :debug
use Mix.Config import Config
# For the actual-production deployments we will use releases, config :plausible, PlausibleWeb.Endpoint,
# i.e., "releases.exs" is the _actual_ production config cache_static_manifest: "priv/static/cache_manifest.json",
# see "releases.exs" check_origin: false,
server: true,
import_config "releases.exs" code_reloader: false
import Config import Config
### Mandatory params Start if config_env() == :dev do
# it is highly recommended to change this parameters in production systems Envy.auto_load()
# params are made optional to facilitate smooth release end
port = System.get_env("PORT") || 8000 port = System.get_env("PORT") || 8000
...@@ -78,17 +78,9 @@ config :plausible, :selfhost, ...@@ -78,17 +78,9 @@ config :plausible, :selfhost,
config :plausible, PlausibleWeb.Endpoint, config :plausible, PlausibleWeb.Endpoint,
url: [host: base_url.host, scheme: base_url.scheme, port: base_url.port], url: [host: base_url.host, scheme: base_url.scheme, port: base_url.port],
http: [port: port], http: [port: port],
secret_key_base: secret_key_base, secret_key_base: secret_key_base
cache_static_manifest: "priv/static/cache_manifest.json",
check_origin: false,
load_from_system_env: true,
server: true,
code_reloader: false
config :plausible, config :plausible, Plausible.Repo, url: db_url
Plausible.Repo,
url: db_url,
adapter: Ecto.Adapters.Postgres
config :sentry, config :sentry,
dsn: sentry_dsn, dsn: sentry_dsn,
...@@ -130,6 +122,9 @@ case mailer_adapter do ...@@ -130,6 +122,9 @@ case mailer_adapter do
retries: System.get_env("SMTP_RETRIES") || 2, retries: System.get_env("SMTP_RETRIES") || 2,
no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true no_mx_lookups: System.get_env("SMTP_MX_LOOKUPS_ENABLED") || true
"Bamboo.LocalAdapter" ->
config :plausible, Plausible.Mailer, adapter: :"Elixir.#{mailer_adapter}"
_ -> _ ->
raise "Unknown mailer_adapter; expected SMTPAdapter or PostmarkAdapter" raise "Unknown mailer_adapter; expected SMTPAdapter or PostmarkAdapter"
end end
...@@ -167,7 +162,9 @@ extra_cron = [ ...@@ -167,7 +162,9 @@ extra_cron = [
# Every 10 minutes # Every 10 minutes
{"*/10 * * * *", Plausible.Workers.ProvisionSslCertificates}, {"*/10 * * * *", Plausible.Workers.ProvisionSslCertificates},
# Every 15 minutes # Every 15 minutes
{"*/15 * * * *", Plausible.Workers.SpikeNotifier} {"*/15 * * * *", Plausible.Workers.SpikeNotifier},
# Every day at midnight
{"0 0 * * *", Plausible.Workers.CleanEmailVerificationCodes}
] ]
base_queues = [rotate_salts: 1] base_queues = [rotate_salts: 1]
...@@ -180,7 +177,8 @@ extra_queues = [ ...@@ -180,7 +177,8 @@ extra_queues = [
trial_notification_emails: 1, trial_notification_emails: 1,
schedule_email_reports: 1, schedule_email_reports: 1,
send_email_reports: 1, send_email_reports: 1,
spike_notifications: 1 spike_notifications: 1,
clean_email_verification_codes: 1
] ]
config :plausible, Oban, config :plausible, Oban,
......
use Mix.Config import Config
# We don't run a server during test. If one is required, # We don't run a server during test. If one is required,
# you can enable the server option below. # you can enable the server option below.
......
...@@ -101,7 +101,8 @@ defmodule Plausible.MixProject do ...@@ -101,7 +101,8 @@ defmodule Plausible.MixProject do
{:cachex, "~> 3.3"}, {:cachex, "~> 3.3"},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false}, {:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:kaffy, "~> 0.9.0"} {:kaffy, "~> 0.9.0"},
{:envy, "~> 1.1.1"}
] ]
end end
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
"ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"}, "ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"}, "elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
"envy": {:hex, :envy, "1.1.1", "0bc9bd654dec24fcdf203f7c5aa1b8f30620f12cfb28c589d5e9c38fe1b07475", [:mix], [], "hexpm", "7061eb1a47415fd757145d8dec10dc0b1e48344960265cb108f194c4252c3a89"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"}, "eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"},
"ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"}, "ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment