diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8267453 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env/ +venv/ +.env +*.db +.git +.gitignore +.idea/ +.vscode/ +*.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..19b8f98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# 使用Python 3.9作为基础镜像 +FROM python:3.9-slim + +# 设置工作目录 +WORKDIR /app + +# 设置环境变量 +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + TZ=Asia/Shanghai + +# 安装系统依赖 +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# 复制项目文件 +COPY requirements.txt . +COPY app app/ + +# 安装Python依赖 +RUN pip install --no-cache-dir -r requirements.txt + +# 暴露端口 +EXPOSE 8000 + +# 启动命令 +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/app/core/config.py b/app/core/config.py index 6632db4..eb5c3aa 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -5,9 +5,7 @@ class Settings(BaseSettings): DEBUG: bool = True # 开发模式标志 API_V1_STR: str = "/api/v1" PROJECT_NAME: str = "FastAPI 项目" - - # 数据库配置 - DATABASE_URL: str = "sqlite:///./sql_app.db" + # JWT 配置 SECRET_KEY: str = "your-secret-key-here" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..de0f7c0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +version: '3.8' + +services: + api: + build: . + ports: + - "8000:8000" + environment: + - DEBUG=1 + - REDIS_HOST=redis + - MYSQL_HOST=mysql + depends_on: + - redis + - mysql + restart: unless-stopped + + redis: + image: redis:6 + command: redis-server --requirepass ${REDIS_PASSWORD} + ports: + - "6379:6379" + volumes: + - redis_data:/data + restart: unless-stopped + + mysql: + image: mysql:8 + ports: + - "3306:3306" + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=${MYSQL_DATABASE} + volumes: + - mysql_data:/var/lib/mysql + restart: unless-stopped + +volumes: + redis_data: + mysql_data: \ No newline at end of file