restructure for docker

This commit is contained in:
Ville Rantanen
2023-07-24 20:02:45 +03:00
parent 79780f0769
commit 58abf04d2c
45 changed files with 152 additions and 17 deletions

50
forum/docker-entrypoint.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
PYTHON=python3
SQLITE=sqlite3
export DB="/app/forum.db"
export SERVER=gunicorn
export PID="forum.pid"
export WORKERS=4
if [[ $( stat -c %u /app ) -ne $( id -u ) ]]; then
echo User id and /app folder owner do not match
printf 'UID: %s\nFolder: %s\n' $( id -u ) $( stat -c %u /app )
exit 1
fi
set -eu
. /opt/venv/bin/activate
if [[ -e "$DB" ]]; then
$SQLITE -header "$DB" "SELECT version,name,description,registration_enabled,login_required FROM config"
echo Database already exists
else
password=$($PYTHON tool.py password "$ADMINP")
time=$($PYTHON -c 'import time; print(time.time_ns())')
version=$($PYTHON tool.py version)
$SQLITE "$DB" -init schema.txt "insert into config (
version,
name,
description,
secret_key,
captcha_key,
registration_enabled,
login_required
)
values (
'$version',
'Forum',
'',
'$(head -c 30 /dev/urandom | base64)',
'$(head -c 30 /dev/urandom | base64)',
0,
1
)"
$SQLITE "$DB" "
insert into users (name, password, role, join_time)
values (lower('$ADMINU'), '$password', 2, $time)
"
fi
exec "$SERVER" -w $WORKERS 'main:app' --pid="$PID" -b 0.0.0.0:5000