Skip to content

Phase 2: CI/CD 部署 ​

完成时间:2026 年初

概述 ​

使用 GitHub Actions 实现自动化构建和部署,镜像推送到阿里云 ACR,服务器端使用 Watchtower 自动更新。

子阶段 ​

2.1 GitHub Actions 配置 ​

配置自动化工作流,包括构建、推送镜像等步骤。

  • .github/workflows/deploy.yml 工作流配置

2.2 阿里云 ACR 集成 ​

创建 ACR 实例、绑定代码源、创建镜像仓库。

2.3 服务器部署与 Watchtower ​

配置服务器端 docker-compose.yml,Watchtower 每 5 分钟自动检查更新。

完整流程 ​

mermaid
graph LR
    A[Push to main] --> B[GitHub Actions]
    B --> C[Build Docker Image]
    C --> D[Push to ACR]
    D --> E[Watchtower Pull]
    E --> F[Restart Container]

踩坑记录 ​

insufficient_scope 错误 ​

问题描述

推送镜像时报错:push access denied, insufficient_scope

解决方案

GitHub Secrets 中的 ACR_REGISTRY 配置错误,只需填写 ACR 实例地址,不要包含命名空间和仓库路径。 参考 绑定阿里云 ACR

Released under the MIT License.