tox.ini: add runuwsgi target (#76419)
gitea/chrono/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-04-08 09:52:54 +02:00
parent 3ea108a3fc
commit 78708d456a
4 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,20 @@
[
{
"model": "auth.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$260000$O4TMYoLPoydHL1h2qE6Rcd$P9/OYa0mPxrgKtYufKWttmIFW+3SfeD8raupkhMbGwo=",
"last_login": "2023-04-08T01:21:28.681Z",
"is_superuser": true,
"username": "admin",
"first_name": "",
"last_name": "",
"email": "admin@example.com",
"is_staff": true,
"is_active": true,
"date_joined": "2023-04-08T01:21:23.751Z",
"groups": [],
"user_permissions": []
}
}
]

View File

@ -0,0 +1,46 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'chrono-runserver',
}
}
LOGGING = {
'version': 1,
'formatters': {
'stream': {
'format': '%(asctime)s %(levelname)s %(name)s: %(message)s',
'datefmt': '%Y-%m-%d %a %H:%M:%S',
},
},
'handlers': {
'stream': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'formatter': 'stream',
# fd3 is redirected to stdout in scripts/uwsgi.sh
# to prevent logs to go to uwsgi log file.
'filename': '/dev/fd/3',
},
},
'loggers': {
# even when debugging seeing SQL queries is too much, activate it
# explicitly using DEBUG_DB
'django.db': {
'level': 'INFO',
'handlers': [],
'propagate': True,
},
'django': {
'level': 'INFO',
'handlers': [],
'propagate': True,
},
'': {
'handlers': ['stream'],
'level': 'INFO',
},
},
}
MIDDLEWARE = list(MIDDLEWARE) + ['testapp.MaDbgMiddleware']

59
scripts/uwsgi.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/sh
set -e
exec 3>&1
function silent() {
LOG=`mktemp`
"$@" >$LOG 2>&1 || (tail $LOG; rm $LOG; exit 1)
rm $LOG
}
mkdir -p $TOX_WORK_DIR/spooler
createdb chrono-runserver >/dev/null 2>&1 || true
silent ./manage.py migrate
silent ./manage.py loaddata scripts/fixtures/admin.json
set -m
UWSGI_INI=$TOX_WORK_DIR/uwsgi.ini
cat >$UWSGI_INI <<EOF
[uwsgi]
plugin = python3
single-interpreter = true
pymodule-alias = testapp=scripts/testapp.py
module = chrono.wsgi:application
need-app = true
plugin = logfile
logger = file:$TOX_WORK_DIR/uwsgi.log
req-logger = file:/dev/fd/3
logformat-strftime = true
log-date = %%Y-%%m-%%d %%a %%H:%%M:%%S
log-format = %(ftime) INFO %(method) %(uri) (%(rsize) bytes, %(msecs) msecs, status %(status))
virtualenv = $TOX_ENV_DIR
auto-procname = true
procname-prefix-spaced = chrono
master = true
enable-threads = true
processes = 3
pidfile = $TOX_WORK_DIR/uwsgi.pid
http-socket = 127.0.0.1:9040
spooler-python-import = chrono.utils.spooler
spooler = $TOX_WORK_DIR/spooler
python-autoreload = 1
EOF
echo
silent uwsgi $UWSGI_INI &
echo - uwsgi.ini: $UWSGI_INI
echo - pidfile: $TOX_WORK_DIR/uwsgi.pid
echo - uwsgi.log: $TOX_WORK_DIR/uwsgi.log
echo - spooler: $TOX_WORK_DIR/spooler
echo
echo
echo " Open http://127.0.0.1:9040/ with login/password: admin / admin"
fg >/dev/null

20
tox.ini
View File

@ -63,3 +63,23 @@ deps =
commands =
./getlasso3.sh
pylint: ./pylint.sh chrono/ tests/
[testenv:runuwsgi]
usedevelop = True
passenv =
DISPLAY
XAUTHORITY
setenv =
DJANGO_SETTINGS_MODULE=chrono.settings
CHRONO_SETTINGS_FILE=scripts/runuwsgi_settings.py
deps =
django-filter>=2.4,<2.5
git+https://git.entrouvert.org/entrouvert/hobo.git@wip/76423-uwsgidecorators-corriger-le-pass
git+https://git.entrouvert.org/entrouvert/gadjo.git
git+https://git.entrouvert.org/entrouvert/publik-django-templatetags.git
psycopg2-binary
madbg
allowlist_externals=
bash
commands =
bash scripts/uwsgi.sh