Skip to content
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

feat: Working django container debug #98

Open
wants to merge 5 commits into
base: main
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
38 changes: 27 additions & 11 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
# TODO: should I put the images in another directory??
!**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
.vscode
__pycache__
env
README.md
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,36 @@
],
"jinja": true,
"justMyCode": true
},
{
"name": "Docker: Python Flask",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug flask",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "flask"
}
},
{
"name": "Docker: Python Long Script",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug long-script",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "flask"
}
}
]
}
61 changes: 61 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build: flask",
"platform": "python",
"dockerBuild": {
"tag": "pythonsamplevscodeflasktutorial:latest",
"dockerfile": "${workspaceFolder}/compose/flask_apps/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug flask",
"dependsOn": [
"docker-build: flask"
],
"dockerRun": {
"env": {
"FLASK_APP": "hello_app/webapp.py"
}
},
"python": {
"args": [
"run",
"--no-debugger",
"--no-reload",
"--host",
"0.0.0.0",
"--port",
"5002"
],
"module": "flask"
}
},
{
"type": "docker-build",
"label": "docker-build: long-script",
"platform": "python",
"dockerBuild": {
"tag": "pythonsamplevscodeflasktutorial:latest",
"dockerfile": "${workspaceFolder}/compose/long_script/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug long-script",
"dependsOn": [
"docker-build: long-script"
],
"python": {
"file": "long_script.py"
}
}
]
}
34 changes: 0 additions & 34 deletions Dockerfile

This file was deleted.

21 changes: 21 additions & 0 deletions compose.debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.4'

services:
pythonsamplevscodeflasktutorial:
image: pythonsamplevscodeflasktutorial
build:
context: .
dockerfile: ./compose/flask_apps/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 5002"]
ports:
- 5002:5002
- 5678:5678
environment:
- FLASK_APP=hello_app/webapp.py

long-script:
image: long-script
build:
context: .
dockerfile: ./compose/long_script/Dockerfile
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 long_script.py"]
16 changes: 16 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.4'

services:
pythonsamplevscodeflasktutorial:
image: pythonsamplevscodeflasktutorial
build:
context: .
dockerfile: ./compose/flask_apps/Dockerfile
ports:
- 5002:5002

long-script:
image: long-script
build:
context: .
dockerfile: ./compose/long_script/Dockerfile
25 changes: 25 additions & 0 deletions compose/flask_apps/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3-slim

EXPOSE 5002

# 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 requirements.txt .
RUN python -m pip install -r requirements.txt

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", "--bind", "0.0.0.0:5002", "hello_app.webapp:app"]
25 changes: 25 additions & 0 deletions compose/long_script/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3-slim

EXPOSE 5002

# 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 requirements.txt .
RUN python -m pip install -r requirements.txt

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 ["python", "long_script.py"]
11 changes: 11 additions & 0 deletions long_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import time


def main():
print("I'm here")
time.sleep(15)
print("I'm done")


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Flask
gunicorn