From 6f61b95795d1f7c447e49bcdaaa7b9210914e97e Mon Sep 17 00:00:00 2001 From: Lyda <1829913225@qq.com> Date: Wed, 20 Aug 2025 17:26:15 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20Web=20=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=8F=91=E5=B8=83=E6=9E=84=E5=BB=BA=E7=9A=84=20GitHub?= =?UTF-8?q?=20Action=EF=BC=8C=E7=AE=80=E5=8C=96=20Docker=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84=E8=BE=93=E5=85=A5=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=92=8C=E6=AD=A5=E9=AA=A4=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E4=BF=A1=E6=81=AF=E4=BB=A5=E6=8F=90=E9=AB=98=E5=8F=AF?= =?UTF-8?q?=E8=AF=BB=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release-web/action.yml | 110 +----------------- release-web/examples/basic-release.yml | 1 - release-web/examples/custom-docker-tags.yml | 64 ---------- .../examples/environment-variables.yml | 3 - release-web/examples/full-cicd.yml | 28 ----- release-web/examples/multi-environment.yml | 66 +---------- 6 files changed, 7 insertions(+), 265 deletions(-) delete mode 100644 release-web/examples/custom-docker-tags.yml diff --git a/release-web/action.yml b/release-web/action.yml index 6cccb4b..88e08a2 100644 --- a/release-web/action.yml +++ b/release-web/action.yml @@ -1,9 +1,9 @@ name: 'Web项目发布构建' -description: '自动化Web项目发布流程,包括版本发布、Docker镜像构建和推送' +description: '自动化Web项目发布流程,支持版本管理和发布' author: 'Your Organization' branding: - icon: 'upload-cloud' + icon: 'tag' color: 'green' inputs: @@ -22,31 +22,6 @@ inputs: required: false default: 'npm run release -- --release -V' - docker-registry: - description: 'Docker仓库地址' - required: false - default: 'docker-registry.bjxgj.com' - - docker-context: - description: 'Docker构建上下文路径' - required: false - default: '.' - - dockerfile-path: - description: 'Dockerfile路径' - required: false - default: './container/dev/Dockerfile' - - docker-tags: - description: '额外的Docker标签 (每行一个标签)' - required: false - default: '' - - enable-docker-build: - description: '是否执行Docker构建 (true/false)' - required: false - default: 'true' - node-debug: description: '是否启用Node.js调试模式 (true/false)' required: false @@ -60,14 +35,6 @@ outputs: version-with-dash: description: '版本号(点号替换为横线)' value: ${{ steps.get_var.outputs.version_with_dash }} - - docker-image-digest: - description: 'Docker镜像摘要' - value: ${{ steps.build.outputs.digest }} - - docker-image-tags: - description: 'Docker镜像标签列表' - value: ${{ steps.build.outputs.tags }} runs: using: 'composite' @@ -82,13 +49,6 @@ runs: exit 1 fi - if [[ "${{ inputs.enable-docker-build }}" == "true" ]]; then - if [[ ! -f "${{ inputs.dockerfile-path }}" ]]; then - echo "❌ 错误: Dockerfile 不存在: ${{ inputs.dockerfile-path }}" - exit 1 - fi - fi - echo "✅ 参数验证通过" - name: 发布构建 @@ -124,57 +84,6 @@ runs: echo "📦 发布版本: $VERSION" echo "📦 带横线版本: $VERSION_WITH_DASH" - - name: 准备Docker标签 - if: ${{ inputs.enable-docker-build == 'true' }} - id: docker_tags - shell: bash - run: | - echo "🏷️ 准备Docker标签..." - - REPO_NAME="${{ github.event.repository.name }}" - REGISTRY="${{ inputs.docker-registry }}" - VERSION="${{ steps.get_var.outputs.version }}" - - # 基础标签(保留版本标签) - TAGS="${TAGS}\n${REGISTRY}/${REPO_NAME}:${VERSION}" - - # 添加用户自定义标签 - if [[ -n "${{ inputs.docker-tags }}" ]]; then - while IFS= read -r tag; do - if [[ -n "$tag" ]]; then - # 如果标签不包含仓库地址,则添加默认仓库前缀 - if [[ "$tag" != *"/"* ]]; then - TAGS="${TAGS}\n${REGISTRY}/${REPO_NAME}:${tag}" - else - TAGS="${TAGS}\n${tag}" - fi - fi - done <<< "${{ inputs.docker-tags }}" - fi - - echo "Docker标签列表:" - echo -e "$TAGS" | sed 's/^/ - /' - - # 将标签转换为多行格式供后续步骤使用 - echo -e "$TAGS" > /tmp/docker-tags.txt - - # 输出标签给后续步骤使用 - { - echo "tags<> $GITHUB_OUTPUT - - - name: 构建并推送Docker镜像 - if: ${{ inputs.enable-docker-build == 'true' }} - id: build - uses: docker/build-push-action@v6 - with: - context: ${{ inputs.docker-context }} - file: ${{ inputs.dockerfile-path }} - push: true - tags: ${{ steps.docker_tags.outputs.tags }} - - name: 发布总结 shell: bash run: | @@ -183,18 +92,3 @@ runs: echo "📋 发布信息:" echo " - 版本号: ${{ steps.get_var.outputs.version }}" echo " - 应用环境: ${{ inputs.app-env }}" - echo " - Sentry启用: ${{ inputs.enable-sentry }}" - echo "" - - if [[ "${{ inputs.enable-docker-build }}" == "true" ]]; then - echo "🐳 Docker信息:" - echo " - 仓库: ${{ inputs.docker-registry }}" - echo " - 项目名: ${{ github.event.repository.name }}" - echo " - 主要标签:" - echo " - ${{ steps.get_var.outputs.version }}" - if [[ -n "${{ steps.build.outputs.digest }}" ]]; then - echo " - 镜像摘要: ${{ steps.build.outputs.digest }}" - fi - else - echo "🐳 Docker构建已跳过" - fi diff --git a/release-web/examples/basic-release.yml b/release-web/examples/basic-release.yml index def6e27..b535a20 100644 --- a/release-web/examples/basic-release.yml +++ b/release-web/examples/basic-release.yml @@ -40,4 +40,3 @@ jobs: run: | echo "✅ 发布完成!" echo "📦 版本: ${{ steps.release.outputs.version }}" - echo "🐳 Docker镜像已推送到仓库" diff --git a/release-web/examples/custom-docker-tags.yml b/release-web/examples/custom-docker-tags.yml deleted file mode 100644 index 6d492a6..0000000 --- a/release-web/examples/custom-docker-tags.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: "自定义Docker标签发布" - -on: - push: - branches: - - main - - develop - workflow_dispatch: - inputs: - custom_tag: - description: "自定义Docker标签" - required: false - default: "manual" - -jobs: - release: - runs-on: ubuntu-latest - name: "发布项目(自定义标签)" - - steps: - - name: 检出代码 - uses: actions/checkout@v4 - with: - fetch-depth: 0 - token: ${{ secrets.GITEA_TOKEN }} - - - name: 设置构建环境 - uses: actions/xgj/setup-env@main - with: - docker-password: ${{ secrets.DOCKER_PASSWORD }} - skip-kubectl: "true" - - - name: 安装依赖 - uses: actions/xgj/npm-install@main - with: - package-manager: "pnpm" - - - name: 发布构建(带自定义标签) - id: release - uses: actions/xgj/release-web@main - with: - gitea-token: ${{ secrets.GITEA_TOKEN }} - app-env: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} - sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }} - sentry-dsn: ${{ vars.SENTRY_DSN }} - enable-sentry: "true" - docker-tags: | - ${{ github.sha }} - ${{ github.ref_name }} - ${{ github.event.inputs.custom_tag || 'auto' }} - stable - ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} - - - name: 显示所有Docker标签 - run: | - echo "🏷️ 生成的Docker标签包括:" - echo " - latest(默认)" - echo " - prod(默认)" - echo " - ${{ steps.release.outputs.version }}(版本标签,保留)" - echo " - ${{ github.sha }}(提交哈希)" - echo " - ${{ github.ref_name }}(分支名)" - echo " - ${{ github.event.inputs.custom_tag || 'auto' }}(自定义标签)" - echo " - stable(稳定版本)" - echo " - ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}(环境标签)" diff --git a/release-web/examples/environment-variables.yml b/release-web/examples/environment-variables.yml index 2743015..19e954c 100644 --- a/release-web/examples/environment-variables.yml +++ b/release-web/examples/environment-variables.yml @@ -58,9 +58,6 @@ jobs: uses: actions/xgj/release-web@main with: gitea-token: ${{ secrets.GITEA_TOKEN }} - docker-tags: | - env-example - ${{ github.ref_name }} env: # 🎯 根据分支设置不同的环境变量 APP_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} diff --git a/release-web/examples/full-cicd.yml b/release-web/examples/full-cicd.yml index fa2cc37..635a349 100644 --- a/release-web/examples/full-cicd.yml +++ b/release-web/examples/full-cicd.yml @@ -75,37 +75,9 @@ jobs: with: gitea-token: ${{ secrets.GITEA_TOKEN }} app-env: ${{ github.ref == 'refs/heads/main' && 'production' || 'develop' }} - sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }} - sentry-dsn: ${{ vars.SENTRY_DSN }} - enable-sentry: ${{ github.ref == 'refs/heads/main' && 'true' || 'false' }} - docker-registry: ${{ env.REGISTRY }} - dockerfile-path: "./Dockerfile" - docker-tags: | - ${{ github.sha }} - ${{ github.ref_name }} - ${{ github.ref == 'refs/heads/main' && 'stable' || 'unstable' }} - - - name: 部署到Kubernetes (生产环境) - if: github.ref == 'refs/heads/main' - run: | - echo "🚀 部署到生产环境..." - kubectl set image deployment/web-app \ - web-app=${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }} \ - -n production - kubectl rollout status deployment/web-app -n production - - - name: 部署到Kubernetes (开发环境) - if: github.ref == 'refs/heads/develop' - run: | - echo "🧪 部署到开发环境..." - kubectl set image deployment/web-app-dev \ - web-app=${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }} \ - -n development - kubectl rollout status deployment/web-app-dev -n development - name: 通知发布结果 run: | echo "🎉 发布完成!" echo "📦 版本: ${{ steps.release.outputs.version }}" echo "🌍 环境: ${{ github.ref == 'refs/heads/main' && '生产环境' || '开发环境' }}" - echo "🐳 Docker镜像: ${{ env.REGISTRY }}/${{ github.event.repository.name }}:${{ steps.release.outputs.version }}" diff --git a/release-web/examples/multi-environment.yml b/release-web/examples/multi-environment.yml index 41c1a93..dfe8fd2 100644 --- a/release-web/examples/multi-environment.yml +++ b/release-web/examples/multi-environment.yml @@ -22,7 +22,7 @@ on: - minor - major custom_tags: - description: "自定义Docker标签(每行一个)" + description: "自定义标签(每行一个)" required: false default: "" @@ -35,19 +35,13 @@ jobs: matrix: include: - environment: staging - dockerfile: "./container/dev/Dockerfile" app_env: "staging" - registry: "docker-registry.bjxgj.com" namespace: "staging" - environment: production - dockerfile: "./container/prod/Dockerfile" app_env: "production" - registry: "docker-registry.bjxgj.com" namespace: "production" - environment: testing - dockerfile: "./container/test/Dockerfile" app_env: "testing" - registry: "docker-registry.bjxgj.com" namespace: "testing" steps: @@ -60,8 +54,6 @@ jobs: - name: 设置构建环境 uses: actions/xgj/setup-env@main with: - docker-registry: ${{ matrix.registry }} - docker-password: ${{ secrets.DOCKER_PASSWORD }} kube-config: ${{ secrets.KUBE_CONFIG }} - name: 安装依赖 @@ -69,67 +61,26 @@ jobs: with: package-manager: "pnpm" - - name: 准备环境特定的标签 - id: env_tags - run: | - ENVIRONMENT="${{ github.event.inputs.environment }}" - VERSION_TYPE="${{ github.event.inputs.version_type }}" - CUSTOM_TAGS="${{ github.event.inputs.custom_tags }}" - - # 基础标签 - TAGS="${ENVIRONMENT}" - TAGS="${TAGS}\n${ENVIRONMENT}-${VERSION_TYPE}" - TAGS="${TAGS}\n$(date +%Y%m%d)-${ENVIRONMENT}" - - # 添加自定义标签 - if [[ -n "$CUSTOM_TAGS" ]]; then - while IFS= read -r tag; do - if [[ -n "$tag" ]]; then - TAGS="${TAGS}\n${tag}-${ENVIRONMENT}" - fi - done <<< "$CUSTOM_TAGS" - fi - - { - echo "tags<> $GITHUB_OUTPUT - - echo "🏷️ 环境特定标签:" - echo -e "$TAGS" | sed 's/^/ - /' - - name: 发布构建 id: release uses: actions/xgj/release-web@main with: gitea-token: ${{ secrets.GITEA_TOKEN }} app-env: ${{ matrix.app_env }} - sentry-auth-token: ${{ secrets.SENTRY_AUTH_TOKEN }} - sentry-dsn: ${{ vars.SENTRY_DSN }} - enable-sentry: ${{ matrix.environment == 'production' && 'true' || 'false' }} - docker-registry: ${{ matrix.registry }} - dockerfile-path: ${{ matrix.dockerfile }} release-command: "npm run release -- --release -V --increment ${{ github.event.inputs.version_type }}" - docker-tags: ${{ steps.env_tags.outputs.tags }} - - name: 部署到Kubernetes + - name: 部署应用 run: | ENVIRONMENT="${{ github.event.inputs.environment }}" VERSION="${{ steps.release.outputs.version }}" NAMESPACE="${{ matrix.namespace }}" - IMAGE="${{ matrix.registry }}/${{ github.event.repository.name }}:${VERSION}" echo "🚀 部署到 ${ENVIRONMENT} 环境..." echo "📦 版本: ${VERSION}" - echo "🐳 镜像: ${IMAGE}" echo "📍 命名空间: ${NAMESPACE}" - kubectl set image deployment/web-app \ - web-app=${IMAGE} \ - -n ${NAMESPACE} - - kubectl rollout status deployment/web-app -n ${NAMESPACE} + # 这里可以根据实际情况部署应用 + # 例如通过配置文件更新、API调用等方式 echo "✅ 部署完成!" @@ -141,11 +92,4 @@ jobs: echo " - 环境: ${{ github.event.inputs.environment }}" echo " - 版本: ${{ steps.release.outputs.version }}" echo " - 版本类型: ${{ github.event.inputs.version_type }}" - echo " - Docker仓库: ${{ matrix.registry }}" - echo " - Kubernetes命名空间: ${{ matrix.namespace }}" - echo "" - echo "🏷️ 主要标签:" - echo " - latest(默认)" - echo " - prod(默认)" - echo " - ${{ steps.release.outputs.version }}(版本标签)" - echo " - ${{ github.event.inputs.environment }}(环境标签)" + echo " - 命名空间: ${{ matrix.namespace }}"