V4.x Docker Refactoring and Docs

This commit is contained in:
Ariel Rin
2023-08-14 03:05:44 +00:00
parent 4aff4006e3
commit 4305ae7995
14 changed files with 297 additions and 108 deletions

33
docker/conf/celery.py Normal file
View File

@@ -0,0 +1,33 @@
import os
from celery import Celery
from celery.app import trace
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myauth.settings.local')
from django.conf import settings # noqa
app = Celery('myauth')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
app.config_from_object('django.conf:settings')
# setup priorities ( 0 Highest, 9 Lowest )
app.conf.broker_transport_options = {
'priority_steps': list(range(10)), # setup que to have 10 steps
'queue_order_strategy': 'priority', # setup que to use prio sorting
}
app.conf.task_default_priority = 5 # anything called with the task.delay() will be given normal priority (5)
app.conf.worker_prefetch_multiplier = 1 # only prefetch single tasks at a time on the workers so that prio tasks happen
app.conf.ONCE = {
'backend': 'allianceauth.services.tasks.DjangoBackend',
'settings': {}
}
# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
# Remove result from default log message on task success
trace.LOG_SUCCESS = "Task %(name)s[%(id)s] succeeded in %(runtime)ss"

27
docker/conf/memory_check.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
max_mem=$1
cur_mem=$(</sys/fs/cgroup/memory.current)
health_file="/tmp/health.stat"
if [ -f "$health_file" ]; then
echo "$health_file exists."
else
echo "$health_file does not exist. Creating"
echo 0 > "$health_file"
fi
health=$(<$health_file)
echo "Testing Mem: $cur_mem / $max_mem"
if [[ max_mem -gt cur_mem ]]
then
echo 0 > "$health_file"
echo "All Ok"
exit 0
else
new_val=$((1+$health))
echo "Un-healthy! Check #$new_val"
echo $new_val > "$health_file"
if (($new_val > 3)); then
echo "Starting a restart of this the container..."
kill -SIGTERM 1
fi
exit 1
fi

View File

@@ -11,7 +11,7 @@ server {
}
location / {
proxy_pass http://allianceauth:8000;
proxy_pass http://allianceauth_gunicorn:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

View File

@@ -1,56 +0,0 @@
[supervisord]
nodaemon=true
user=allianceauth
[program:beat]
command=/opt/venv/bin/celery -A myauth beat
directory=/home/allianceauth/myauth
user=allianceauth
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
startsecs=10
priority=998
stdout_events_enabled=true
stderr_events_enabled=true
[program:worker]
command=/opt/venv/bin/celery -A myauth worker -l INFO --max-tasks-per-child=250
directory=/home/allianceauth/myauth
user=allianceauth
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
numprocs=1
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
stdout_events_enabled=true
stderr_events_enabled=true
[program:gunicorn]
user=allianceauth
directory=/home/allianceauth/myauth
command=/opt/venv/bin/gunicorn myauth.wsgi --bind :8000 --workers=3 --timeout 120
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
stdout_events_enabled=true
stderr_events_enabled=true
autostart=true
autorestart=true
stopsignal=INT
[group:myauth]
programs=beat,worker,gunicorn
priority=999
[supervisorctl]

11
docker/conf/urls.py Normal file
View File

@@ -0,0 +1,11 @@
from allianceauth import urls
from django.urls import include, path
urlpatterns = [
path('', include(urls)),
]
handler500 = 'allianceauth.views.Generic500Redirect'
handler404 = 'allianceauth.views.Generic404Redirect'
handler403 = 'allianceauth.views.Generic403Redirect'
handler400 = 'allianceauth.views.Generic400Redirect'