Мурад Гаджимагомедов commited on
Commit
fa11207
·
1 Parent(s): 4e1cb22

переработанный докерфайл

Browse files
Files changed (2) hide show
  1. teapot/Dockerfile +12 -5
  2. teapot/backend/app.py +25 -18
teapot/Dockerfile CHANGED
@@ -1,13 +1,20 @@
1
  FROM python:3.9
2
 
3
- RUN useradd -m -u 1000 user
4
- USER user
5
- ENV PATH="/home/user/.local/bin:$PATH"
6
 
7
  WORKDIR /app
8
 
9
- COPY --chown=user ./requirements.txt .
10
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
12
- COPY --chown=user ./backend /app/backend
 
 
 
 
 
 
 
 
 
13
  CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.9
2
 
3
+ USER root
 
 
4
 
5
  WORKDIR /app
6
 
7
+ COPY requirements.txt .
8
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
9
 
10
+ COPY ./backend/app/backend
11
+ COPY ./frontend/app/frontend
12
+
13
+ RUN mkdir -p /app/data && chown -R 1000:1000 /app/data && chmod -R 777 /app/data
14
+
15
+ RUN useradd -m -u 1000 user
16
+ USER user
17
+ ENV PATH="/home/user/.local/bin:$PATH"
18
+
19
+ EXPOSE 7860
20
  CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "7860"]
teapot/backend/app.py CHANGED
@@ -1,20 +1,33 @@
 
1
  from fastapi import FastAPI, Request, HTTPException
2
  from fastapi.responses import FileResponse, JSONResponse
3
  from pydantic import BaseModel
4
  import uvicorn
5
- import json
6
- from .database import create_tables
7
  from .logic import spin, get_all_participants, add_new_participant, remove_participant, get_all_history
8
- from .database import update_participant_manually
9
 
10
  app = FastAPI()
11
 
12
  DB_PATH = 'data/teapot.db'
13
 
 
 
14
  @app.on_event("startup")
15
  async def startup_event():
16
  await create_tables(DB_PATH)
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  @app.get("/")
19
  async def get_index():
20
  return FileResponse('frontend/index.html')
@@ -27,20 +40,22 @@ async def get_admin():
27
  async def api_get_participants():
28
  return await get_all_participants(DB_PATH)
29
 
30
- class ParticipantRequest(BaseModel):
31
- name: str
32
-
33
  @app.post("/api/participants")
34
  async def api_add_participant(request: ParticipantRequest):
35
- if not await add_new_participant(DB_PATH, request.name):
 
36
  raise HTTPException(status_code=400, detail="Participant already exists")
 
37
 
38
  @app.delete("/api/participants/{id}")
39
  async def api_remove_participant(id: int):
40
  await remove_participant(DB_PATH, id)
 
41
 
42
- class SpinRequest(BaseModel):
43
- present: list[str]
 
 
44
 
45
  @app.post("/api/spin")
46
  async def api_spin(request: SpinRequest):
@@ -54,12 +69,4 @@ async def api_get_history():
54
  return await get_all_history(DB_PATH)
55
 
56
  if __name__ == "__main__":
57
- uvicorn.run(app, host='0.0.0.0', port=7860)
58
-
59
- class ParticipantUpdate(BaseModel):
60
- tickets: int
61
- pass_point: bool
62
-
63
- @app.patch("/api/participants/{id}")
64
- async def api_update_participant(id: int, data: ParticipantUpdate):
65
- await update_participant_manually(DB_PATH, id, data.tickets, data.pass_point)
 
1
+ import os
2
  from fastapi import FastAPI, Request, HTTPException
3
  from fastapi.responses import FileResponse, JSONResponse
4
  from pydantic import BaseModel
5
  import uvicorn
6
+
7
+ from .database import create_tables, update_participant_manually
8
  from .logic import spin, get_all_participants, add_new_participant, remove_participant, get_all_history
 
9
 
10
  app = FastAPI()
11
 
12
  DB_PATH = 'data/teapot.db'
13
 
14
+ os.makedirs('data', exist_ok=True)
15
+
16
  @app.on_event("startup")
17
  async def startup_event():
18
  await create_tables(DB_PATH)
19
 
20
+
21
+ class ParticipantRequest(BaseModel):
22
+ name: str
23
+
24
+ class SpinRequest(BaseModel):
25
+ present: list[str]
26
+
27
+ class ParticipantUpdate(BaseModel):
28
+ tickets: int
29
+ pass_point: bool
30
+
31
  @app.get("/")
32
  async def get_index():
33
  return FileResponse('frontend/index.html')
 
40
  async def api_get_participants():
41
  return await get_all_participants(DB_PATH)
42
 
 
 
 
43
  @app.post("/api/participants")
44
  async def api_add_participant(request: ParticipantRequest):
45
+ success = await add_new_participant(DB_PATH, request.name)
46
+ if not success:
47
  raise HTTPException(status_code=400, detail="Participant already exists")
48
+ return {"status": "ok"}
49
 
50
  @app.delete("/api/participants/{id}")
51
  async def api_remove_participant(id: int):
52
  await remove_participant(DB_PATH, id)
53
+ return {"status": "ok"}
54
 
55
+ @app.patch("/api/participants/{id}")
56
+ async def api_update_participant(id: int, data: ParticipantUpdate):
57
+ await update_participant_manually(DB_PATH, id, data.tickets, data.pass_point)
58
+ return {"status": "ok"}
59
 
60
  @app.post("/api/spin")
61
  async def api_spin(request: SpinRequest):
 
69
  return await get_all_history(DB_PATH)
70
 
71
  if __name__ == "__main__":
72
+ uvicorn.run(app, host='0.0.0.0', port=7860)