From d69ae0123265d4f2d717945c09304bce2571f6c2 Mon Sep 17 00:00:00 2001 From: Solomon Laing Date: Thu, 3 Jun 2021 08:59:19 +0930 Subject: [PATCH] added auto-generated stuff from vs code, not sure if it works yet but it looks good. --- .dockerignore | 26 ++++++++++++++++++++++++ .vscode/launch.json | 19 ++++++++++++++++++ .vscode/tasks.json | 40 +++++++++++++++++++++++++++++++++++++ Dockerfile | 43 ++++++++++++++++++++++++---------------- docker-compose.debug.yml | 14 +++++++++++++ docker-compose.yml | 10 ++++++++++ gunicorn_config.py | 2 +- requirements.txt | 28 +++++++++++++------------- 8 files changed, 150 insertions(+), 32 deletions(-) create mode 100644 .dockerignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 docker-compose.debug.yml create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..da7fe8e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +**/__pycache__ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +README.md diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..339b284 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Docker: Python - Flask", + "type": "docker", + "request": "launch", + "preLaunchTask": "docker-run: debug", + "python": { + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/app" + } + ], + "projectType": "flask" + } + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..77673ad --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,40 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "docker-build", + "label": "docker-build", + "platform": "python", + "dockerBuild": { + "tag": "simpleblogapi:latest", + "dockerfile": "${workspaceFolder}/Dockerfile", + "context": "${workspaceFolder}", + "pull": true + } + }, + { + "type": "docker-run", + "label": "docker-run: debug", + "dependsOn": [ + "docker-build" + ], + "dockerRun": { + "env": { + "FLASK_APP": "wsgi.py" + } + }, + "python": { + "args": [ + "run", + "--no-debugger", + "--no-reload", + "--host", + "0.0.0.0", + "--port", + "5000" + ], + "module": "flask" + } + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ddec06d..f78c635 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,26 @@ -FROM python:3.8 - -RUN pip3 install pipenv gunicorn - -ENV PROJECT_DIR /usr/src/simpleblogapi - -WORKDIR ${PROJECT_DIR} - -COPY Pipfile . -COPY Pipfile.lock . -COPY . . - -RUN pipenv install --deploy --ignore-pipfile - -EXPOSE 5400 - -CMD ["gunicorn", "-c", "gunicorn_config.py", "wsgi:api"] +# For more information, please refer to https://aka.ms/vscode-docker-python +FROM python:3.8-slim-buster + +EXPOSE 5000 + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + +# Install pip requirements +COPY Pipfile . +COPY Pipfile.lock . +RUN pipenv install --deploy --ignore-pipfile + +WORKDIR /app +COPY . /app + +# Creates a non-root user with an explicit UID and adds permission to access the /app folder +# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers +RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app +USER appuser + +# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug +CMD ["gunicorn", "-c", "gunicorn_config.py", "wsgi:api"] diff --git a/docker-compose.debug.yml b/docker-compose.debug.yml new file mode 100644 index 0000000..f6a96fa --- /dev/null +++ b/docker-compose.debug.yml @@ -0,0 +1,14 @@ +version: '3.4' + +services: + simpleblogapi: + image: simpleblogapi + build: + context: . + dockerfile: ./Dockerfile + command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5000"] + ports: + - 5000:5000 + - 5678:5678 + environment: + - FLASK_APP=wsgi.py diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..84f6345 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.4' + +services: + simpleblogapi: + image: simpleblogapi + build: + context: . + dockerfile: ./Dockerfile + ports: + - 5000:5000 diff --git a/gunicorn_config.py b/gunicorn_config.py index d415b56..2a1573b 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,4 +1,4 @@ # to run: gunicorn -c gunicorn_config.py wsgi:api -bind = "0.0.0.0:5400" +bind = "0.0.0.0:5000" workers = 2 diff --git a/requirements.txt b/requirements.txt index b45bd26..2f1c032 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,14 @@ -aniso8601==9.0.1 -beautifulsoup4==4.9.3 -click==8.0.1 -Flask==2.0.1 -Flask-RESTful==0.3.9 -gunicorn==20.1.0 -itsdangerous==2.0.1 -Jinja2==3.0.1 -Markdown==3.3.4 -MarkupSafe==2.0.1 -pytz==2021.1 -six==1.16.0 -soupsieve==2.2.1 -Werkzeug==2.0.1 +# To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file +flask==1.1.2 +gunicorn==20.0.4 +aniso8601==9.0.1 +beautifulsoup4==4.9.3 +click==8.0.1 +Flask-RESTful==0.3.9 +itsdangerous==2.0.1 +Jinja2==3.0.1 +Markdown==3.3.4 +MarkupSafe==2.0.1 +pytz==2021.1 +six==1.16.0 +soupsieve==2.2.1