Skip to content

Commit

Permalink
Support remote debugging in dev environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Sachs authored and Adam Sachs committed Nov 14, 2022
1 parent 4408279 commit 352854f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
22 changes: 19 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// Ensure your local dev server/container is configured remote debugging.
// See VSCode docs for some more information about remote debugging python apps:
// https://code.visualstudio.com/docs/python/debugging#_debugging-by-attaching-over-a-network-connection
{
"name": "Python debugger: Remote Attach Fides",
"type": "python",
"request": "attach",
"connect": {
"host": "0.0.0.0",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
"justMyCode": false
},
{
"name": "Launch Chrome: Admin UI",
"request": "launch",
Expand All @@ -21,6 +40,3 @@
}
]
}



1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The types of changes are:
### Developer Experience

* Admin-UI-Cypress tests that fail in CI will now upload screen recordings for debugging. [#1728](https://github.com/ethyca/fides/pull/1728/files/c23e62fea284f7910028c8483feff893903068b8#r1019491323)
* Enable remote debugging from VSCode of live dev app (#1780)(https://github.com/ethyca/fides/pull/1780)

### Removed

Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
black==22.8.0
debugpy==1.6.3
Faker==14.1.0
GitPython==3.1.27
isort==5.10.1
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.remote-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
fides:
command: python -m debugpy --listen 0.0.0.0:5678 -m uvicorn --host 0.0.0.0 --port 8080 --reload --reload-dir src fides.api.main:app
ports:
- "8080:8080"
- "5678:5678"
11 changes: 11 additions & 0 deletions noxfiles/constants_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
COMPOSE_FILE = "docker-compose.yml"
INTEGRATION_COMPOSE_FILE = "docker-compose.integration-tests.yml"
TEST_ENV_COMPOSE_FILE = "docker-compose.test-env.yml"
REMOTE_DEBUG_COMPOSE_FILE = "docker-compose.remote-debug.yml"
WITH_TEST_CONFIG = ("-f", "tests/ctl/test_config.toml")

# Image Names & Tags
Expand Down Expand Up @@ -91,6 +92,16 @@
"--wait",
COMPOSE_SERVICE_NAME,
)
START_APP_REMOTE_DEBUG = (
"docker",
"compose",
"-f",
COMPOSE_FILE,
"-f",
REMOTE_DEBUG_COMPOSE_FILE,
"up",
COMPOSE_SERVICE_NAME,
)
START_APP_WITH_EXTERNAL_POSTGRES = (
"docker",
"compose",
Expand Down
14 changes: 12 additions & 2 deletions noxfiles/dev_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
RUN,
RUN_NO_DEPS,
START_APP,
START_APP_REMOTE_DEBUG,
START_TEST_ENV,
)
from docker_nox import build
Expand Down Expand Up @@ -38,16 +39,25 @@ def dev(session: Session) -> None:
session.run("docker", "compose", "up", "-d", "fides-pc", external=True)

open_shell = "shell" in session.posargs
remote_debug = "remote_debug" in session.posargs
if not datastores:
if open_shell:
session.run(*START_APP, external=True)
session.run(*RUN, "/bin/bash", external=True)
else:
session.run("docker", "compose", "up", COMPOSE_SERVICE_NAME, external=True)
if remote_debug:
session.run(*START_APP_REMOTE_DEBUG, external=True)
else:
session.run(
"docker", "compose", "up", COMPOSE_SERVICE_NAME, external=True
)
else:
# Run the webserver with additional datastores
run_infrastructure(
open_shell=open_shell, run_application=True, datastores=datastores
open_shell=open_shell,
run_application=True,
datastores=datastores,
remote_debug=remote_debug,
)


Expand Down
7 changes: 5 additions & 2 deletions noxfiles/run_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def run_infrastructure(
run_tests: bool = False, # Should we run the tests after creating the infra?
run_create_test_data: bool = False, # Should we run the create_test_data command?
analytics_opt_out: bool = False, # Should we opt out of analytics?
remote_debug: bool = False, # Should remote debugging be enabled?
) -> None:
"""
- Create a Docker Compose file path for all datastores specified in `datastores`.
Expand All @@ -64,7 +65,7 @@ def run_infrastructure(
]

# Configure docker compose path
path: str = get_path_for_datastores(datastores)
path: str = get_path_for_datastores(datastores, remote_debug)

_run_cmd_or_err(
f"docker compose {path} up --wait {COMPOSE_SERVICE_NAME} {' '.join(docker_datastores)}"
Expand Down Expand Up @@ -120,11 +121,13 @@ def seed_initial_data(
)


def get_path_for_datastores(datastores: List[str]) -> str:
def get_path_for_datastores(datastores: List[str], remote_debug: bool) -> str:
"""
Returns the docker compose file paths for the specified datastores
"""
path: str = "-f docker-compose.yml"
if remote_debug:
path += " -f docker-compose.remote-debug.yml"
for datastore in datastores:
_run_cmd_or_err(f'echo "configuring infrastructure for {datastore}"')
if datastore in DOCKERFILE_DATASTORES:
Expand Down

0 comments on commit 352854f

Please sign in to comment.