From 11c646ea52915e705c409c14c186511480a22a14 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Fri, 29 Nov 2024 13:08:50 +0000 Subject: [PATCH] fix: Remove the usage of pkg_resources + add debugging instructions --- dev/compose/README.md | 54 ++++++++++++++++++++++++++++++++- dev/compose/aap.yaml | 23 +++++++++++--- dev/compose/community.yaml | 23 +++++++++++--- dev/compose/insights.yaml | 23 +++++++++++--- galaxy_ng/app/dynaconf_hooks.py | 16 +++++++--- 5 files changed, 122 insertions(+), 17 deletions(-) diff --git a/dev/compose/README.md b/dev/compose/README.md index f5fb19ec54..8efbcbc5a1 100644 --- a/dev/compose/README.md +++ b/dev/compose/README.md @@ -216,10 +216,62 @@ Run with legacy oci-env, check the [Running oci-env integration tests](../../doc ## Tips and Tricks. -**TBD** +--- ### Debugging +#### Step 1 - Enable tty and stdin on the container you want to debug + +For example, if you are debugging the `migrations` container, edit the migrations: service +on `aap.yaml` and find the lines. + +```yaml +# uncomment below when debugging +# stdin_open: true +# tty: true +``` + +and remove the comment + +```yaml +stdin_open: true +tty: true +``` + +#### Step 2 - Add the breakpoint + +Edit the file you want to debug and add a breakpoint + +```python +__import__("ipdb").set_trace() +``` + +> [!TIP] +> Replace if you are using a different debugger, however the images has only **pdb** and **ipdb** installed. + +If you discover other ways of debugging, likle connecting dab protocol or vscode debugger, please update this file! + +#### Step 3- Now execute your stack or just the container you are trying to debug. + +Example: + +```bash +$ export DEV_SOURCE_PATH=galaxy_ng +$ docker compose -f dev/compose/aap.yaml up migrations +# The container will keep running stopped on the breakpoint. +``` + +#### Step 4- Attach + +```bash +$ docker compose -f dev/compose/insights.yaml attach migrations +ipdb> +``` + +--- + +**TBD** + ### Connecting to Database ### Dumping and restoring the database diff --git a/dev/compose/aap.yaml b/dev/compose/aap.yaml index a7f76eaf8a..41538aeb07 100644 --- a/dev/compose/aap.yaml +++ b/dev/compose/aap.yaml @@ -140,6 +140,9 @@ services: touch /var/lib/pulp/.migrated; " + # uncomment below when debugging + # stdin_open: true + # tty: true api: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -162,11 +165,14 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-api " + # uncomment below when debugging + # stdin_open: true + # tty: true content: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -189,11 +195,14 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-content " + # uncomment below when debugging + # stdin_open: true + # tty: true worker: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -211,14 +220,17 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; # Worker needs gpg in order to consume signing tasks; gpg --list-secret-keys; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-worker " + # uncomment below when debugging + # stdin_open: true + # tty: true manager: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -237,8 +249,8 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; # Give some time for API to start; sleep 5; @@ -275,6 +287,9 @@ services: # Keep it running indefinitely to enable `docker compose -f ... exec manager /bin/bash`; tail -f /dev/null " + # uncomment below when debugging + # stdin_open: true + # tty: true nginx: image: "nginx:latest" diff --git a/dev/compose/community.yaml b/dev/compose/community.yaml index 9ff409f59e..8b3e01f3cb 100644 --- a/dev/compose/community.yaml +++ b/dev/compose/community.yaml @@ -161,6 +161,9 @@ services: touch /var/lib/pulp/.migrated; " + # uncomment below when debugging + # stdin_open: true + # tty: true api: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -183,10 +186,13 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-api " + # uncomment below when debugging + # stdin_open: true + # tty: true content: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -209,10 +215,13 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-content " + # uncomment below when debugging + # stdin_open: true + # tty: true worker: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -230,10 +239,13 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-worker " + # uncomment below when debugging + # stdin_open: true + # tty: true manager: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -252,8 +264,8 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; # Give some time for API to start; sleep 5; @@ -276,6 +288,9 @@ services: # Keep it running indefinitely to enable `docker compose -f ... exec manager /bin/bash`; tail -f /dev/null " + # uncomment below when debugging + # stdin_open: true + # tty: true nginx: image: "nginx:latest" diff --git a/dev/compose/insights.yaml b/dev/compose/insights.yaml index ae56fe8abe..8f45fbde3a 100644 --- a/dev/compose/insights.yaml +++ b/dev/compose/insights.yaml @@ -140,6 +140,9 @@ services: touch /var/lib/pulp/.migrated; " + # uncomment below when debugging + # stdin_open: true + # tty: true api: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -162,10 +165,13 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-api " + # uncomment below when debugging + # stdin_open: true + # tty: true content: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -188,10 +194,13 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-content " + # uncomment below when debugging + # stdin_open: true + # tty: true worker: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -209,14 +218,17 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; # Worker needs gpg in order to consume signing tasks; gpg --list-secret-keys; /src/galaxy_ng/dev/compose/bin/reloader /venv/bin/pulpcore-worker " + # uncomment below when debugging + # stdin_open: true + # tty: true manager: image: "localhost/galaxy_ng/galaxy_ng:dev" @@ -235,8 +247,8 @@ services: user: root command: | bash -c " - /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; /src/galaxy_ng/dev/compose/bin/devinstall; + /src/galaxy_ng/dev/compose/bin/wait /var/lib/pulp/.migrated; # Give some time for API to start; sleep 5; @@ -263,6 +275,9 @@ services: # Keep it running indefinitely to enable `docker compose -f ... exec manager /bin/bash`; tail -f /dev/null " + # uncomment below when debugging + # stdin_open: true + # tty: true nginx: image: "nginx:latest" diff --git a/galaxy_ng/app/dynaconf_hooks.py b/galaxy_ng/app/dynaconf_hooks.py index dbc0b725e5..cbd633873e 100644 --- a/galaxy_ng/app/dynaconf_hooks.py +++ b/galaxy_ng/app/dynaconf_hooks.py @@ -15,10 +15,10 @@ import logging import os import re +import sys from typing import Any import ldap -import pkg_resources from ansible_base.lib.dynamic_config.settings_logic import get_dab_settings from crum import get_current_request from django.apps import apps @@ -27,6 +27,13 @@ from galaxy_ng.app.dynamic_settings import DYNAMIC_SETTINGS_SCHEMA +if sys.version_info < (3, 10): + # Python 3.9 has a rather different interface for `entry_points`. + # Let's use a compatibility version. + from importlib_metadata import EntryPoint +else: + from importlib.metadata import EntryPoint + logger = logging.getLogger(__name__) DAB_SERVICE_BACKED_REDIRECT = ( @@ -535,9 +542,10 @@ def configure_ldap(settings: Dynaconf) -> dict[str, Any]: "AUTH_LDAP_GROUP_TYPE_CLASS", default="django_auth_ldap.config:GroupOfNamesType" ): - group_type_class = pkg_resources.EntryPoint.parse( - f"__name = {classpath}" - ).resolve() + entry_point = EntryPoint( + name=None, group=None, value=classpath + ) + group_type_class = entry_point.load() group_type_params = settings.get( "AUTH_LDAP_GROUP_TYPE_PARAMS", default={"name_attr": "cn"}