From e19376f909fd55a4e9e0d480dbf2454a9ee2af04 Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Mon, 30 Sep 2019 20:39:46 +1000 Subject: [PATCH] python debugging examples --- .vscode/launch.json | 16 +++++++++++++++- docker-compose.yaml | 3 ++- python/dockerfile | 17 +++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6e79ee66b..ce7bf3ab6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,6 +32,20 @@ "args": [], "trace" : "verbose", "env" : {} - } + }, + { + "name": "Python Attach", + "type": "python", + "request": "attach", + "pathMappings": [ + { + "localRoot": "${workspaceFolder}/python/src/", + "remoteRoot": "/work" + } + ], + "port": 5678, + "host": "127.0.0.1" + }, + ] } \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 590e64213..15ff12b9f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -44,7 +44,7 @@ services: image: aimvector/python:1.0.0 build: context: ./python - target: prod + target: debug #working_dir: /work #comment out for build.target:prod #entrypoint: /bin/sh #comment out for build.target:prod #stdin_open: true #comment out for build.target:prod @@ -53,3 +53,4 @@ services: - ./python/src/:/work ports: - 5003:5000 + - 5678:5678 diff --git a/python/dockerfile b/python/dockerfile index 57632821a..0cb36f6a9 100644 --- a/python/dockerfile +++ b/python/dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7.3-alpine3.9 as dev +FROM python:3.7.3-alpine3.9 as base RUN mkdir /work/ WORKDIR /work/ @@ -7,15 +7,16 @@ COPY ./src/requirements.txt /work/requirements.txt RUN pip install -r requirements.txt COPY ./src/ /work/ +ENV FLASK_APP=server.py -###########START NEW IMAGE################### +###########START NEW IMAGE : DEBUGGER ################### +FROM base as debug +RUN pip install ptvsd -FROM python:3.7.3-alpine3.9 as prod +WORKDIR /work/ +CMD python -m ptvsd --host 0.0.0.0 --port 5678 --wait --multiprocess -m flask run -h 0.0.0 -p 5000 -RUN mkdir /app/ -WORKDIR /app/ +###########START NEW IMAGE: PRODUCTION ################### +FROM base as prod -COPY --from=dev /work/ /app/ -RUN pip install -r requirements.txt -ENV FLASK_APP=server.py CMD flask run -h 0.0.0 -p 5000