ABP VNext + GitHub Actions:CI/CD 全流程自动化

🌟 ABP VNext + GitHub Actions:CI/CD 全流程自动化


📚 目录

  • 🌟 ABP VNext + GitHub Actions:CI/CD 全流程自动化
    • 🤩 TL;DR
    • 🔄 全局流程概览
    • 1️⃣ 准备工作与项目结构
      • 1.1 🛠️ 工具链与 Secrets
      • 1.2 📁 项目目录示例
    • 2️⃣ 🔨 Build & Test(并行编译与单测)
        • 🔄 子流程图
    • 3️⃣ 🕵️ Static Analysis(SonarCloud & CodeQL)
        • 🔄 子流程图
    • 4️⃣ 📦 Package & Publish(NuGet 与 Docker)
    • 5️⃣ 🚀 Deploy to Staging(预发布环境)
    • 6️⃣ 🏭 Deploy to Production(生产环境)
    • 7️⃣ ⏪ Rollback & Alert(自动回滚与告警)
      • Rollback Staging
      • Rollback Production
    • 🔧 ABP VNext 专属集成示例
      • Program.cs 示例
      • Helm Chart 探针示例 (`charts/myapp/values.yaml`)
    • 📦 附录:配置文件
      • sonar-project.properties
      • CodeQL 配置 (`.github/codeql/codeql-config.yml`)


🤩 TL;DR

  • 🚀 端到端流水线:Push → 并行编译/测试 → 静态扫描 (SonarCloud/CodeQL) → NuGet/Docker 打包 → 分环境部署 → 自动回滚
  • 🔒 严格审批:在 GitHub Environments 中分别为 stagingproduction 配置 Required Reviewers
  • 性能优化:NuGet 缓存、actions/cache、Docker Layer 缓存、并行 Jobs、Concurrency 控制
  • 🛠️ 深度契合 ABP VNext:自动执行 EF Core 迁移、Swagger/UI、Health Checks 与 AKS 探针

🔄 全局流程概览

Yes
No
Yes
No
🛎️ Push 代码
🔨 Build & Test
🕵️ Static Scan
📦 Package & Publish
🚀 Deploy to Staging
✅ Staging OK?
🏭 Deploy to Production
⏪ Rollback Staging
✅ Production OK?
🎉 完成
⏪ Rollback Production

1️⃣ 准备工作与项目结构

1.1 🛠️ 工具链与 Secrets

在仓库 Settings → Secrets 添加以下凭据:

  • AZURE_CREDENTIALS:Azure Service Principal JSON(az ad sp create-for-rbac … --sdk-auth
  • NUGET_API_KEY:NuGet.org 发布 Key
  • SONAR_TOKEN:SonarCloud Access Token
  • SLACK_WEBHOOK_URL:Slack Incoming Webhook URL
  • GITHUB_TOKEN(Actions 内置,用于 GHCR)

🎯 示例 CLI:

az ad sp create-for-rbac \--name "abp-ci-sp" \--role contributor \--scopes /subscriptions/<SUB_ID>/resourceGroups/<RG_NAME> \--sdk-auth > azure-credentials.json

1.2 📁 项目目录示例

.
├─ .github/workflows/ci-cd.yml
├─ src/
│    ├─ MyApp.Domain/
│    ├─ MyApp.Application/
│    ├─ MyApp.EntityFrameworkCore/
│    └─ MyApp.HttpApi.Host/
└─ tests/└─ MyApp.Tests/

2️⃣ 🔨 Build & Test(并行编译与单测)

📝 本 Job 目标:并行 Restore/Build/Test,上传测试报告

build-test:name: 🔨 Build & Testruns-on: ubuntu-lateststrategy:matrix:dotnet-version: ['8.0.x']steps:- name: Checkout Codeuses: actions/checkout@v3- name: Cache NuGet packagesuses: actions/cache@v3with:path: ~/.nuget/packageskey: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}restore-keys: ${{ runner.os }}-nuget-- name: Setup .NET SDKuses: actions/setup-dotnet@v3with:dotnet-version: ${{ matrix.dotnet-version }}cache: true- name: Restore Dependenciesrun: dotnet restore src/MyApp.sln --locked-mode- name: Build Solutionrun: dotnet build src/MyApp.sln --no-restore --configuration Release- name: Run Unit Testsrun: dotnet test tests/MyApp.Tests/MyApp.Tests.csproj \--no-build --configuration Release --logger "trx"- name: Upload Test Resultsuses: actions/upload-artifact@v3with:name: test-resultspath: '**/*.trx'retention-days: 7
🔄 子流程图
✅ Checkout
🗄️ Cache NuGet
📦 Setup SDK
🔄 Restore
🏗️ Build
🧪 Test
💾 Upload Artifacts

3️⃣ 🕵️ Static Analysis(SonarCloud & CodeQL)

📝 本 Job 目标:Shift‐Left 质量与安全保障

static-scan:name: 🕵️ Static Analysisruns-on: ubuntu-latestneeds: build-teststrategy:matrix:tool: ['sonarcloud','codeql']steps:- name: Checkout Full Historyuses: actions/checkout@v3with:fetch-depth: 0# SonarCloud- if: matrix.tool == 'sonarcloud'name: SonarCloud Prepareuses: SonarSource/sonarcloud-github-action@v1.9.0- if: matrix.tool == 'sonarcloud'name: Build for SonarCloudrun: dotnet build src/MyApp.sln --configuration Release- if: matrix.tool == 'sonarcloud'name: SonarCloud Publishuses: SonarSource/sonarcloud-github-action@v1.9.0# CodeQL- if: matrix.tool == 'codeql'name: Initialize CodeQLuses: github/codeql-action/init@v2with:languages: csharpconfig-file: .github/codeql/codeql-config.yml- if: matrix.tool == 'codeql'name: Autobuilduses: github/codeql-action/autobuild@v2- if: matrix.tool == 'codeql'name: Perform CodeQL Analysisuses: github/codeql-action/analyze@v2
🔄 子流程图
SonarCloud
CodeQL
👥 Checkout
🔍 Tool?
📊 Run SonarCloud
⚙️ Init CodeQL
🚧 Autobuild
🔎 Analyze

4️⃣ 📦 Package & Publish(NuGet 与 Docker)

📝 本 Job 目标:仅在 Push 时执行包与镜像发布

package-publish:name: 📦 Package & Publishif: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')runs-on: ubuntu-latestneeds: static-scansteps:- name: Checkout Codeuses: actions/checkout@v3# NuGet- name: Pack NuGet Packagerun: dotnet pack src/MyApp.Application/MyApp.Application.csproj \--no-build -o ./artifacts- uses: NuGet/setup-nuget@v2- name: Push to NuGet.orgrun: dotnet nuget push ./artifacts/*.nupkg \--api-key ${{ secrets.NUGET_API_KEY }} \--source https://api.nuget.org/v3/index.json# Docker (GHCR)- name: Login to GHCRuses: docker/login-action@v3with:registry: ghcr.iousername: ${{ github.repository_owner }}password: ${{ secrets.GITHUB_TOKEN }}- name: Build & Push Docker Imageuses: docker/build-push-action@v4with:context: src/MyApp.HttpApi.Hostfile: src/MyApp.HttpApi.Host/Dockerfilepush: truetags: |ghcr.io/${{ github.repository_owner }}/myapp:${{ github.sha }}ghcr.io/${{ github.repository_owner }}/myapp:latestcache-from: type=gha,scope=src-MyApp.HttpApi.Hostcache-to: type=gha,mode=max,scope=src-MyApp.HttpApi.Host

5️⃣ 🚀 Deploy to Staging(预发布环境)

📝 本 Job 目标:在 develop 分支推送时执行,需审批

deploy-staging:name: 🚀 Deploy to Stagingruns-on: ubuntu-latestneeds: package-publishif: github.ref == 'refs/heads/develop'environment: stagingsteps:- name: Azure Loginuses: azure/login@v1with:creds: ${{ secrets.AZURE_CREDENTIALS }}- name: Set AKS Contextuses: azure/aks-set-context@v2with:creds: ${{ secrets.AZURE_CREDENTIALS }}cluster-name: myClusterresource-group: myRG- name: Install EF CLIrun: |dotnet tool install --global dotnet-ef --version 8.* echo "$HOME/.dotnet/tools" >> $GITHUB_PATH- name: Run EF Core Migrationsrun: dotnet ef database update \--project src/MyApp.EntityFrameworkCore/MyApp.EntityFrameworkCore.csproj \--startup-project src/MyApp.HttpApi.Host/MyApp.HttpApi.Host.csproj \--configuration Release- name: Helm Upgrade (Staging)run: |helm upgrade myapp-staging ./charts/myapp \--namespace staging --install \--set image.tag=${{ github.sha }}

6️⃣ 🏭 Deploy to Production(生产环境)

📝 本 Job 目标:在 main 分支推送时执行,需审批

deploy-prod:name: 🏭 Deploy to Productionruns-on: ubuntu-latestneeds: deploy-stagingif: github.ref == 'refs/heads/main'environment: productionsteps:- name: Azure Loginuses: azure/login@v1with:creds: ${{ secrets.AZURE_CREDENTIALS }}- name: Set AKS Contextuses: azure/aks-set-context@v2with:creds: ${{ secrets.AZURE_CREDENTIALS }}cluster-name: myClusterresource-group: myRG- name: Helm Upgrade (Production)run: |helm upgrade myapp-prod ./charts/myapp \--namespace prod --install \--set image.tag=${{ github.sha }}

7️⃣ ⏪ Rollback & Alert(自动回滚与告警)

Rollback Staging

rollback-staging:name: ⏪ Rollback & Notify (Staging)if: failure() && github.ref == 'refs/heads/develop'runs-on: ubuntu-latestneeds: deploy-stagingsteps:- name: Determine Last Successful Revisionid: histrun: |rev=$(helm history myapp-staging -n staging --max 5 \--output json | jq -r '.[] | select(.status=="DEPLOYED") | .revision' | tail -1)if [[ -z "$rev" || "$rev" -le 0 ]]; thenecho "No valid revision to rollback"; exit 1fiecho "::set-output name=revision::$rev"- name: Helm Rollback (Staging)run: helm rollback myapp-staging ${{ steps.hist.outputs.revision }} -n staging- name: Slack Notificationuses: rtCamp/action-slack-notify@v2with:webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}message: ":warning: Staging 部署失败,已回滚到 revision ${{ steps.hist.outputs.revision }}"

Rollback Production

rollback-prod:name: ⏪ Rollback & Notify (Production)if: failure() && github.ref == 'refs/heads/main'runs-on: ubuntu-latestneeds: deploy-prodsteps:- name: Determine Last Successful Revisionid: histrun: |rev=$(helm history myapp-prod -n prod --max 5 \--output json | jq -r '.[] | select(.status=="DEPLOYED") | .revision' | tail -1)if [[ -z "$rev" || "$rev" -le 0 ]]; thenecho "No valid revision to rollback"; exit 1fiecho "::set-output name=revision::$rev"- name: Helm Rollback (Production)run: helm rollback myapp-prod ${{ steps.hist.outputs.revision }} -n prod- name: Slack Notificationuses: rtCamp/action-slack-notify@v2with:webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}message: ":x: Production 部署失败,已回滚到 revision ${{ steps.hist.outputs.revision }}"

🔧 ABP VNext 专属集成示例

Program.cs 示例

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApplication<MyAppHttpApiHostModule>();
builder.Host.UseAutofac();var app = builder.Build();
app.UseAbpRequestLocalization();
app.UseAbpSwaggerUI(options =>
{options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyApp API V1");
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapHealthChecks("/health");
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{Predicate = reg => reg.Name.Contains("ready")
});
app.Run();

Helm Chart 探针示例 (charts/myapp/values.yaml)

livenessProbe:httpGet:path: /healthport: httpinitialDelaySeconds: 30readinessProbe:httpGet:path: /health/readyport: httpinitialDelaySeconds: 10

📦 附录:配置文件

sonar-project.properties

sonar.projectKey=<YOUR_PROJECT_KEY>
sonar.organization=<YOUR_ORGANIZATION>
sonar.sources=src
sonar.tests=tests
sonar.dotnet.visualstudio.solution.file=src/MyApp.sln

CodeQL 配置 (.github/codeql/codeql-config.yml)

queries:- security-and-quality- security-and-performance

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/89729.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/89729.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Elasticsearch 重命名索引

作者&#xff1a;来自 Elastic Alex Salgado 学习如何使用四种实用方法在 Elasticsearch 中重命名索引。 想获得 Elastic 认证&#xff1f;看看下一期 Elasticsearch Engineer 培训什么时候开始&#xff01; Elasticsearch 拥有丰富的新功能&#xff0c;帮助你根据使用场景构建…

高通8255 Android Virtio Virtio-SPI 配置方法

目录 一&#xff1a;VirtIO和Passthrough的区别 二&#xff1a;配置逻辑 三&#xff1a;配置方法 步骤一&#xff1a;QNX SPI资源配置 & 测试 配置 测试 步骤二&#xff1a;BE配置 &测试 配置 测试 步骤三&#xff1a;Hypervisor配置 配置 测试 步骤四&…

从零手写红黑树(C++实现详解)

目录 一、红黑树概述 二、红黑树节点设计 (1)枚举红黑 &#xff08;2&#xff09;红黑树的节点设计 三、红黑树核心实现:Insert 1.首先将节点遍历到对应位置创建对应节点并插入到二叉搜索树对应的位置 2.本文重点的重点 &#xff08;1&#xff09;parent为黑时直接插入即…

【黄山派-SF32LB52】—硬件原理图学习笔记

目录 一、硬件介绍 二、芯片主控 1.模组介绍 2.原理图介绍 3.模组供电电路 三、电源转换部分 1.OVP过压保护电路 2.CHG充电电路 3.系统电源桥接电路 4.LDO电路 四、Debug电路 1.一键下载电路 五、QSPI屏幕 六、SD卡 七、AUDIO音频 八、GPIO电路 1.按键部分…

从五次方程到计算机:数学抽象如何塑造现代计算

引言 数学的发展往往始于一个具体的问题&#xff0c;而后在寻求解答的过程中&#xff0c;催生出深刻的抽象理论。从五次方程的求解到抽象代数&#xff0c;再到范畴论和λ演算&#xff0c;最终影响图灵机和现代计算机的设计&#xff0c;这一历程展现了数学如何从实际问题演变为通…

剧本杀小程序开发:科技赋能,重塑推理娱乐新形态

在科技飞速发展的今天&#xff0c;各个行业都在积极探索与科技的融合&#xff0c;以实现创新发展。剧本杀行业也不例外&#xff0c;剧本杀小程序的开发&#xff0c;正是科技赋能传统娱乐的生动体现&#xff0c;它重塑了推理娱乐的新形态&#xff0c;为玩家带来了前所未有的游戏…

机器学习sklearn入门:归一化和标准化

bg&#xff1a;归一化&#xff08;Normalization&#xff09;通常指将数据按比例缩放至某个特定范围&#xff0c;但具体范围并不一定是固定的 0到1。标准化是将数据转换成均值为0&#xff0c;标准差为1的分布。使用场景&#xff1a;用归一化&#xff1a;需要严格限定范围&#…

【Project】kafka+flume+davinci广告点击实时分析系统

一、项目需求分析 某电商平台需实现广告实时点击分析系统&#xff0c;核心需求为实时统计以下内容的Top10&#xff1a; 各个广告的点击量各个省份的广告点击量各个城市的广告点击量 通过实时掌握广告投放效果&#xff0c;为广告投放策略调整和大规模投入提供依据&#xff0c;以…

JAVA后端开发——success(data) vs toAjax(rows): 何时用

toAjax(int rows)用途&#xff1a;用于不返回任何数据的 “写” 操作&#xff08;增、删、改&#xff09;。工作原理&#xff1a;它只接收一个 int 类型的参数&#xff08;通常是数据库操作影响的行数&#xff09;。它只关心这个数字是不是大于0&#xff0c;然后返回一个通用的…

pdf格式怎么提取其中一部分张页?

想从PDF里提取几个页面&#xff0c;办法还挺多的&#xff0c;下面给你唠唠常见的几种&#xff0c;保准你一看就懂。一、用专业PDF编辑软件提取 像Adobe Acrobat&#xff0c;这可是PDF编辑界的“老手”了。你先把要处理的PDF文件在Adobe Acrobat里打开&#xff0c;接着找到菜单栏…

Spring监听器

1、监听器的原理 ApplicationListener<T>是Spring框架中基于观察者模式实现的事件监听接口&#xff0c;用于监听应用程序中特定类型的事件。该接口是一个函数式接口&#xff0c;从Spring 4.2开始支持Lambda表达式实现。 接口定义如下&#xff1a; FunctionalInterface …

基于Rust游戏引擎实践(Game)

Rust游戏引擎推荐 以下是一些流行的Rust游戏引擎,适用于不同开发需求: Bevy 特点:数据驱动、模块化设计,支持ECS架构,适合初学者和复杂项目。 适用场景:2D/3D游戏、原型开发。 Amethyst 特点:成熟的ECS框架,支持多线程,社区活跃。 适用场景:大型游戏或高性能应用。…

PyTorch 数据加载实战:从 CSV 到图像的全流程解析

目录 一、PyTorch 数据加载的核心组件 1.1 Dataset 类的核心方法 1.2 DataLoader 的作用 二、加载 CSV 数据实战 2.1 自定义 CSV 数据集 2.2 使用 TensorDataset 快速加载 三、加载图像数据实战 3.1 自定义图像数据集 3.2 使用 ImageFolder 快速加载 四、加载官方数据…

程序人生,开启2025下半年

时光匆匆&#xff0c;2025年已然过去一半。转眼来到了7月份。 回望过去上半年&#xff0c;可能你也经历了职场的浮沉、生活的跌宕、家庭的变故。 而下半年&#xff0c;生活依旧充满了各种变数。 大环境的起起伏伏、生活节奏的加快&#xff0c;都让未来的不确定性愈发凸显。 在这…

在 .NET Core 中创建 Web Socket API

要在 ASP.NET Core 中创建 WebSocket API&#xff0c;您可以按照以下步骤操作&#xff1a;设置新的 ASP.NET Core 项目打开 Visual Studio 或您喜欢的 IDE。 创建一个新的 ASP.NET Core Web 应用程序项目。 选择API模板&#xff0c;因为这将成为您的 WebSocket API 的基础。在启…

Python 之地址编码识别

根据输入地址&#xff0c;利用已有的地址编码文件&#xff0c;构造处理规则策略识别地址的编码。 lib/address.json 地址编码文件&#xff08;这个文件太大&#xff0c;博客里放不下&#xff0c;需要的话可以到 gitcode 仓库获取&#xff1a;https://gitcode.com/TomorrowAndT…

kafka的部署

目录 一、kafka简介 1.1、概述 1.2、消息系统介绍 1.3、点对点消息传递模式 1.4、发布-订阅消息传递模式 二、kafka术语解释 2.1、结构概述 2.2、broker 2.3、topic 2.4、producer 2.5、consumer 2.6、consumer group 2.7、leader 2.8、follower 2.9、partition…

小语种OCR识别技术实现原理

小语种OCR&#xff08;光学字符识别&#xff09;技术的实现原理涉及计算机视觉、自然语言处理&#xff08;NLP&#xff09;和深度学习等多个领域的融合&#xff0c;其核心目标是让计算机能够准确识别并理解不同语言的印刷或手写文本。以下是其关键技术实现原理的详细解析&#…

GPT:让机器拥有“创造力”的语言引擎

当ChatGPT写出莎士比亚风格的十四行诗&#xff0c;当GitHub Copilot自动生成编程代码&#xff0c;背后都源于同一项革命性技术——**GPT&#xff08;Generative Pre-trained Transformer&#xff09;**。今天&#xff0c;我们将揭开这项“语言魔术”背后的科学原理&#xff01;…

LeetCode|Day19|14. 最长公共前缀|Python刷题笔记

LeetCode&#xff5c;Day19&#xff5c;14. 最长公共前缀&#xff5c;Python刷题笔记 &#x1f5d3;️ 本文属于【LeetCode 简单题百日计划】系列 &#x1f449; 点击查看系列总目录 >> &#x1f4cc; 题目简介 题号&#xff1a;14. 最长公共前缀 难度&#xff1a;简单…