Skip to content

Commit

Permalink
[chore] Support developing and debugging in a docker container (#31)
Browse files Browse the repository at this point in the history
* Our main branch is called main.

* Support debugging and developing in docker.

* Update readme.

* fix
  • Loading branch information
jgadling authored Aug 17, 2023
1 parent e07cf02 commit 0b8a57d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/entities-push-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Entities tests
on:
push:
branches:
- trunk
- main
paths:
- "entities/**"
pull_request:
Expand Down
23 changes: 23 additions & 0 deletions entities/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Entities devcontainer",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "entities",
"workspaceFolder": "/czid-platformics/entities",
"shutdownAction": "echo shutting down",
"customizations": {
"vscode": {
"settings": {
"extensions.verifySignature": false
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"matangover.mypy",
"GitHub.copilot"
]
}
}
}
21 changes: 21 additions & 0 deletions entities/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Entities",
"type": "python",
"request": "launch",
"module": "api.main",
// Stop the normal webserver so we can start a new one attached to our debugger.
"preLaunchTask": "stopservices",
// Turn the normal server back on when we're done debugging.
"postDebugTask": "startservices",
"jinja": true,
"justMyCode": true
}
]
}

15 changes: 15 additions & 0 deletions entities/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "stopservices",
"command": "supervisorctl",
"args": ["-c", "/czid-platformics/entities/etc/supervisord.conf", "stop", "all"]
},
{
"label": "startservices",
"command": "supervisorctl",
"args": ["-c", "/czid-platformics/entities/etc/supervisord.conf", "start", "all"]
}
]
}
9 changes: 9 additions & 0 deletions entities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ docker compose exec entities bash
export PLATFORMICS_AUTH_TOKEN=$(./cli/gqlcli.py auth generate-token 111 --project 444:admin --expiration 3600)
./cli/gqlcli.py samples list
```

### Debugging in VSCode:
- Install the 'Dev Containers' and 'Docker' VSCode extensions
- Open VSCode at the entities directory
- Click "reopen in container" when VSCode suggests it.
- You're now editing code directly in the container! This is handy because all of the python packages used by the app are installed in the container and type checking will work properly.
- You can set breakpoints and click the "debug/play" icon in VSCode to step through your code.
- **Note** that you'll generally have to make a request (via cli/browser/???) to actually trigger the section of code you're debugging.

16 changes: 5 additions & 11 deletions entities/api/main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import typing
from database.connect import AsyncDB

import database.models as db
import strawberry
import uvicorn
from cerbos.sdk.client import CerbosClient
from cerbos.sdk.model import Principal
from database.connect import AsyncDB
from fastapi import Depends, FastAPI
from strawberry.fastapi import GraphQLRouter
from thirdparty.strawberry_sqlalchemy_mapper import (
StrawberrySQLAlchemyMapper,
)
from api.core.gql_loaders import EntityLoader, get_base_loader
from thirdparty.strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper

from api.core.deps import (
get_auth_principal,
get_cerbos_client,
get_engine,
)
from api.core.deps import get_auth_principal, get_cerbos_client, get_engine
from api.core.gql_loaders import EntityLoader, get_base_loader
from api.core.settings import APISettings

######################
Expand Down Expand Up @@ -95,6 +89,6 @@ def get_app() -> FastAPI:
app = get_app()

if __name__ == "__main__":
config = uvicorn.Config("example:app", host="0.0.0.0", port=8008, log_level="info")
config = uvicorn.Config("api.main:app", host="0.0.0.0", port=8008, log_level="info")
server = uvicorn.Server(config)
server.run()

0 comments on commit 0b8a57d

Please sign in to comment.