Skip to content

Debugging options #1157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions dev/local/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ web:
--network delphi-net --name delphi_web_epidata \
delphi_web_epidata >$(LOG_WEB) 2>&1 &

.PHONY=web_vscodedebug
web_vscodedebug:
@# Full giude can be found by the link below:
@# https://docs.google.com/presentation/d/1RMxsPO3uYqjAqBNzhDJTtLM0Xglm7kAijFi2W2tzd6U/edit?usp=sharing

@# Stop container if running
@if [ $(WEB_CONTAINER_ID) ]; then\
docker stop $(WEB_CONTAINER_ID);\
fi

@# Setup virtual network if it doesn't exist
@docker network ls | grep delphi-net || docker network create --driver bridge delphi-net

@# Build the web_epidata image
@cd repos/delphi/delphi-epidata; \
docker build -t delphi_web_epidata \
$(M1) \
-f ./devops/Dockerfile .;\
cd -

@# Run the web server
@# MODULE_NAME specifies the location of the `app` variable, the actual WSGI application object to run.
@# see https://github.com/tiangolo/meinheld-gunicorn-docker#module_name

@# mount the debuging start script (start_vscodedebug.sh) into the container so the webserver uses it
@docker run --rm -p 127.0.0.1:5000:5000 -p 127.0.0.1:5678:5678 \
$(M1) \
--mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/devops/start_vscodedebug.sh,target=/start_vscodedebug.sh,readonly \
--mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src/server,target=/app/delphi/epidata/server \
--env "MODULE_NAME=delphi.epidata.server.main" \
--env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \
--env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \
--network delphi-net --name delphi_web_epidata \
delphi_web_epidata >$(LOG_WEB) 2>&1 &


.PHONY=db
db:
@# Stop container if running
Expand Down Expand Up @@ -175,6 +211,9 @@ redis:
.PHONY=all
all: db web py redis

.PHONY=debug
debug: db web_vscodedebug py

.PHONY=test
test:
@docker run -i --rm --network delphi-net \
Expand Down
18 changes: 18 additions & 0 deletions devops/start_vscodedebug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env sh
set -e

# If there's a prestart.sh script in the /app directory, run it before starting
PRE_START_PATH=/app/prestart.sh
echo "Checking for script in $PRE_START_PATH"
if [ -f $PRE_START_PATH ] ; then
echo "Running script $PRE_START_PATH"
. "$PRE_START_PATH"
else
echo "There is no script $PRE_START_PATH"
fi

export FLASK_APP=delphi.epidata.server.main

pip install debugpy

python -m debugpy --listen 0.0.0.0:5678 --wait-for-client -m flask run -h 0.0.0.0 -p 5000