Explorar o código

feat:dockerfile

tanjingyu hai 1 semana
pai
achega
e6d6979070
Modificáronse 5 ficheiros con 175 adicións e 3 borrados
  1. 56 0
      .dockerignore
  2. 25 0
      .env
  3. 0 3
      .gitignore
  4. 65 0
      Dockerfile
  5. 29 0
      docker-compose.yml

+ 56 - 0
.dockerignore

@@ -0,0 +1,56 @@
+# Git
+.git
+.gitignore
+
+# IDE
+.idea/
+.vscode/
+*.iml
+
+# Claude / Gemini
+.claude/
+.gemini/
+.agents/
+
+# Python 缓存
+__pycache__/
+*.py[cod]
+*.pyo
+.Python
+*.egg-info/
+dist/
+build/
+.eggs/
+*.egg
+.venv/
+venv/
+env/
+
+# 环境变量(不要打包到镜像,通过 env_file 挂载)
+.env
+
+# 本地存储数据
+storage/
+
+# 日志
+*.log
+logs/
+
+# 系统文件
+.DS_Store
+Thumbs.db
+
+# 测试
+tests/
+.pytest_cache/
+.coverage
+htmlcov/
+
+# Docker 自身
+Dockerfile
+docker-compose.yml
+docker-compose.*.yml
+.dockerignore
+
+# 文档
+*.md

+ 25 - 0
.env

@@ -0,0 +1,25 @@
+# ========== 数据库配置 ==========
+DB_HOST=rm-t4n8oyqunr5b4461s6o.mysql.singapore.rds.aliyuncs.com
+DB_PORT=3306
+DB_USER=developer_saas
+DB_PASSWORD=developer_saas#Aiddit
+DB_NAME=data_nexus
+
+# ========== Gogs 配置 ==========
+GOGS_URL=https://git.yishihui.com
+GOGS_TOKEN=4ae18a8e348dd931e33bf6f752536e9a6fd4d9c3
+GOGS_SECRET=
+
+# ========== Webhook 自动配置 ==========
+# 定时任务扫描仓库后,会将此 URL 配置为仓库的 webhook 回调地址
+GOGS_WEBHOOK_URL=http://your-data-nexus-host:8000/webhook
+# Webhook 回调时携带的签名密钥(可留空)
+GOGS_WEBHOOK_SECRET=
+
+# ========== OSS 配置 ==========
+OSS_ACCESS_KEY_ID=LTAI5t8tmBWXGsrG6KNG3GBL
+OSS_ACCESS_KEY_SECRET=HlGsLmtvZAlLIRvA2l7SgtlVj4Ojij
+OSS_ENDPOINT=oss-accelerate.aliyuncs.com
+OSS_BUCKET_NAME=aigc-crawler
+OSS_PREFIX=data_nexus
+OSS_CDN_URL=https://res-bj.cybertogether.net

+ 0 - 3
.gitignore

@@ -23,9 +23,6 @@ build/
 venv/
 env/
 
-# Environment
-.env
-
 # Logs
 *.log
 logs/

+ 65 - 0
Dockerfile

@@ -0,0 +1,65 @@
+# ============================================================
+# Data Nexus - Dockerfile
+# 基于 Python 3.11 slim 镜像,构建轻量级生产容器
+# ============================================================
+
+# ---------- 阶段 1:构建依赖 ----------
+FROM python:3.11-slim AS builder
+
+WORKDIR /tmp
+
+# 仅拷贝依赖文件,利用 Docker 缓存层
+COPY requirements.txt .
+
+# 安装依赖到独立目录,方便后续 COPY --from
+RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
+
+# ---------- 阶段 2:最终运行镜像 ----------
+FROM python:3.11-slim
+
+# 设置元数据
+LABEL maintainer="Data Nexus Team"
+LABEL description="Data Nexus - 轻量级数据中台服务"
+
+# 设置环境变量
+ENV PYTHONDONTWRITEBYTECODE=1 \
+    PYTHONUNBUFFERED=1 \
+    TZ=Asia/Shanghai
+
+# 安装运行时依赖(时区支持)
+RUN apt-get update && \
+    apt-get install -y --no-install-recommends \
+        tzdata \
+        curl && \
+    ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
+    echo "${TZ}" > /etc/timezone && \
+    apt-get clean && \
+    rm -rf /var/lib/apt/lists/*
+
+# 创建非 root 用户
+RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser
+
+# 从 builder 阶段复制已安装的 Python 依赖
+COPY --from=builder /install /usr/local
+
+# 设置工作目录
+WORKDIR /app
+
+# 拷贝应用代码
+COPY app/ ./app/
+
+# 创建 storage 目录并设置权限
+RUN mkdir -p /data/storage && chown -R appuser:appuser /app /data/storage
+
+# 切换到非 root 用户
+USER appuser
+
+# 暴露端口
+EXPOSE 8000
+
+# 健康检查
+HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
+    CMD curl -f http://localhost:8000/ || exit 1
+
+# 启动命令:运行 app/main.py
+CMD ["python", "-m", "app.main"]

+ 29 - 0
docker-compose.yml

@@ -0,0 +1,29 @@
+# ============================================================
+# Data Nexus - Docker Compose 配置
+# 应用服务(数据库使用远程云服务)
+# ============================================================
+
+services:
+  app:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    container_name: data-nexus-app
+    restart: unless-stopped
+    ports:
+      - "8000:8000"
+    env_file:
+      - .env
+    volumes:
+      # 持久化本地存储目录
+      - storage_data:/data/storage
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost:8000/"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+
+# -------------------- 持久化卷 --------------------
+volumes:
+  storage_data:
+    driver: local