# 私有仓库和 Docker Registry 配置指南 ## 概述 项目已配置为使用私有 Git 仓库和私有 Docker Registry: - **Git 仓库**: https://git.quanyu360.cn/admin/wecom-ai-assistant - **Docker Registry**: git.quanyu360.cn ## 配置信息 ### Git 仓库配置 - **远程名称**: `private` - **仓库地址**: https://git.quanyu360.cn/admin/wecom-ai-assistant.git - **用户名**: admin - **密码**: 已配置(存储在 Git 凭据中) ### Docker Registry 配置 配置文件:`.registry-config`(不提交到 Git) ```bash REGISTRY_URL=git.quanyu360.cn REGISTRY_USERNAME=admin REGISTRY_PASSWORD=ye972030 REGISTRY_NAMESPACE=wecom-ai BACKEND_IMAGE_NAME=wecom-ai-backend ADMIN_IMAGE_NAME=wecom-ai-admin ``` ## 使用方法 ### 1. 推送代码到私有仓库 #### 默认推送到私有仓库 ```powershell # 使用脚本(推荐) .\scripts\push-to-private-repo.ps1 # 或手动推送 git push private main ``` #### 推送到 GitHub ```powershell # 使用脚本 .\scripts\push-to-private-repo.ps1 -PushToGitHub # 或手动推送 git push origin main ``` #### 推送到两个仓库 ```powershell # 使用脚本 .\scripts\push-to-private-repo.ps1 -PushToBoth # 或手动推送 git push private main git push origin main ``` ### 2. 构建并推送 Docker 镜像 #### 测试 Registry 连接 ```powershell .\scripts\test-registry-connection.ps1 ``` #### 推送所有镜像 ```powershell # 推送所有镜像(backend + admin) .\scripts\push-images-to-private-registry.ps1 -BuildAll # 或指定标签 .\scripts\push-images-to-private-registry.ps1 -BuildAll -Tag v1.0.0 ``` #### 只推送 Backend 镜像 ```powershell .\scripts\push-images-to-private-registry.ps1 -BuildBackend ``` #### 只推送 Admin 镜像 ```powershell .\scripts\push-images-to-private-registry.ps1 -BuildAdmin ``` ### 3. 在生产环境使用私有镜像 更新 `docker-compose.prod.yml` 中的环境变量: ```bash # 在 .env.prod 中设置 REGISTRY_URL=git.quanyu360.cn REGISTRY_NAMESPACE=wecom-ai IMAGE_TAG=latest ``` 或在服务器上登录 Registry: ```bash docker login git.quanyu360.cn -u admin -p ye972030 ``` 然后使用 docker-compose 部署: ```bash docker-compose -f docker-compose.prod.yml --env-file .env.prod up -d ``` ## 镜像命名规则 推送后的镜像地址: - **Backend**: `git.quanyu360.cn/wecom-ai/wecom-ai-backend:latest` - **Admin**: `git.quanyu360.cn/wecom-ai/wecom-ai-admin:latest` ## 验证配置 ### 检查 Git 远程仓库 ```powershell git remote -v ``` 应该看到: - `origin` → GitHub 仓库 - `private` → 私有仓库 ### 检查 Docker Registry 登录 ```powershell docker login git.quanyu360.cn -u admin -p ye972030 ``` ### 测试 Registry 连接 ```powershell .\scripts\test-registry-connection.ps1 ``` ## 更新配置 ### 修改 Registry 配置 编辑 `.registry-config` 文件: ```bash REGISTRY_URL=新的registry地址 REGISTRY_USERNAME=新的用户名 REGISTRY_PASSWORD=新的密码 ``` ### 修改 Git 远程仓库 ```powershell # 更新私有仓库地址 git remote set-url private https://admin:password@git.quanyu360.cn/admin/wecom-ai-assistant.git # 验证 git remote -v ``` ## 安全建议 1. **配置文件安全**: - `.registry-config` 已添加到 `.gitignore` - 不要将密码提交到 Git - 定期更新密码 2. **Docker 凭据**: - 使用 Docker Credential Helper 存储凭据 - 或在 CI/CD 中使用 Secrets 3. **访问控制**: - 限制 Registry 访问权限 - 使用只读用户进行拉取操作 ## 故障排查 ### 问题:Docker 登录失败 **检查项**: 1. Registry URL 是否正确 2. 用户名和密码是否正确 3. Registry 服务是否正常运行 4. 网络连接是否正常 ### 问题:推送镜像失败 **解决方案**: 1. 确认已登录 Registry 2. 检查镜像名称格式是否正确 3. 确认有推送权限 ### 问题:Git 推送失败 **解决方案**: 1. 检查远程仓库地址是否正确 2. 确认用户名和密码正确 3. 检查网络连接 ## 相关文档 - [Docker Registry 文档](https://docs.docker.com/registry/) - [Git 远程仓库文档](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes)