Skip to content

root: move database calls from ready() to dedicated startup signal#9081

Merged
BeryJu merged 16 commits intomainfrom
root/better-startup-logic
Apr 2, 2024
Merged

root: move database calls from ready() to dedicated startup signal#9081
BeryJu merged 16 commits intomainfrom
root/better-startup-logic

Conversation

@BeryJu
Copy link
Member

@BeryJu BeryJu commented Mar 30, 2024

Details

This started out as an attempt to get rid of the Django 5.x deprecation message saying to not do database calls in the AppConfig's ready() call.

The PR introduces a couple new signals for startup logic, and the signals are triggered by either the dev_server command or gunicorn's post_worker_init hook. To not change too much of the startup logic, the ManagedAppConfig connects to those new signals to call its startup reconcilers.

There's also an optimisation in this PR; for gunicorn the signal is only triggered for the first worker as all required things such as importing modules is not handled by this signal, and thus it is enough to know that the startup reconcilers were triggered once per gunicorn process.

There's also a nice side-effect of speeding up the startup as startup tasks are no longer run when migrating


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

@BeryJu BeryJu requested a review from a team as a code owner March 30, 2024 14:51
@netlify
Copy link

netlify bot commented Mar 30, 2024

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 7c692bb
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/660bf155a0e0f10008430e61
😎 Deploy Preview https://deploy-preview-9081--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Mar 30, 2024

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 7c692bb
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/660bf155f7aa9d0008222f12
😎 Deploy Preview https://deploy-preview-9081--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@BeryJu BeryJu requested a review from a team as a code owner March 30, 2024 15:14
@BeryJu BeryJu force-pushed the root/better-startup-logic branch from fd5af82 to a7b203d Compare March 30, 2024 15:19
@BeryJu BeryJu requested a review from a team as a code owner March 30, 2024 15:37
@github-actions
Copy link
Contributor

github-actions bot commented Mar 30, 2024

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-ghcr.io/goauthentik/dev-server:gh-7c692bb652cb03e73df0377a845c8f26e8bb92e4
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

For arm64, use these values:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-ghcr.io/goauthentik/dev-server:gh-7c692bb652cb03e73df0377a845c8f26e8bb92e4-arm64
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-ghcr.io/goauthentik/dev-server:gh-7c692bb652cb03e73df0377a845c8f26e8bb92e4

For arm64, use these values:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-ghcr.io/goauthentik/dev-server:gh-7c692bb652cb03e73df0377a845c8f26e8bb92e4-arm64

Afterwards, run the upgrade commands from the latest release notes.

@BeryJu BeryJu force-pushed the root/better-startup-logic branch from c1bd800 to 35facad Compare March 30, 2024 16:11
@BeryJu BeryJu requested a review from a team as a code owner March 30, 2024 21:13
BeryJu added 16 commits April 2, 2024 13:51
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
we didn't really use it to do anything, and we shouldn't have to since the live/ready probes are handled by django anyways and so the container runtime will restart the server if needed

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This reverts commit a129f7a.

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

# Conflicts:
#	authentik/root/settings.py
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
@BeryJu BeryJu force-pushed the root/better-startup-logic branch from e2faadb to 7c692bb Compare April 2, 2024 11:51
@BeryJu BeryJu merged commit 7ea721c into main Apr 2, 2024
@BeryJu BeryJu deleted the root/better-startup-logic branch April 2, 2024 12:19
BeryJu added a commit that referenced this pull request Apr 2, 2024
kensternberg-authentik added a commit that referenced this pull request Apr 4, 2024
* main:
  root: fix missing imports after #9081 (#9106)
  root: move database calls from ready() to dedicated startup signal (#9081)
  web: fix console log leftover (#9096)
  web: bump the eslint group in /web with 2 updates (#9098)
  core: bump twilio from 9.0.2 to 9.0.3 (#9103)
  web: bump the eslint group in /tests/wdio with 2 updates (#9099)
  core: bump drf-spectacular from 0.27.1 to 0.27.2 (#9100)
  core: bump django-model-utils from 4.4.0 to 4.5.0 (#9101)
  core: bump ruff from 0.3.4 to 0.3.5 (#9102)
  website/docs:  update notes on SECRET_KEY (#9091)
  web: fix broken locale compile (#9095)
  website/integrations: add outline knowledge base (#8786)
  website/docs: fix typo (#9082)
  website/docs: email stage: fix example translation error (#9048)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants