feat: PostgresProvider - Add POSTGRES_URL override.

This commit is contained in:
Tarek Al-Qarqaz 2024-03-30 19:38:23 +00:00
parent 79fb1fb299
commit ae5a1a9af2
3 changed files with 41 additions and 26 deletions

View File

@ -33,6 +33,7 @@
| POSTGRES_SERVER | postgres | Postgres database server address |
| POSTGRES_PORT | 5432 | Postgres database port |
| POSTGRES_DB | mealie | Postgres database name |
| POSTGRES_URL | None | Postgres URL override. Must be used with DB_ENGINE: postgres |
### Email

View File

@ -5,40 +5,41 @@ PostgreSQL might be considered if you need to support many concurrent users. In
**For Environment Variable Configuration, see** [Backend Configuration](./backend-config.md)
```yaml
---
version: "3.7"
services:
mealie:
image: ghcr.io/mealie-recipes/mealie:v1.3.2 # (3)
image: ghcr.io/mealie-recipes/mealie:1.3.2 # (3)
container_name: mealie
restart: always
ports:
- "9925:9000" # (1)
deploy:
resources:
limits:
memory: 1000M # (2)
depends_on:
- postgres
volumes:
- mealie-data:/app/data/
- /etc/timezone:/etc/timezone:ro
environment:
# Set Backend ENV Variables Here
- ALLOW_SIGNUP=true
- PUID=1000
- PGID=1000
- TZ=America/Anchorage
- MAX_WORKERS=1
- WEB_CONCURRENCY=1
- BASE_URL=https://mealie.yourdomain.com
ALLOW_SIGNUP: true
PUID: 1000
PGID: 1000
MAX_WORKERS: 1
WEB_CONCURRENCY: 1
BASE_URL: http://localhost # (4)
# Database Settings
- DB_ENGINE=postgres
- POSTGRES_USER=mealie
- POSTGRES_PASSWORD=mealie
- POSTGRES_SERVER=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=mealie
restart: always
DB_ENGINE: postgres
POSTGRES_URL: 'postgres://mealie:mealie@postgres/mealie' # (5)
# The following variables are supported if you do not specify POSTGRES_URL
# POSTGRES_USER: mealie
# POSTGRES_PASSWORD: mealie
# POSTGRES_SERVER: postgres
# POSTGRES_PORT: 5432
# POSTGRES_DB: mealie
depends_on:
postgres:
condition: service_healthy
postgres:
container_name: postgres
image: postgres:15
@ -48,12 +49,15 @@ services:
environment:
POSTGRES_PASSWORD: mealie
POSTGRES_USER: mealie
healthcheck:
test: ["CMD", "pg_isready"]
interval: 30s
timeout: 20s
retries: 3
volumes:
mealie-data:
driver: local
mealie-pgdata:
driver: local
```
<!-- Updating This? Be Sure to also update the SQLite Annotations -->
@ -61,3 +65,8 @@ volumes:
1. To access the mealie interface you only need to expose port 9000 on the mealie container. Here we expose port 9925 on the host, but feel free to change this to any port you like.
2. Setting an explicit memory limit is recommended. Python can pre-allocate larger amounts of memory than is necessary if you have a machine with a lot of RAM. This can cause the container to idle at a high memory usage. Setting a memory limit will improve idle performance.
3. You should double check this value isn't out of date when setting up for the first time; check the README and use the value from the "latest release" badge at the top - the format should be `vX.Y.Z`. Whilst a 'latest' tag is available, the Mealie team advises specifying a specific version tag and consciously updating to newer versions when you have time to read the release notes and ensure you follow any manual actions required (which should be rare).
4. You should replace this with your domain eg. mealie.yourdomain.com
5. When set, this variable will override POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_SERVER,
POSTGRES_PORT, and POSTGRES_DB. It must be used in conjunction with DB_ENGINE: postgres.
The format is 'postgresql://POSTGRES_USER:POSTGRES_PASSWORD@POSTGRES_SERVER:POSTGRES_PORT/POSTGRES_DB'
You may pass in a UNIX socket with the following format: postgresql://POSTGRES_USER:POSTGRES_PASSWORD@/POSTGRES_DB?host=/run/postgresql', where the path at the end is the parent directory of the socket.

View File

@ -39,22 +39,27 @@ class PostgresProvider(AbstractDBProvider, BaseSettings):
POSTGRES_SERVER: str = "postgres"
POSTGRES_PORT: str = "5432"
POSTGRES_DB: str = "mealie"
POSTGRES_URL: str = ""
model_config = SettingsConfigDict(arbitrary_types_allowed=True, extra="allow")
@property
def db_url(self) -> str:
host = f"{self.POSTGRES_SERVER}:{self.POSTGRES_PORT}"
return str(
if self.POSTGRES_URL:
return self.POSTGRES_URL
self.db_url: str = str(
PostgresDsn.build(
scheme="postgresql",
username=self.POSTGRES_USER,
password=urlparse.quote_plus(self.POSTGRES_PASSWORD),
host=host,
host=f"{self.POSTGRES_SERVER}:{self.POSTGRES_PORT}",
path=f"{self.POSTGRES_DB or ''}",
)
)
return self.POSTGRES_URL
@property
def db_url_public(self) -> str:
user = self.POSTGRES_USER