From ae2eac4235a0c15b60e63e4df83978c42aca3fe1 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Tue, 2 May 2023 17:18:04 +0300 Subject: [PATCH 1/4] Added additional entry to Makefile to build & run debugging setup. Added start.sh script to run epidata in 'debug' mode --- dev/local/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ devops/start.sh | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 devops/start.sh diff --git a/dev/local/Makefile b/dev/local/Makefile index 55210d790..df3a267b1 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -101,6 +101,41 @@ web: --network delphi-net --name delphi_web_epidata \ delphi_web_epidata >$(LOG_WEB) 2>&1 & +.PHONY=web_debug +web_debug: + @# 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 + @docker run --rm -p 127.0.0.1:10080:80 -p 127.0.0.1:5678:5678 \ + $(M1) \ + --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/devops/start.sh,target=/start.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" \ + --env "REDIS_HOST=delphi_redis" \ + --env "REDIS_PASSWORD=1234" \ + --env "API_KEY_ADMIN_PASSWORD=test_admin_password" \ + --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \ + --network delphi-net --name delphi_web_epidata \ + delphi_web_epidata >$(LOG_WEB) 2>&1 & + + .PHONY=db db: @# Stop container if running @@ -139,6 +174,9 @@ py: .PHONY=all all: db web py +.PHONY=debug +debug: db web_debug py redis + .PHONY=test test: @docker run -i --rm --network delphi-net \ diff --git a/devops/start.sh b/devops/start.sh new file mode 100644 index 000000000..1e7d53a50 --- /dev/null +++ b/devops/start.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 From 36a23d54d90da88022ce89bbda2519cbb8227ca0 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Wed, 3 May 2023 19:20:39 +0300 Subject: [PATCH 2/4] Update Makefile --- dev/local/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/local/Makefile b/dev/local/Makefile index df3a267b1..b2b01a8eb 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -121,7 +121,7 @@ web_debug: @# 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 - @docker run --rm -p 127.0.0.1:10080:80 -p 127.0.0.1:5678:5678 \ + @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.sh,target=/start.sh,readonly \ --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src/server,target=/app/delphi/epidata/server \ From faf97145d9527289cde367c04844becaaa0f7365 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 5 May 2023 18:30:09 +0300 Subject: [PATCH 3/4] Update Makefile --- dev/local/Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dev/local/Makefile b/dev/local/Makefile index b2b01a8eb..9fce3cd66 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -128,10 +128,6 @@ web_debug: --env "MODULE_NAME=delphi.epidata.server.main" \ --env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \ --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \ - --env "REDIS_HOST=delphi_redis" \ - --env "REDIS_PASSWORD=1234" \ - --env "API_KEY_ADMIN_PASSWORD=test_admin_password" \ - --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \ --network delphi-net --name delphi_web_epidata \ delphi_web_epidata >$(LOG_WEB) 2>&1 & @@ -175,7 +171,7 @@ py: all: db web py .PHONY=debug -debug: db web_debug py redis +debug: db web_debug py .PHONY=test test: From 1a804cd2b98d688a1bbad2aa15d3a2fd08a56e07 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Thu, 19 Oct 2023 00:00:16 +0300 Subject: [PATCH 4/4] Requested changes --- dev/local/Makefile | 13 +++++++++---- devops/{start.sh => start_vscodedebug.sh} | 0 2 files changed, 9 insertions(+), 4 deletions(-) rename devops/{start.sh => start_vscodedebug.sh} (100%) diff --git a/dev/local/Makefile b/dev/local/Makefile index 9fce3cd66..7e6434d85 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -101,8 +101,11 @@ web: --network delphi-net --name delphi_web_epidata \ delphi_web_epidata >$(LOG_WEB) 2>&1 & -.PHONY=web_debug -web_debug: +.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);\ @@ -121,9 +124,11 @@ web_debug: @# 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.sh,target=/start.sh,readonly \ + --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)" \ @@ -171,7 +176,7 @@ py: all: db web py .PHONY=debug -debug: db web_debug py +debug: db web_vscodedebug py .PHONY=test test: diff --git a/devops/start.sh b/devops/start_vscodedebug.sh similarity index 100% rename from devops/start.sh rename to devops/start_vscodedebug.sh