container docker pour le backend python pret

This commit is contained in:
2023-01-11 23:31:37 +01:00
parent e1810554a6
commit 01eb7976a2
9 changed files with 83 additions and 30 deletions

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

18
code/backend/Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim
# 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
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "main.py"]

28
code/backend/main.py Normal file
View File

@@ -0,0 +1,28 @@
import asyncio
import json
import websockets
import random
class WebsocketServer:
def __init__(self,getEffects,port=5000,host="backend") -> None:
self.host = host
self.port = port
self.getEffects = getEffects
async def run(self):
async with websockets.serve(self.handler, self.host, self.port):
await asyncio.Future()
async def handler(self,websocket):
while True:
messages = self.getEffects()
await websocket.send(json.dumps(messages))
await asyncio.sleep(1/30)
#Remplacer ça par la fonction qui récupère les effets (dans le module de reconnaissance de gestes)
def getEffects():
return {"type": "effects", "effects": [{"type": "thumbs_up", "x":random.randint(0,100), "y": random.randint(0,100), "width": 50, "height": 50}]}
server = WebsocketServer(getEffects)
asyncio.run(server.run())

View File

@@ -0,0 +1 @@
websockets