Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

New config (#595)

Uku Taht6c8ae24adcc2
diff --git a/.env.dev b/.env.dev
new file mode 100644
index 0000000000..48ab1190f3
--- /dev/null
+++ b/.env.dev
@@ -0,0 +1,8 @@
+BASE_URL=http://localhost:8000
+DATABASE_URL=postgres://postgres:[email protected]: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
diff --git a/config/config.exs b/config/config.exs
index 425c06f7b2..e2f9a9fb03 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,58 +1,9 @@
-use Mix.Config
-
-base_url =
- System.get_env("BASE_URL", "http://localhost:8000")
- |> URI.parse()
+import Config
config :plausible,
- admin_user: System.get_env("ADMIN_USER_NAME", "admin"),
- admin_email: System.get_env("ADMIN_USER_EMAIL", "[email protected]"),
- mailer_email: System.get_env("MAILER_EMAIL", "[email protected]"),
- 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"))
- )
+ ecto_repos: [Plausible.Repo, Plausible.ClickhouseRepo]
-# 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,
- 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
+config :plausible, PlausibleWeb.Endpoint, pubsub_server: Plausible.PubSub
# Configures Elixir's Logger
config :logger, :console,
@@ -77,142 +28,20 @@ config :plausible,
session_timeout: 1000 * 60 * 30,
session_length_minutes: 30
-config :plausible, :paddle,
- vendor_id: "49430",
- vendor_auth_code: System.get_env("PADDLE_VENDOR_AUTH_CODE")
-
-config :plausible, Plausible.ClickhouseRepo,
- loggers: [Ecto.LogEntry],
- url:
- System.get_env(
- "CLICKHOUSE_DATABASE_URL",
- "http://127.0.0.1:8123/plausible_dev"
- )
-
-config :plausible,
- Plausible.Repo,
- timeout: 300_000,
- connect_timeout: 300_000,
- handshake_timeout: 300_000,
- url:
- System.get_env(
- "DATABASE_URL",
- "postgres://postgres:[email protected]: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, :paddle, vendor_id: "49430"
-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, Plausible.ClickhouseRepo, loggers: [Ecto.LogEntry]
-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, Plausible.Repo,
+ timeout: 300_000,
+ connect_timeout: 300_000,
+ handshake_timeout: 300_000,
+ adapter: Ecto.Adapters.Postgres
config :plausible, :user_agent_cache,
limit: 1000,
stats: false
-config :geolix,
- databases: [
- %{
- id: :country,
- adapter: Geolix.Adapter.MMDB2,
- source: "priv/geolix/GeoLite2-Country.mmdb"
- }
- ]
-
config :kaffy,
otp_app: :plausible,
ecto_repo: Plausible.Repo,
@@ -231,6 +60,4 @@ config :kaffy,
]
]
-# Import environment specific config. This must remain at the bottom
-# of this file so it overrides the configuration defined above.
-import_config "#{Mix.env()}.exs"
+import_config "#{config_env()}.exs"
diff --git a/config/dev.exs b/config/dev.exs
index 20e8660572..89cf9908c5 100644
--- a/config/dev.exs
+++ b/config/dev.exs
@@ -1,4 +1,4 @@
-use Mix.Config
+import Config
config :plausible, PlausibleWeb.Endpoint,
server: true,
@@ -16,6 +16,10 @@ config :plausible, PlausibleWeb.Endpoint,
]
config :plausible, PlausibleWeb.Endpoint,
+ render_errors: [
+ view: PlausibleWeb.ErrorView,
+ accepts: ~w(html json)
+ ],
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
@@ -30,9 +34,3 @@ config :plausible, PlausibleWeb.Endpoint,
config :logger, :console, format: "[$level] $message\n"
config :phoenix, :stacktrace_depth, 20
config :phoenix, :plug_init_mode, :runtime
-
-if File.exists?("config/dev.secret.exs") do
- import_config "dev.secret.exs"
-end
-
-config :logger, level: :debug
diff --git a/config/prod.exs b/config/prod.exs
index 3ccd578d1e..56559d1532 100644
--- a/config/prod.exs
+++ b/config/prod.exs
@@ -1,7 +1,7 @@
-use Mix.Config
+import Config
-# For the actual-production deployments we will use releases,
-# i.e., "releases.exs" is the _actual_ production config
-# see "releases.exs"
-
-import_config "releases.exs"
+config :plausible, PlausibleWeb.Endpoint,
+ cache_static_manifest: "priv/static/cache_manifest.json",
+ check_origin: false,
+ server: true,
+ code_reloader: false
diff --git a/config/releases.exs b/config/runtime.exs
similarity index 93%
rename from config/releases.exs
rename to config/runtime.exs
index 57529db38b..7b8345d914 100644
--- a/config/releases.exs
+++ b/config/runtime.exs
@@ -1,8 +1,8 @@
import Config
-### Mandatory params Start
-# it is highly recommended to change this parameters in production systems
-# params are made optional to facilitate smooth release
+if config_env() == :dev do
+ Envy.auto_load()
+end
port = System.get_env("PORT") || 8000
@@ -78,17 +78,9 @@ config :plausible, :selfhost,
config :plausible, PlausibleWeb.Endpoint,
url: [host: base_url.host, scheme: base_url.scheme, port: base_url.port],
http: [port: port],
- 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
+ secret_key_base: secret_key_base
-config :plausible,
- Plausible.Repo,
- url: db_url,
- adapter: Ecto.Adapters.Postgres
+config :plausible, Plausible.Repo, url: db_url
config :sentry,
dsn: sentry_dsn,
@@ -130,6 +122,9 @@ case mailer_adapter do
retries: System.get_env("SMTP_RETRIES") || 2,
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"
end
@@ -167,7 +162,9 @@ extra_cron = [
# Every 10 minutes
{"*/10 * * * *", Plausible.Workers.ProvisionSslCertificates},
# 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]
@@ -180,7 +177,8 @@ extra_queues = [
trial_notification_emails: 1,
schedule_email_reports: 1,
send_email_reports: 1,
- spike_notifications: 1
+ spike_notifications: 1,
+ clean_email_verification_codes: 1
]
config :plausible, Oban,
diff --git a/config/test.exs b/config/test.exs
index 8408277c7f..9db5172ae4 100644
--- a/config/test.exs
+++ b/config/test.exs
@@ -1,4 +1,4 @@
-use Mix.Config
+import Config
# We don't run a server during test. If one is required,
# you can enable the server option below.
diff --git a/mix.exs b/mix.exs
index 4ecbd2543b..143a1497da 100644
--- a/mix.exs
+++ b/mix.exs
@@ -101,7 +101,8 @@ defmodule Plausible.MixProject do
{:cachex, "~> 3.3"},
{:dialyxir, "~> 1.0", 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
diff --git a/mix.lock b/mix.lock
index ef6cffdccb..8e7d889286 100644
--- a/mix.lock
+++ b/mix.lock
@@ -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"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"},
"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"},
"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"},