Ajouter les fichiers de configuration pour VS Code et le fichier .gitignore, et mettre à jour le Dockerfile, requirements.txt, les imports dans models.py et security.py

This commit is contained in:
Pierre Berthe 2024-04-12 12:14:59 +02:00
parent c6579868d7
commit dce4482e46
6 changed files with 118 additions and 11 deletions

27
.dockerignore Normal file
View file

@ -0,0 +1,27 @@
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

19
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Docker: Python - Fastapi",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "fastapi"
}
}
]
}

25
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,25 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "pytest:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": ["docker-build"],
"python": {
"args": ["main:app", "--host", "0.0.0.0", "--port", "8000"],
"module": "uvicorn"
}
}
]
}

View file

@ -1,11 +1,25 @@
FROM python:3.12-bookworm # For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.12-slim
EXPOSE 8000
# 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 WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY . /app COPY . /app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] # 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:8000", "-k", "uvicorn.workers.UvicornWorker", "main:app"]

12
docker-compose.debug.yml Normal file
View file

@ -0,0 +1,12 @@
version: '3.4'
services:
pytest:
image: pytest
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 uvicorn main:app --host 0.0.0.0 --port 8000"]
ports:
- 8000:8000
- 5678:5678

10
docker-compose.yml Normal file
View file

@ -0,0 +1,10 @@
version: '3.4'
services:
pytest:
image: pytest
build:
context: .
dockerfile: ./Dockerfile
ports:
- 8000:8000