Release 7 (devel -> main)

See merge request W13R/drinks-manager!3
This commit is contained in:
Julian Müller 2022-05-29 19:03:58 +00:00
commit 230fe267f8
8 changed files with 34 additions and 131 deletions

View file

@ -1,6 +1,6 @@
# Drinks Manager (season 2) # Drinks Manager (season 2)
Note: This piece of software is tailored to my own needs. Note: This software is tailored to my own needs.
I probably won't accept feature requests, and don't recommend you I probably won't accept feature requests, and don't recommend you
to use this software if this isn't exactly what you are looking for. to use this software if this isn't exactly what you are looking for.
@ -15,7 +15,7 @@ You have to bring your own PostgreSQL Database though.
## Setup, Installation, Updating and Dependencies ## Setup, Installation, Updating and Dependencies
You can find the latest releases [here](https://gitlab.com/W13R/drinks-manager/-/releases), but for Installation/Updating, you should consider using Git. You can find the latest releases [here](https://gitlab.com/W13R/drinks-manager/-/releases), but you should consider using Git to easily switch between versions.
For more information see [Setup](docs/Setup.md). For more information see [Setup](docs/Setup.md).

View file

@ -1,15 +1,15 @@
# environment variables # environment variables
export HTTP_PORT=80 # required by caddy, will be redirected to https export HTTP_PORT=80 # required by caddy, will be redirected to https
export HTTPS_PORT=443 # actual port for webinterface export HTTPS_PORT=443 # actual port for the webinterface
export DJANGO_PORT=8001 # caddy's http port (should be blocked by the firewall) export DJANGO_PORT=8001 # caddy's http port (should be blocked by the firewall)
export DJANGO_SESSION_COOKIE_AGE=600 # auto-logout, in seconds export DJANGO_SESSION_COOKIE_AGE=600 # auto-logout, in seconds
export SESSION_CLEAR_INTERVAL=120 # interval for automatic session clearing, in minutes export SESSION_CLEAR_INTERVAL=120 # interval for automatic session clearing, in minutes
export DJANGO_LANGUAGE_CODE="en" # the default and fallback language. Currently only de and en are supported. export DJANGO_LANGUAGE_CODE="en" # the default and fallback language, currently only de and en are supported.
export DJANGO_TIME_ZONE="CET" export DJANGO_TIME_ZONE="CET" # your timezone
export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specify it here export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specify it here
@ -18,10 +18,10 @@ export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specif
export DJANGO_ENABLE_PASSWORD_VALIDATION="true" export DJANGO_ENABLE_PASSWORD_VALIDATION="true"
# database connection (postgresql) # database connection (postgresql)
export PGDB_DB="" # The name of the databae export PGDB_DB="" # The name of the database
export PGDB_USER="" # The database user export PGDB_USER="" # The database user
export PGDB_PASSWORD='' # The password for the database user export PGDB_PASSWORD='' # The password for the database user
export PGDB_HOST="" # The hostname of your database (e.g. example.org or 127.0.0.1) export PGDB_HOST="127.0.0.1" # The hostname of your database
export PGDB_PORT=5432 # The port your database is listening on export PGDB_PORT=5432 # The port your database is listening on
# log files # log files

View file

@ -1,14 +1,14 @@
# Configuration # Configuration
## Main Configuration ## Main Configuration
`./config/config.sh` <u>`config/config.sh`</u>
There is no default configuration available, only a sample configuration with explanations. There is a sample configuration with explanations: [/config/config.sample.sh](/config/config.sample.sh)
## Caddy Server Configuration ## Caddy (Reverse Proxy & Static File Server)
`./config/Caddyfile` <u>[config/Caddyfile](/config/Caddyfile)</u>
The default configuration should work out of the box, don't edit this file unless you know what you're doing. The default configuration should work out of the box, don't edit this file unless you know what you're doing.

View file

@ -8,10 +8,11 @@ Before the actual setup, you have to satisfy the following dependencies:
### System ### System
- `pg_config` - `pg_config`
- Fedora/RHEL/Ubuntu: `libpq-dev` - Ubuntu: `libpq-dev`
- Fedora/RHEL: `libpq-devel`
- `Caddy` 2.4.3+ (HTTP Reverse Proxy & Static File Server) - `Caddy` 2.4.3+ (HTTP Reverse Proxy & Static File Server)
- `gcc`, `gettext` - `gcc`, `gettext`
- `Python` 3.9 with pip - `Python` 3.9+ with pip
- `Python` header files - `Python` header files
- Fedora/RHEL: `python3-devel` - Fedora/RHEL: `python3-devel`
- Ubuntu: `python3-dev` - Ubuntu: `python3-dev`
@ -19,7 +20,7 @@ Before the actual setup, you have to satisfy the following dependencies:
### Python Packages (pip) ### Python Packages (pip)
All required python packages are listed `in pip-dependencies.txt` All required python packages are listed in [pip-dependencies.txt](/pip-dependencies.txt)
You can install the required python packages with You can install the required python packages with
```bash ```bash
@ -31,9 +32,9 @@ You can install the required python packages with
You can get the latest version with git: You can get the latest version with git:
``` ```
git clone --branch release-x.x https://gitlab.com/W13R/drinks-manager.git git clone --branch release-x https://gitlab.com/W13R/drinks-manager.git
``` ```
(replace x.x with the latest version) (replace x with the latest version)
Alternatively, you can download the [latest release](https://gitlab.com/W13R/drinks-manager/-/releases) and extract the files to your prefered destination. Alternatively, you can download the [latest release](https://gitlab.com/W13R/drinks-manager/-/releases) and extract the files to your prefered destination.
@ -54,9 +55,9 @@ If you installed the application with git, you can run the following in the drin
``` ```
git fetch git fetch
git checkout x.x git checkout x
``` ```
(replace x.x with the new version) (replace x with the new version)
If you downloaded the application from the releases page, you can download the new release in the same manner, and overwrite the old files with the new ones. If you downloaded the application from the releases page, you can download the new release in the same manner, and overwrite the old files with the new ones.
@ -68,16 +69,20 @@ Further upgrading-instructions may be provided in the Release Notes on the Relea
## III. Database ## III. Database
This project is using PostgreSQL. You have to set up a database by yourself. This project is using PostgreSQL. You have to set up a database:
The database must have the schema `public` (exists on a new database). Make shure that you create a database user with the necessary privileges to write to and read from the database (SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, CREATE, CONNECT):
```sql ```sql
-- connected to target database create user drinksmanager password '<a safe password>';
grant SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES on all tables in schema public to <dbuser>; create database drinksmgr owner drinksmanager;
grant CREATE, CONNECT on database <dbname> to <dbuser>;
``` ```
You can configure your database connection in `config/config.sh`. After creating the user, you have to edit your `pg_hba.conf` (see https://www.postgresql.org/docs/current/auth-pg-hba-conf.html).
Add the following line:
```
host drinksmgr drinksmanager 127.0.0.1/32 md5
```
Now you can configure your database connection in `config/config.sh`.
## IV. HTTPS & TLS Certificates ## IV. HTTPS & TLS Certificates
@ -88,7 +93,7 @@ Filepaths:
- `config/tls/server.pem` for the certificate - `config/tls/server.pem` for the certificate
- `config/tls/server-key.pem` for the key - `config/tls/server-key.pem` for the key
You can set another filepath for those files in your caddy configuration at `config/Caddyfile`. You can set another filepath for those files in your caddy configuration at [config/Caddyfile](/config/Caddyfile).
## V. Configuration ## V. Configuration

View file

@ -2,5 +2,5 @@
export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt"
export STATIC_FILES="$(pwd)/static/" export STATIC_FILES="$(pwd)/static/"
export APP_VERSION="6" export APP_VERSION="7"
export PYTHONPATH="$(pwd)/packages/" export PYTHONPATH="$(pwd)/packages/"

View file

@ -1,18 +0,0 @@
def parse_config_from_file(filepath):
config = {}
with open(filepath, "r") as f:
lines = f.readlines()
for line in lines:
line = line.lstrip(" ").replace("\n", "")
if line.startswith("export "):
line = line.replace("export ", "").lstrip(" ")
varname = line[:line.find("=")]
varvalue = line[line.find("=")+1:]
if varvalue.startswith("'"): varvalue = varvalue.strip("'")
elif varvalue.startswith('"'): varvalue = varvalue.strip('"')
config[varname] = varvalue
return config

View file

@ -1,84 +0,0 @@
#!/usr/bin/env python3
import os, sys
from pathlib import Path
from psycopg2 import connect
from psycopg2 import Error
from lib import parse_config_from_file
USER_ID = 2
N_NEW_ORDER_ROWS = 1000000
COMMIT_AFTER = 50
AMOUNT_PER_ORDER = 1
PRODUCT_NAME = "Wasser"
DRINK_ID = 1
if __name__ == "__main__":
print("\nGetting config...")
config_file = Path(Path(os.path.dirname(__file__)).parent / "config" / "config.sh").absolute()
config = parse_config_from_file(config_file)
print(f"Commit will be done after every {COMMIT_AFTER} rows.")
x = input(f"Do you want to add {N_NEW_ORDER_ROWS} rows to the app_order table? (enter 'yes' to continue) ")
try:
if str(x) != "yes":
exit()
except ValueError:
exit()
try:
print("\nConnecting to database...")
conn = connect(
user = config["PGDB_USER"],
password = config["PGDB_PASSWORD"],
host = config["PGDB_HOST"],
port = config["PGDB_PORT"],
database = config["PGDB_DB"]
)
cur = conn.cursor()
for i in range(N_NEW_ORDER_ROWS):
cur.execute(f"""
insert into app_order (datetime, product_name, price_sum, content_litres, drink_id, user_id, amount)
values (
current_timestamp,
'{PRODUCT_NAME}',
10.00,
0.5,
{DRINK_ID},
{USER_ID},
{AMOUNT_PER_ORDER}
)
""")
if i % COMMIT_AFTER == 0 and not i == 0:
conn.commit()
print(f"\nAdded {i} rows")
conn.commit()
print(f"\nAdded {N_NEW_ORDER_ROWS} rows")
print("done with db setup.")
except (Error, Exception) as err:
print(f"An error occured while connecting to the database {config['PGDB_DB']} at {config['PGDB_HOST']}:\n{err}", file=sys.stderr)
finally:
cur.close()
conn.close()