From 18594b60c4e1bcc2d5f41855c8ceed9af60b7b51 Mon Sep 17 00:00:00 2001 From: James Baker Date: Sat, 28 Dec 2024 14:41:33 +0000 Subject: [PATCH 1/5] Support configuring teslamate with unix domain sockets for Postgres --- config/runtime.exs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 97334c303b..a5ff0e1839 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -101,14 +101,22 @@ end config :teslamate, default_geofence: System.get_env("DEFAULT_GEOFENCE") +case System.get_env("DATABASE_SOCKET_DIR") do + nil -> + config :teslamate, TeslaMate.Repo, + username: Util.fetch_env!("DATABASE_USER", all: "postgres"), + password: Util.fetch_env!("DATABASE_PASS", all: "postgres"), + hostname: Util.fetch_env!("DATABASE_HOST", all: "localhost"), + port: System.get_env("DATABASE_PORT", "5432") + socket_dir -> + config :teslamate, TeslaMate.Repo, + socket_dir: socket_dir +end + config :teslamate, TeslaMate.Repo, - username: Util.fetch_env!("DATABASE_USER", all: "postgres"), - password: Util.fetch_env!("DATABASE_PASS", all: "postgres"), - database: Util.fetch_env!("DATABASE_NAME", dev: "teslamate_dev", test: "teslamate_test"), - hostname: Util.fetch_env!("DATABASE_HOST", all: "localhost"), - port: System.get_env("DATABASE_PORT", "5432"), pool_size: System.get_env("DATABASE_POOL_SIZE", "10") |> String.to_integer(), - timeout: System.get_env("DATABASE_TIMEOUT", "60000") |> String.to_integer() + timeout: System.get_env("DATABASE_TIMEOUT", "60000") |> String.to_integer(), + database: Util.fetch_env!("DATABASE_NAME", dev: "teslamate_dev", test: "teslamate_test") case System.get_env("DATABASE_SSL") do "true" -> From 9519934286c2a744dee1f062cd15a545f7d6ef85 Mon Sep 17 00:00:00 2001 From: James Baker Date: Sat, 28 Dec 2024 16:42:25 +0000 Subject: [PATCH 2/5] docs --- website/docs/configuration/environment_variables.md | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/configuration/environment_variables.md b/website/docs/configuration/environment_variables.md index 75765353e7..4f440d866c 100644 --- a/website/docs/configuration/environment_variables.md +++ b/website/docs/configuration/environment_variables.md @@ -12,6 +12,7 @@ TeslaMate accepts the following environment variables for runtime configuration: | **DATABASE_USER** | Username (**required**) | | | **DATABASE_PASS** | User password (**required**) | | | **DATABASE_NAME** | The database to connect to (**required**) | | +| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database. If this is provided, the database host, port need not be provided. | | **DATABASE_HOST** | Hostname of the database server (**required**) | | | **DATABASE_PORT** | Port of the database server | 5432 | | **DATABASE_POOL_SIZE** | Size of the database connection pool | 10 | From a8200c57991b207aceeda5fe15ee13ef84bcd063 Mon Sep 17 00:00:00 2001 From: James Baker Date: Sat, 28 Dec 2024 16:46:06 +0000 Subject: [PATCH 3/5] reorder --- website/docs/configuration/environment_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/configuration/environment_variables.md b/website/docs/configuration/environment_variables.md index 4f440d866c..31a0b39fe7 100644 --- a/website/docs/configuration/environment_variables.md +++ b/website/docs/configuration/environment_variables.md @@ -12,9 +12,9 @@ TeslaMate accepts the following environment variables for runtime configuration: | **DATABASE_USER** | Username (**required**) | | | **DATABASE_PASS** | User password (**required**) | | | **DATABASE_NAME** | The database to connect to (**required**) | | -| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database. If this is provided, the database host, port need not be provided. | | **DATABASE_HOST** | Hostname of the database server (**required**) | | | **DATABASE_PORT** | Port of the database server | 5432 | +| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database. If this is provided, the database host, port need not be provided. | | **DATABASE_POOL_SIZE** | Size of the database connection pool | 10 | | **DATABASE_TIMEOUT** | The time in milliseconds to wait for database query calls to finish | 60000 | | **DATABASE_SSL** | Set to `true` if SSL should be enabled or `noverify` if certificate verification should not be performed. | false | From b2fa0dae7a6daf8222d2359f6bd7ad18423ade63 Mon Sep 17 00:00:00 2001 From: James Baker Date: Sun, 29 Dec 2024 10:15:51 +0000 Subject: [PATCH 4/5] format, cleanup --- config/runtime.exs | 4 ++-- website/docs/configuration/environment_variables.md | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index a5ff0e1839..db8e1c0abc 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -108,9 +108,9 @@ case System.get_env("DATABASE_SOCKET_DIR") do password: Util.fetch_env!("DATABASE_PASS", all: "postgres"), hostname: Util.fetch_env!("DATABASE_HOST", all: "localhost"), port: System.get_env("DATABASE_PORT", "5432") + socket_dir -> - config :teslamate, TeslaMate.Repo, - socket_dir: socket_dir + config :teslamate, TeslaMate.Repo, socket_dir: socket_dir end config :teslamate, TeslaMate.Repo, diff --git a/website/docs/configuration/environment_variables.md b/website/docs/configuration/environment_variables.md index 31a0b39fe7..d4dd5df531 100644 --- a/website/docs/configuration/environment_variables.md +++ b/website/docs/configuration/environment_variables.md @@ -9,12 +9,12 @@ TeslaMate accepts the following environment variables for runtime configuration: | Variable Name | Description | Default Value | | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | | **ENCRYPTION_KEY** | A key used to encrypt the Tesla API tokens (**required**) | | -| **DATABASE_USER** | Username (**required**) | | -| **DATABASE_PASS** | User password (**required**) | | -| **DATABASE_NAME** | The database to connect to (**required**) | | -| **DATABASE_HOST** | Hostname of the database server (**required**) | | +| **DATABASE_USER** | Username | | +| **DATABASE_PASS** | User password | | +| **DATABASE_NAME** | The database to connect to | | +| **DATABASE_HOST** | Hostname of the database server | | | **DATABASE_PORT** | Port of the database server | 5432 | -| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database. If this is provided, the database host, port need not be provided. | +| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database if that connection mechanic is preferred. Provide one of DATABASE_SOCKET_DIR and DATABASE_(USER|PASS|HOST|PORT) | | | **DATABASE_POOL_SIZE** | Size of the database connection pool | 10 | | **DATABASE_TIMEOUT** | The time in milliseconds to wait for database query calls to finish | 60000 | | **DATABASE_SSL** | Set to `true` if SSL should be enabled or `noverify` if certificate verification should not be performed. | false | From 915451280d6df6506dfe8bf170f119fa039f3843 Mon Sep 17 00:00:00 2001 From: Jakob Lichterfeld Date: Tue, 7 Jan 2025 14:39:39 +0100 Subject: [PATCH 5/5] style: update environment variables documentation for DATABASE_SOCKET_DIR formatting --- website/docs/configuration/environment_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/configuration/environment_variables.md b/website/docs/configuration/environment_variables.md index d4dd5df531..7a21e97920 100644 --- a/website/docs/configuration/environment_variables.md +++ b/website/docs/configuration/environment_variables.md @@ -14,7 +14,7 @@ TeslaMate accepts the following environment variables for runtime configuration: | **DATABASE_NAME** | The database to connect to | | | **DATABASE_HOST** | Hostname of the database server | | | **DATABASE_PORT** | Port of the database server | 5432 | -| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database if that connection mechanic is preferred. Provide one of DATABASE_SOCKET_DIR and DATABASE_(USER|PASS|HOST|PORT) | | +| **DATABASE_SOCKET_DIR** | Local path containing unix socket for database if that connection mechanic is preferred. Provide one of DATABASE*SOCKET_DIR and DATABASE*(USER\|PASS\|HOST\|PORT) | | | **DATABASE_POOL_SIZE** | Size of the database connection pool | 10 | | **DATABASE_TIMEOUT** | The time in milliseconds to wait for database query calls to finish | 60000 | | **DATABASE_SSL** | Set to `true` if SSL should be enabled or `noverify` if certificate verification should not be performed. | false |