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 1 commit
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
Prev Previous commit
fix: Allowed to run a python script
  • Loading branch information
angelxehg committed Jul 24, 2024
commit b7c9fa6dc22d735ddc9a4c6c49e97704d03a008f
19 changes: 17 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,25 @@
"justMyCode": true
},
{
"name": "Docker: Python - Flask",
"name": "Docker: Python Flask",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"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": [
{
Expand Down
27 changes: 24 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"label": "docker-build: flask",
"platform": "python",
"dockerBuild": {
"tag": "pythonsamplevscodeflasktutorial:latest",
Expand All @@ -14,9 +14,9 @@
},
{
"type": "docker-run",
"label": "docker-run: debug",
"label": "docker-run: debug flask",
"dependsOn": [
"docker-build"
"docker-build: flask"
],
"dockerRun": {
"env": {
Expand All @@ -35,6 +35,27 @@
],
"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"
}
}
]
}
7 changes: 7 additions & 0 deletions compose.debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ services:
- 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"]
6 changes: 6 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ services:
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/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()