lifecycle: run bootstrap tasks inline when using automated install
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
66f4a31b4c
commit
7beebe030d
|
@ -0,0 +1,13 @@
|
||||||
|
"""Run bootstrap tasks"""
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from authentik.root.celery import _get_startup_tasks
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): # pragma: no cover
|
||||||
|
"""Run bootstrap tasks to ensure certain objects are created"""
|
||||||
|
|
||||||
|
def handle(self, **options):
|
||||||
|
tasks = _get_startup_tasks()
|
||||||
|
for task in tasks:
|
||||||
|
task()
|
|
@ -1,6 +1,7 @@
|
||||||
"""authentik core celery"""
|
"""authentik core celery"""
|
||||||
import os
|
import os
|
||||||
from logging.config import dictConfig
|
from logging.config import dictConfig
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
from celery.signals import (
|
from celery.signals import (
|
||||||
|
@ -76,23 +77,28 @@ def task_error_hook(task_id, exception: Exception, traceback, *args, **kwargs):
|
||||||
Event.new(EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception)).save()
|
Event.new(EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception)).save()
|
||||||
|
|
||||||
|
|
||||||
@worker_ready.connect
|
def _get_startup_tasks() -> list[Callable]:
|
||||||
def worker_ready_hook(*args, **kwargs):
|
"""Get all tasks to be run on startup"""
|
||||||
"""Run certain tasks on worker start"""
|
|
||||||
from authentik.admin.tasks import clear_update_notifications
|
from authentik.admin.tasks import clear_update_notifications
|
||||||
from authentik.managed.tasks import managed_reconcile
|
from authentik.managed.tasks import managed_reconcile
|
||||||
from authentik.outposts.tasks import outpost_controller_all, outpost_local_connection
|
from authentik.outposts.tasks import outpost_controller_all, outpost_local_connection
|
||||||
from authentik.providers.proxy.tasks import proxy_set_defaults
|
from authentik.providers.proxy.tasks import proxy_set_defaults
|
||||||
|
|
||||||
tasks = [
|
return [
|
||||||
clear_update_notifications,
|
clear_update_notifications,
|
||||||
outpost_local_connection,
|
outpost_local_connection,
|
||||||
outpost_controller_all,
|
outpost_controller_all,
|
||||||
proxy_set_defaults,
|
proxy_set_defaults,
|
||||||
managed_reconcile,
|
managed_reconcile,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@worker_ready.connect
|
||||||
|
def worker_ready_hook(*args, **kwargs):
|
||||||
|
"""Run certain tasks on worker start"""
|
||||||
|
|
||||||
LOGGER.info("Dispatching startup tasks...")
|
LOGGER.info("Dispatching startup tasks...")
|
||||||
for task in tasks:
|
for task in _get_startup_tasks():
|
||||||
try:
|
try:
|
||||||
task.delay()
|
task.delay()
|
||||||
except ProgrammingError as exc:
|
except ProgrammingError as exc:
|
||||||
|
|
|
@ -38,6 +38,9 @@ if [[ "$1" == "server" ]]; then
|
||||||
wait_for_db
|
wait_for_db
|
||||||
echo "server" > $MODE_FILE
|
echo "server" > $MODE_FILE
|
||||||
python -m lifecycle.migrate
|
python -m lifecycle.migrate
|
||||||
|
if [[ ! -z "${AUTHENTIK_BOOTSTRAP_PASSWORD}" || ! -z "${AUTHENTIK_BOOTSTRAP_TOKEN}" ]]; then
|
||||||
|
python -m manage bootstrap_tasks
|
||||||
|
fi
|
||||||
/authentik-proxy
|
/authentik-proxy
|
||||||
elif [[ "$1" == "worker" ]]; then
|
elif [[ "$1" == "worker" ]]; then
|
||||||
wait_for_db
|
wait_for_db
|
||||||
|
|
Reference in New Issue