From 62f3ee56935957a2a0498d6bd768b2c6d9c985ea Mon Sep 17 00:00:00 2001 From: Zhenyu Zheng Date: Tue, 24 Feb 2026 13:16:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dockerfile: 使用 /bin/sh 调用 entrypoint.sh,解决文件权限问题 - 001_initial: publish_records 表补充 community_id 列(原迁移遗漏) - 002_schema_additions: 撤销临时补丁,保持迁移文件干净 - README: 更新启动命令加 --build,新增完整清理重部署说明 --- README.md | 33 +++++++++++++++++-- backend/Dockerfile | 2 +- backend/alembic/versions/001_initial.py | 2 ++ .../alembic/versions/002_schema_additions.py | 1 + 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a7fc86..c474405 100644 --- a/README.md +++ b/README.md @@ -105,14 +105,43 @@ cd openGecko cp backend/.env.example backend/.env # ⚠️ 生产环境务必编辑 backend/.env,修改 JWT_SECRET_KEY 为强随机字符串 -# 3. 启动 -docker compose up -d +# 3. 构建并启动(首次或代码更新后必须加 --build) +docker compose up -d --build ``` 启动后访问: - 🖥️ **平台界面**:http://localhost - 📖 **API 文档**:http://localhost:8000/docs +### 完整清理重部署 + +升级遇到问题或需要全量重置时,用以下命令彻底清除旧环境后重新部署: + +```bash +# 停止并移除容器、网络 +docker compose down + +# 删除旧镜像(强制下次重新构建) +docker rmi opengecko-backend opengecko-frontend 2>/dev/null || true + +# 删除持久化数据库(⚠️ 数据不可恢复,谨慎操作) +rm -f backend/opengecko.db + +# 重新构建并启动 +docker compose up -d --build +``` + +一行执行版: + +```bash +docker compose down && \ +docker rmi opengecko-backend opengecko-frontend 2>/dev/null; \ +rm -f backend/opengecko.db && \ +docker compose up -d --build +``` + +> **注意**:`backend/opengecko.db` 是通过 `docker-compose.override.yml` 挂载到宿主机的 SQLite 数据库文件,删除后所有数据(社区、内容、用户等)将清空,重启后重新初始化。生产环境使用 PostgreSQL 时此步骤不适用。 + ### 首次使用流程 1. 使用 `.env` 中配置的默认账号登录(默认 `admin` / `admin123`) diff --git a/backend/Dockerfile b/backend/Dockerfile index 60bdb16..b4eadef 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -28,6 +28,6 @@ USER appuser EXPOSE 8000 # entrypoint 先执行 alembic upgrade head,再启动应用 -ENTRYPOINT ["/app/entrypoint.sh"] +ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"] # 开发环境使用 uvicorn,生产通过 docker-compose.prod.yml 覆盖为 gunicorn CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/backend/alembic/versions/001_initial.py b/backend/alembic/versions/001_initial.py index 86ec294..ba182de 100644 --- a/backend/alembic/versions/001_initial.py +++ b/backend/alembic/versions/001_initial.py @@ -186,6 +186,7 @@ def upgrade(): "publish_records", sa.Column("id", sa.Integer(), primary_key=True), sa.Column("content_id", sa.Integer(), nullable=False), + sa.Column("community_id", sa.Integer(), nullable=True, index=True), sa.Column("channel", sa.String(50), nullable=False), sa.Column("status", sa.String(50), nullable=True), sa.Column("platform_article_id", sa.String(200), nullable=True), @@ -194,6 +195,7 @@ def upgrade(): sa.Column("error_message", sa.Text(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(["content_id"], ["contents.id"], ondelete="CASCADE"), + sa.ForeignKeyConstraint(["community_id"], ["communities.id"], ondelete="CASCADE"), ) # ------------------------------------------------------------------ diff --git a/backend/alembic/versions/002_schema_additions.py b/backend/alembic/versions/002_schema_additions.py index ac319ef..4dd37ab 100644 --- a/backend/alembic/versions/002_schema_additions.py +++ b/backend/alembic/versions/002_schema_additions.py @@ -28,6 +28,7 @@ def upgrade() -> None: + # ── 1. contents.community_id → nullable ──────────────────────────────────── with op.batch_alter_table("contents") as batch_op: batch_op.alter_column("community_id", existing_type=sa.Integer(), nullable=True)