Skip to content

Commit

Permalink
fix: Remove the usage of pkg_resources + add debugging instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Nov 29, 2024
1 parent 767254d commit 3ab702e
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 17 deletions.
54 changes: 53 additions & 1 deletion dev/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions dev/compose/aap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
23 changes: 19 additions & 4 deletions dev/compose/community.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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;
Expand All @@ -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"
Expand Down
23 changes: 19 additions & 4 deletions dev/compose/insights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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;
Expand All @@ -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"
Expand Down
16 changes: 12 additions & 4 deletions galaxy_ng/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = (
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 3ab702e

Please sign in to comment.