From 315cb0177d5f62f6affe5700cc2e2edaef05ace9 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 6 Jan 2023 13:42:36 +0100 Subject: [PATCH 1/5] Add postgres as database engine --- .env.sample | 13 +++++++++++++ docs/Options.md | 36 ++++++++++++++++++++++++++++++++++++ siteroot/settings/base.py | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/.env.sample b/.env.sample index 06256180..c92935b5 100644 --- a/.env.sample +++ b/.env.sample @@ -27,3 +27,16 @@ LD_AUTH_PROXY_LOGOUT_URL= # List of trusted origins from which to accept POST requests # See docs/Options.md for more details LD_CSRF_TRUSTED_ORIGINS= + +#Database engine can be sqlite (default) or postgres +LD_DB_ENGINE=sqlite +#Database name (default : linkding) +LD_DB_DATABASE= +#username/login for the database +LD_DB_LOGIN= +#password for the database +LD_DB_PASSWORD= +#Database Hostname (default : localhost) +LD_DB_HOST= +#Database port (if not set, the default database port is used) +LD_DB_PORT= diff --git a/docs/Options.md b/docs/Options.md index 0b9f53d9..533f05b3 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -108,3 +108,39 @@ Note that the setting **must** include the correct protocol (`https` or `http`), Multiple origins can be specified by separating them with a comma (`,`). This setting is adopted from the Django framework used by linkding, more information on the setting is available in the [Django documentation](https://docs.djangoproject.com/en/4.0/ref/settings/#std-setting-CSRF_TRUSTED_ORIGINS). + +### `LD_DB_ENGINE` + +Values: `'postgres'` or `'sqlite'` | Default = `'sqlite'` + +Database engine can be sqlite (default) or postgres + +### `LD_DB_DATABASE` + +Values: `String` | Default = `'linkding'` + +Database name (default : linkding) + +### `LD_DB_LOGIN` + +Values: `String` | Default = `'linkding'` + +username/login for the database + +### `LD_DB_PASSWORD` + +Values: `String` | Default = None + +Password for the database + +### `LD_DB_HOST` + +Values: `String` | Default = `'localhost'` + +Database Hostname (default : localhost) + +### `LD_DB_PORT` + +Values: `Integer` | Default = None + +Database port (if not set, the default database port is used) diff --git a/siteroot/settings/base.py b/siteroot/settings/base.py index 11b59e02..92d9d68f 100644 --- a/siteroot/settings/base.py +++ b/siteroot/settings/base.py @@ -79,15 +79,6 @@ WSGI_APPLICATION = 'siteroot.wsgi.application' -# Database -# https://docs.djangoproject.com/en/2.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'), - } -} # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators @@ -204,3 +195,32 @@ if trusted_origins: CSRF_TRUSTED_ORIGINS = trusted_origins.split(',') +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +LD_DB_ENGINE = os.getenv('LD_DB_ENGINE', 'sqlite') +LD_DB_HOST = os.getenv('LD_DB_HOST', 'localhost') +LD_DB_DATABASE = os.getenv('LD_DB_DATABASE', 'linkding') +LD_DB_LOGIN = os.getenv('LD_DB_LOGIN', 'linkding') +LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', '') +LD_DB_PORT = os.getenv('LD_DB_PORT', '') + +if LD_DB_ENGINE == "postgres" : + default_database = { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': LD_DB_DATABASE, + 'USER': LD_DB_LOGIN, + 'PASSWORD': LD_DB_PASSWORD, + 'HOST': LD_DB_HOST, + 'PORT': LD_DB_PORT, + } +else: + default_database = { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'data', 'db.sqlite3'), + } + +DATABASES = { + 'default': default_database +} + From fadcf556ef840f0f376dbcf4cff108c0700a660b Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 6 Jan 2023 21:13:22 +0100 Subject: [PATCH 2/5] Fix sissbruecker review --- .env.sample | 15 +++++++++------ docs/Options.md | 24 ++++++++++++++---------- requirements.prod.txt | 1 + requirements.txt | 1 + siteroot/settings/base.py | 8 ++++---- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.env.sample b/.env.sample index c92935b5..8e0c1c2a 100644 --- a/.env.sample +++ b/.env.sample @@ -28,15 +28,18 @@ LD_AUTH_PROXY_LOGOUT_URL= # See docs/Options.md for more details LD_CSRF_TRUSTED_ORIGINS= -#Database engine can be sqlite (default) or postgres +#Database engine use by linkding to store data. it can be sqlite (default) or postgres +#sqlite not use other LD_DB_* variables +#postgres use bellow variable LD_DB_DATABASE, LD_DB_LOGIN, LD_DB_PASSWORD, LD_DB_HOST, LD_DB_PORT LD_DB_ENGINE=sqlite + #Database name (default : linkding) LD_DB_DATABASE= -#username/login for the database -LD_DB_LOGIN= -#password for the database +#Username use to connect on the database server (default : linkding) +LD_DB_USER= +#Password use to connect on the database server LD_DB_PASSWORD= -#Database Hostname (default : localhost) +#The hostname where the database is hosted (default : localhost) LD_DB_HOST= -#Database port (if not set, the default database port is used) +#Port use to connect on the database server (if not set, the default database port is used) LD_DB_PORT= diff --git a/docs/Options.md b/docs/Options.md index 533f05b3..f5668e29 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -111,36 +111,40 @@ This setting is adopted from the Django framework used by linkding, more informa ### `LD_DB_ENGINE` -Values: `'postgres'` or `'sqlite'` | Default = `'sqlite'` +Values: `postgres` or `sqlite` | Default = `sqlite` -Database engine can be sqlite (default) or postgres +Database engine use by linkding to store data. it can be sqlite (default) or postgres + +sqlite not use other LD_DB_* variables + +postgres use bellow variable LD_DB_DATABASE, LD_DB_LOGIN, LD_DB_PASSWORD, LD_DB_HOST, LD_DB_PORT ### `LD_DB_DATABASE` -Values: `String` | Default = `'linkding'` +Values: `String` | Default = `linkding` Database name (default : linkding) -### `LD_DB_LOGIN` +### `LD_DB_USER` -Values: `String` | Default = `'linkding'` +Values: `String` | Default = `linkding` -username/login for the database +Username use to connect on the database server (default : linkding) ### `LD_DB_PASSWORD` Values: `String` | Default = None -Password for the database +Password use to connect on the database server ### `LD_DB_HOST` -Values: `String` | Default = `'localhost'` +Values: `String` | Default = `localhost` -Database Hostname (default : localhost) +The hostname or IP where the database is hosted (default : localhost) ### `LD_DB_PORT` Values: `Integer` | Default = None -Database port (if not set, the default database port is used) +Port use to connect on the database server (if not set, the default database port is used) diff --git a/requirements.prod.txt b/requirements.prod.txt index 6051a8c1..4b9c2eb7 100644 --- a/requirements.prod.txt +++ b/requirements.prod.txt @@ -22,3 +22,4 @@ typing-extensions==3.10.0.0 urllib3==1.26.11 uWSGI==2.0.20 waybackpy==3.0.6 +psycopg2==2.9.5 diff --git a/requirements.txt b/requirements.txt index 5c7c6602..95794b58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,3 +28,4 @@ sqlparse==0.4.2 typing-extensions==3.10.0.0 urllib3==1.26.11 waybackpy==3.0.6 +psycopg2==2.9.5 diff --git a/siteroot/settings/base.py b/siteroot/settings/base.py index 92d9d68f..40e3751c 100644 --- a/siteroot/settings/base.py +++ b/siteroot/settings/base.py @@ -201,15 +201,15 @@ LD_DB_ENGINE = os.getenv('LD_DB_ENGINE', 'sqlite') LD_DB_HOST = os.getenv('LD_DB_HOST', 'localhost') LD_DB_DATABASE = os.getenv('LD_DB_DATABASE', 'linkding') -LD_DB_LOGIN = os.getenv('LD_DB_LOGIN', 'linkding') -LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', '') -LD_DB_PORT = os.getenv('LD_DB_PORT', '') +LD_DB_USER = os.getenv('LD_DB_USER', 'linkding') +LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', None) +LD_DB_PORT = os.getenv('LD_DB_PORT', None) if LD_DB_ENGINE == "postgres" : default_database = { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': LD_DB_DATABASE, - 'USER': LD_DB_LOGIN, + 'USER': LD_DB_USER, 'PASSWORD': LD_DB_PASSWORD, 'HOST': LD_DB_HOST, 'PORT': LD_DB_PORT, From 9a995b97ba93e05b4b0239ce8c67f69e443ceee3 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 6 Jan 2023 21:23:31 +0100 Subject: [PATCH 3/5] replace psycopg2 by psycopg2-binary --- requirements.prod.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.prod.txt b/requirements.prod.txt index 4b9c2eb7..d5552da6 100644 --- a/requirements.prod.txt +++ b/requirements.prod.txt @@ -22,4 +22,4 @@ typing-extensions==3.10.0.0 urllib3==1.26.11 uWSGI==2.0.20 waybackpy==3.0.6 -psycopg2==2.9.5 +psycopg2-binary==2.9.5 diff --git a/requirements.txt b/requirements.txt index 95794b58..fad092c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,4 +28,4 @@ sqlparse==0.4.2 typing-extensions==3.10.0.0 urllib3==1.26.11 waybackpy==3.0.6 -psycopg2==2.9.5 +psycopg2-binary==2.9.5 From dddf07d6035138a964ef913e7bfc31d8bf8a7069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sat, 7 Jan 2023 12:33:38 +0100 Subject: [PATCH 4/5] Fix Docker setup --- Dockerfile | 4 ++-- requirements.prod.txt | 2 +- requirements.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc2569bb..1d490548 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN npm run build FROM python:3.10.6-slim-buster AS python-base -RUN apt-get update && apt-get -y install build-essential +RUN apt-get update && apt-get -y install build-essential libpq-dev WORKDIR /etc/linkding @@ -34,7 +34,7 @@ RUN mkdir /opt/venv && \ FROM python:3.10.6-slim-buster as final -RUN apt-get update && apt-get -y install mime-support +RUN apt-get update && apt-get -y install mime-support libpq-dev WORKDIR /etc/linkding # copy prod dependencies COPY --from=prod-deps /opt/venv /opt/venv diff --git a/requirements.prod.txt b/requirements.prod.txt index d5552da6..a26f19b3 100644 --- a/requirements.prod.txt +++ b/requirements.prod.txt @@ -12,6 +12,7 @@ django-widget-tweaks==1.4.12 django4-background-tasks==1.2.7 djangorestframework==3.13.1 idna==3.3 +psycopg2==2.9.5 python-dateutil==2.8.2 pytz==2022.2.1 requests==2.28.1 @@ -22,4 +23,3 @@ typing-extensions==3.10.0.0 urllib3==1.26.11 uWSGI==2.0.20 waybackpy==3.0.6 -psycopg2-binary==2.9.5 diff --git a/requirements.txt b/requirements.txt index fad092c2..490b3b7b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ django4-background-tasks==1.2.7 djangorestframework==3.13.1 idna==3.3 libsass==0.21.0 +psycopg2-binary==2.9.5 python-dateutil==2.8.2 pytz==2022.2.1 rcssmin==1.1.0 @@ -28,4 +29,3 @@ sqlparse==0.4.2 typing-extensions==3.10.0.0 urllib3==1.26.11 waybackpy==3.0.6 -psycopg2-binary==2.9.5 From c30b162314d8cb55704165a5a6333d85e51703e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sat, 7 Jan 2023 12:36:18 +0100 Subject: [PATCH 5/5] Polish docs --- .env.sample | 20 +++++++++++--------- README.md | 6 +++++- docs/Options.md | 21 +++++++++++---------- siteroot/settings/base.py | 4 +--- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.env.sample b/.env.sample index 8e0c1c2a..d13947c7 100644 --- a/.env.sample +++ b/.env.sample @@ -28,18 +28,20 @@ LD_AUTH_PROXY_LOGOUT_URL= # See docs/Options.md for more details LD_CSRF_TRUSTED_ORIGINS= -#Database engine use by linkding to store data. it can be sqlite (default) or postgres -#sqlite not use other LD_DB_* variables -#postgres use bellow variable LD_DB_DATABASE, LD_DB_LOGIN, LD_DB_PASSWORD, LD_DB_HOST, LD_DB_PORT -LD_DB_ENGINE=sqlite +# Database settings +# These are currently only required for configuring PostreSQL. +# By default, linkding uses SQLite for which you don't need to configure anything. -#Database name (default : linkding) +# Database engine, can be sqlite (default) or postgres +LD_DB_ENGINE= +# Database name (default: linkding) LD_DB_DATABASE= -#Username use to connect on the database server (default : linkding) +# Username to connect to the database server (default: linkding) LD_DB_USER= -#Password use to connect on the database server +# Password to connect to the database server LD_DB_PASSWORD= -#The hostname where the database is hosted (default : localhost) +# The hostname where the database is hosted (default: localhost) LD_DB_HOST= -#Port use to connect on the database server (if not set, the default database port is used) +# Port use to connect to the database server +# Should use the default port if not set LD_DB_PORT= diff --git a/README.md b/README.md index 28a9236f..0f34b574 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,11 @@ The name comes from: ## Installation -linkding is designed to be run with container solutions like [Docker](https://docs.docker.com/get-started/). The Docker image is compatible with ARM platforms, so it can be run on a Raspberry Pi. +linkding is designed to be run with container solutions like [Docker](https://docs.docker.com/get-started/). +The Docker image is compatible with ARM platforms, so it can be run on a Raspberry Pi. + +By default, linkding uses SQLite as a database. +Alternatively linkding supports PostgreSQL, see the [database options](docs/Options.md#LD_DB_ENGINE) for more information. ### Using Docker diff --git a/docs/Options.md b/docs/Options.md index f5668e29..008cb30b 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -113,38 +113,39 @@ This setting is adopted from the Django framework used by linkding, more informa Values: `postgres` or `sqlite` | Default = `sqlite` -Database engine use by linkding to store data. it can be sqlite (default) or postgres - -sqlite not use other LD_DB_* variables - -postgres use bellow variable LD_DB_DATABASE, LD_DB_LOGIN, LD_DB_PASSWORD, LD_DB_HOST, LD_DB_PORT +Database engine used by linkding to store data. +Currently, linkding supports SQLite and PostgreSQL. +By default, linkding uses SQLite, for which you don't need to configure anything. +All the other database variables below are only required for configured PostgresSQL. ### `LD_DB_DATABASE` Values: `String` | Default = `linkding` -Database name (default : linkding) +The name of the database. ### `LD_DB_USER` Values: `String` | Default = `linkding` -Username use to connect on the database server (default : linkding) +The name of the user to connect to the database server. ### `LD_DB_PASSWORD` Values: `String` | Default = None -Password use to connect on the database server +The password of the user to connect to the database server. +The password must be configured when using a database other than SQLite, there is no default value. ### `LD_DB_HOST` Values: `String` | Default = `localhost` -The hostname or IP where the database is hosted (default : localhost) +The hostname or IP of the database server. ### `LD_DB_PORT` Values: `Integer` | Default = None -Port use to connect on the database server (if not set, the default database port is used) +The port of the database server. +Should use the default port if left empty, for example `5432` for PostgresSQL. diff --git a/siteroot/settings/base.py b/siteroot/settings/base.py index 40e3751c..e5cf817a 100644 --- a/siteroot/settings/base.py +++ b/siteroot/settings/base.py @@ -79,7 +79,6 @@ WSGI_APPLICATION = 'siteroot.wsgi.application' - # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators @@ -205,7 +204,7 @@ LD_DB_PASSWORD = os.getenv('LD_DB_PASSWORD', None) LD_DB_PORT = os.getenv('LD_DB_PORT', None) -if LD_DB_ENGINE == "postgres" : +if LD_DB_ENGINE == 'postgres': default_database = { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': LD_DB_DATABASE, @@ -223,4 +222,3 @@ DATABASES = { 'default': default_database } -