added docker support

This commit is contained in:
WillowMT
2026-02-20 14:03:24 +07:00
parent f17c0ba90e
commit 984b1a68a6
8 changed files with 166 additions and 1 deletions

10
backend/.dockerignore Normal file
View File

@@ -0,0 +1,10 @@
.venv
__pycache__
*.pyc
*.pyo
.pytest_cache
.coverage
htmlcov
.env
.env.*
*.md

27
backend/Dockerfile Normal file
View File

@@ -0,0 +1,27 @@
# syntax=docker/dockerfile:1
FROM python:3.12-alpine AS builder
WORKDIR /app
RUN pip install --no-cache-dir --upgrade pip
COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
# ---
FROM python:3.12-alpine AS runtime
RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001 -G appgroup
WORKDIR /app
COPY --from=builder /wheels /wheels
RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels
COPY --chown=appuser:appgroup main.py .
USER appuser
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

View File

@@ -1,3 +1,4 @@
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@@ -7,9 +8,10 @@ app = FastAPI(
version="0.1.0",
)
_cors_origins = os.getenv("CORS_ORIGINS", "http://localhost:5173").split(",")
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"],
allow_origins=[o.strip() for o in _cors_origins if o.strip()],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],