From ed3a5c048601a0ac2c45ecaa5b16fc4031ab5746 Mon Sep 17 00:00:00 2001 From: bujie9527 Date: Thu, 5 Feb 2026 22:34:17 +0800 Subject: [PATCH] Update registry to registry.667788.cool and add build scripts Co-authored-by: Cursor --- REGISTRY_667788_SETUP.md | 153 +++++++++++++++++++++++++ deploy/docker/backend.Dockerfile | 7 +- docker-compose.prod.yml | 2 +- scripts/build-push-registry-667788.ps1 | 68 +++++++++++ 4 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 REGISTRY_667788_SETUP.md create mode 100644 scripts/build-push-registry-667788.ps1 diff --git a/REGISTRY_667788_SETUP.md b/REGISTRY_667788_SETUP.md new file mode 100644 index 0000000..6c8348b --- /dev/null +++ b/REGISTRY_667788_SETUP.md @@ -0,0 +1,153 @@ +# Registry 667788.cool 配置指南 + +## Registry 信息 + +- **Registry URL**: `registry.667788.cool` +- **API 端点**: `https://registry.667788.cool/v2/` +- **命名空间**: `wecom-ai` +- **镜像地址**: + - Backend: `registry.667788.cool/wecom-ai/wecom-ai-backend:latest` + - Admin: `registry.667788.cool/wecom-ai/wecom-ai-admin:latest` + +## 构建并推送镜像 + +### 方法一:使用脚本(推荐) + +```powershell +# 构建并推送所有镜像 +.\scripts\build-push-registry-667788.ps1 +``` + +### 方法二:手动构建 + +#### 1. 构建 Backend 镜像 + +```powershell +# 构建镜像 +docker build -f deploy/docker/backend.Dockerfile -t registry.667788.cool/wecom-ai/wecom-ai-backend:latest . + +# 推送镜像 +docker push registry.667788.cool/wecom-ai/wecom-ai-backend:latest +``` + +#### 2. 构建 Admin 镜像 + +```powershell +# 构建镜像 +docker build -f deploy/docker/admin.Dockerfile -t registry.667788.cool/wecom-ai/wecom-ai-admin:latest . + +# 推送镜像 +docker push registry.667788.cool/wecom-ai/wecom-ai-admin:latest +``` + +### 方法三:使用 docker-compose 构建 + +```powershell +# 设置环境变量 +$env:REGISTRY_URL = "registry.667788.cool" +$env:REGISTRY_NAMESPACE = "wecom-ai" +$env:IMAGE_TAG = "latest" + +# 构建并推送(如果 docker-compose 支持) +docker-compose -f docker-compose.prod.yml build +docker-compose -f docker-compose.prod.yml push +``` + +## 登录 Registry(如果需要认证) + +```powershell +# 如果 Registry 需要认证 +docker login registry.667788.cool + +# 或使用用户名密码 +docker login registry.667788.cool -u 用户名 -p 密码 +``` + +## 更新配置 + +### 更新 docker-compose.prod.yml + +确保使用新的 Registry: + +```yaml +services: + backend: + image: registry.667788.cool/wecom-ai/wecom-ai-backend:${IMAGE_TAG:-latest} +``` + +### 更新 .env.prod + +```bash +REGISTRY_URL=registry.667788.cool +REGISTRY_NAMESPACE=wecom-ai +IMAGE_TAG=latest +``` + +## 在服务器上拉取镜像 + +```bash +# 登录 Registry(如果需要) +docker login registry.667788.cool + +# 拉取镜像 +docker pull registry.667788.cool/wecom-ai/wecom-ai-backend:latest +docker pull registry.667788.cool/wecom-ai/wecom-ai-admin:latest + +# 使用 docker-compose 部署 +docker-compose -f docker-compose.prod.yml --env-file .env.prod up -d +``` + +## 验证推送 + +推送成功后,可以通过以下方式验证: + +1. **查看本地镜像**: + ```powershell + docker images | grep registry.667788.cool + ``` + +2. **测试拉取**(在另一台机器): + ```bash + docker pull registry.667788.cool/wecom-ai/wecom-ai-backend:latest + ``` + +3. **访问 Registry API**(如果支持): + ``` + https://registry.667788.cool/v2/wecom-ai/wecom-ai-backend/tags/list + ``` + +## 故障排查 + +### 问题:构建时无法拉取基础镜像 + +**解决方案**: +1. 配置 Docker 镜像加速(参考 `docs/docker-mirror.md`) +2. 或使用代理 +3. 或使用构建参数指定镜像源: + ```powershell + docker build --build-arg PYTHON_IMAGE=docker.mirrors.ustc.edu.cn/library/python:3.12-slim -f deploy/docker/backend.Dockerfile -t registry.667788.cool/wecom-ai/wecom-ai-backend:latest . + ``` + +### 问题:推送时提示认证失败 + +**解决方案**: +```powershell +# 登录 Registry +docker login registry.667788.cool + +# 重新推送 +docker push registry.667788.cool/wecom-ai/wecom-ai-backend:latest +``` + +### 问题:推送时提示权限不足 + +**解决方案**: +1. 确认用户名和密码正确 +2. 确认有推送权限 +3. 检查命名空间是否正确 + +## 相关文档 + +- [Docker 镜像加速配置](./docs/docker-mirror.md) +- [私有仓库配置](./docs/private-registry-setup.md) +- [宝塔面板配置](./docs/baota-docker-setup.md) diff --git a/deploy/docker/backend.Dockerfile b/deploy/docker/backend.Dockerfile index aef144b..6de0d5e 100644 --- a/deploy/docker/backend.Dockerfile +++ b/deploy/docker/backend.Dockerfile @@ -1,6 +1,8 @@ # 生产环境 Backend Dockerfile # 用途:构建优化的生产镜像 -FROM python:3.12-slim AS builder +# 支持通过构建参数指定基础镜像(默认使用官方镜像) +ARG PYTHON_IMAGE=python:3.12-slim +FROM ${PYTHON_IMAGE} AS builder WORKDIR /app @@ -16,7 +18,8 @@ COPY backend/requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # 生产镜像 -FROM python:3.12-slim +ARG PYTHON_IMAGE=python:3.12-slim +FROM ${PYTHON_IMAGE} WORKDIR /app diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index acfdb33..171d198 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -6,7 +6,7 @@ version: '3.8' services: backend: - image: ${REGISTRY_URL:-git.quanyu360.cn}/${REGISTRY_NAMESPACE:-wecom-ai}/wecom-ai-backend:${IMAGE_TAG:-latest} + image: ${REGISTRY_URL:-registry.667788.cool}/${REGISTRY_NAMESPACE:-wecom-ai}/wecom-ai-backend:${IMAGE_TAG:-latest} build: context: . dockerfile: deploy/docker/backend.Dockerfile diff --git a/scripts/build-push-registry-667788.ps1 b/scripts/build-push-registry-667788.ps1 new file mode 100644 index 0000000..4a33279 --- /dev/null +++ b/scripts/build-push-registry-667788.ps1 @@ -0,0 +1,68 @@ +# 构建并推送到 registry.667788.cool +# 用途:快速构建并推送镜像到指定 Registry + +$RegistryUrl = "registry.667788.cool" +$Namespace = "wecom-ai" +$Tag = "latest" + +Write-Host "=== 构建并推送到 registry.667788.cool ===" -ForegroundColor Cyan +Write-Host "" + +# 检查是否需要登录 +Write-Host "提示: 如果 Registry 需要认证,请先运行:" -ForegroundColor Yellow +Write-Host " docker login $RegistryUrl" -ForegroundColor Gray +Write-Host "" + +# 构建 Backend 镜像 +Write-Host "=== 构建 Backend 镜像 ===" -ForegroundColor Cyan +$backendImage = "${RegistryUrl}/${Namespace}/wecom-ai-backend:${Tag}" +Write-Host "镜像: $backendImage" -ForegroundColor Gray + +Write-Host "构建中..." -ForegroundColor Yellow +docker build -f deploy/docker/backend.Dockerfile -t $backendImage . +if ($LASTEXITCODE -ne 0) { + Write-Host "✗ Backend 构建失败" -ForegroundColor Red + Write-Host "提示: 如果无法连接 Docker Hub,请配置 Docker 镜像加速" -ForegroundColor Yellow + Write-Host "参考: docs/docker-mirror.md" -ForegroundColor Gray + exit 1 +} +Write-Host "✓ Backend 构建成功" -ForegroundColor Green + +Write-Host "推送中..." -ForegroundColor Yellow +docker push $backendImage +if ($LASTEXITCODE -ne 0) { + Write-Host "✗ Backend 推送失败" -ForegroundColor Red + Write-Host "提示: 请检查 Registry 是否需要登录" -ForegroundColor Yellow + exit 1 +} +Write-Host "✓ Backend 推送成功" -ForegroundColor Green +Write-Host "" + +# 构建 Admin 镜像 +Write-Host "=== 构建 Admin 镜像 ===" -ForegroundColor Cyan +$adminImage = "${RegistryUrl}/${Namespace}/wecom-ai-admin:${Tag}" +Write-Host "镜像: $adminImage" -ForegroundColor Gray + +Write-Host "构建中..." -ForegroundColor Yellow +docker build -f deploy/docker/admin.Dockerfile -t $adminImage . +if ($LASTEXITCODE -ne 0) { + Write-Host "✗ Admin 构建失败" -ForegroundColor Red + exit 1 +} +Write-Host "✓ Admin 构建成功" -ForegroundColor Green + +Write-Host "推送中..." -ForegroundColor Yellow +docker push $adminImage +if ($LASTEXITCODE -ne 0) { + Write-Host "✗ Admin 推送失败" -ForegroundColor Red + exit 1 +} +Write-Host "✓ Admin 推送成功" -ForegroundColor Green +Write-Host "" + +Write-Host "=== 完成 ===" -ForegroundColor Green +Write-Host "" +Write-Host "镜像已推送到:" -ForegroundColor Cyan +Write-Host " - $backendImage" -ForegroundColor Gray +Write-Host " - $adminImage" -ForegroundColor Gray +Write-Host ""