diff --git a/dev/local/Makefile b/dev/local/Makefile index d0854a064..87cee7a12 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -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 @@ -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 \ diff --git a/devops/start_vscodedebug.sh b/devops/start_vscodedebug.sh new file mode 100644 index 000000000..1e7d53a50 --- /dev/null +++ b/devops/start_vscodedebug.sh @@ -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 \ No newline at end of file