From b2478fb25b8785287687fc3c5baac659779f4a4b Mon Sep 17 00:00:00 2001 From: movingsam Date: Fri, 27 Feb 2026 21:11:13 +0800 Subject: [PATCH] =?UTF-8?q?chore(ci):=20=E6=B7=BB=E5=8A=A0=E9=9B=86?= =?UTF-8?q?=E4=B8=AD=E7=AE=A1=E7=90=86NuGet=E5=8C=85=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96GitHub=20Actions=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在Directory.Build.props和Directory.Packages.props中启用包版本集中管理 - 统一管理多个关键依赖项的版本号,包括Fengling服务发现、Microsoft和Serilog组件 - 重构YarpGateway.csproj从项目引用改为包引用以支持包版本集中管理 - 新增NuGet.Config文件配置企业私有源和官方源凭证 - 完善GitHub Actions工作流,添加.NET环境设置及依赖恢复 - 拆分构建、Docker构建推送及部署步骤,增加Kubernetes部署实现 - 支持push和pr触发,使用动态标签和metadata管理镜像版本 - 自动更新Kubernetes部署镜像标签并进行回滚状态检查与验证 --- .gitea/workflows/docker.yml | 126 +++++++++++++++++++++++++++++++----- Directory.Build.props | 1 + Directory.Packages.props | 27 ++++++++ NuGet.Config | 8 +++ YarpGateway.csproj | 10 +-- 5 files changed, 152 insertions(+), 20 deletions(-) create mode 100644 Directory.Packages.props create mode 100644 NuGet.Config diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml index 4aaab38..d9648c1 100644 --- a/.gitea/workflows/docker.yml +++ b/.gitea/workflows/docker.yml @@ -1,31 +1,97 @@ -name: Build and Push Docker +name: Build and Deploy on: push: - branches: [main] - tags: - - "v*" + branches: + - main + - master + pull_request: + branches: + - main + - master env: REGISTRY: gitea.shtao1.cn - IMAGE_NAME: fengling/fengling-gateway + IMAGE_NAME: ${{ gitea.repository }} + DOTNET_VERSION: '10.0' jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Configure NuGet + run: | + cat > NuGet.Config << 'NUGET' + + + + + + + + + + + + + + + NUGET + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release --no-restore + + - name: Publish + run: dotnet publish --configuration Release --no-build --output ./publish + + docker: + needs: build + runs-on: ubuntu-latest + if: gitea.event_name == 'push' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure NuGet for Docker + run: | + cat > NuGet.Config << 'NUGET' + + + + + + + + + + + + + + + NUGET + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Login to Gitea + + - name: Login to Gitea Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} - username: fengling + username: ${{ gitea.actor }} password: ${{ secrets.GITEATOKEN }} - + - name: Extract metadata id: meta uses: docker/metadata-action@v5 @@ -33,13 +99,43 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch - type=sha + type=sha,prefix= type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push + + - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + + deploy: + needs: docker + runs-on: ubuntu-latest + if: gitea.event_name == 'push' && (gitea.ref == 'refs/heads/main' || gitea.ref == 'refs/heads/master') + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up kubectl + uses: azure/setup-kubectl@v3 + + - name: Configure kubectl + run: | + mkdir -p ~/.kube + echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + + - name: Deploy to Kubernetes + run: | + TAG=$(echo ${{ gitea.sha }} | cut -c1-7) + sed -i "s|image:.*fengling-gateway.*|image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}|g" k8s/deployment.yaml + kubectl apply -f k8s/deployment.yaml -n fengling + kubectl apply -f k8s/service.yaml -n fengling + kubectl rollout status deployment/fengling-gateway -n fengling --timeout=300s + + - name: Verify deployment + run: | + kubectl get pods -n fengling -l app=fengling-gateway + kubectl get services -n fengling fengling-gateway diff --git a/Directory.Build.props b/Directory.Build.props index 8afc290..7106f5c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,6 @@ + true enable enable diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..ee290df --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,27 @@ + + + true + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..62a0353 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/YarpGateway.csproj b/YarpGateway.csproj index a8c1728..576fbc5 100644 --- a/YarpGateway.csproj +++ b/YarpGateway.csproj @@ -21,11 +21,11 @@ - - - - - + + + + +