fix(ci): 合并构建和部署步骤解决产物共享问题
问题: - build-artifacts和deploy-production在不同容器运行 - 构建产物无法共享,导致部署步骤被取消 修复: - 将构建和部署合并为build-and-deploy单一步骤 - 确保构建产物在同一容器内可用于部署 - 简化CI流程,修复步骤依赖关系
This commit is contained in:
+20
-63
@@ -16,7 +16,7 @@
|
|||||||
#
|
#
|
||||||
# 3. release/** 分支:生产环境代码
|
# 3. release/** 分支:生产环境代码
|
||||||
# - 触发:push
|
# - 触发:push
|
||||||
# - 执行:代码检查 + 构建产物 + 同步部署
|
# - 执行:代码检查 + 构建部署一体化
|
||||||
# - 部署到:生产环境(139.155.109.62)
|
# - 部署到:生产环境(139.155.109.62)
|
||||||
# - 归档到:main分支
|
# - 归档到:main分支
|
||||||
#
|
#
|
||||||
@@ -27,11 +27,10 @@
|
|||||||
# 流水线阶段:
|
# 流水线阶段:
|
||||||
# 阶段0: 依赖安装(统一缓存)
|
# 阶段0: 依赖安装(统一缓存)
|
||||||
# 阶段1: 并行代码质量检查 (lint, type-check, security-scan)
|
# 阶段1: 并行代码质量检查 (lint, type-check, security-scan)
|
||||||
# 阶段2: 单元测试 -> E2E测试 (允许失败)
|
# 阶段2: 测试 (unit-tests, e2e-tests - 仅dev分支)
|
||||||
# 阶段3: 构建生产产物 (仅release分支)
|
# 阶段3: 构建并部署到生产环境 (release分支,一体化)
|
||||||
# 阶段4: 同步产物到生产服务器并部署 (仅release分支)
|
# 阶段4: 归档到main分支 (release分支)
|
||||||
# 阶段5: 归档到main分支 (仅release分支)
|
# 阶段5: 企业微信通知
|
||||||
# 阶段6: 企业微信通知
|
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
@@ -54,11 +53,6 @@ steps:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
branch:
|
|
||||||
- feature/**
|
|
||||||
- dev
|
|
||||||
- release
|
|
||||||
- release/**
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# 阶段1: 并行代码质量检查
|
# 阶段1: 并行代码质量检查
|
||||||
@@ -78,11 +72,6 @@ steps:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
branch:
|
|
||||||
- feature/**
|
|
||||||
- dev
|
|
||||||
- release
|
|
||||||
- release/**
|
|
||||||
|
|
||||||
type-check:
|
type-check:
|
||||||
image: *node_image
|
image: *node_image
|
||||||
@@ -99,11 +88,6 @@ steps:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
branch:
|
|
||||||
- feature/**
|
|
||||||
- dev
|
|
||||||
- release
|
|
||||||
- release/**
|
|
||||||
|
|
||||||
security-scan:
|
security-scan:
|
||||||
image: *node_image
|
image: *node_image
|
||||||
@@ -121,11 +105,6 @@ steps:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
branch:
|
|
||||||
- feature/**
|
|
||||||
- dev
|
|
||||||
- release
|
|
||||||
- release/**
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# 阶段2: 测试 (仅dev分支,允许失败)
|
# 阶段2: 测试 (仅dev分支,允许失败)
|
||||||
@@ -177,44 +156,25 @@ steps:
|
|||||||
- dev
|
- dev
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# 阶段3: 构建生产产物 (release分支)
|
# 阶段3: 构建并部署到生产环境 (仅release分支)
|
||||||
# ============================================
|
# ============================================
|
||||||
build-artifacts:
|
build-and-deploy:
|
||||||
image: *node_image
|
image: *node_image
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
NEXT_TELEMETRY_DISABLED: 1
|
NEXT_TELEMETRY_DISABLED: 1
|
||||||
|
SSH_PRIVATE_KEY:
|
||||||
|
from_secret: ssh_private_key
|
||||||
depends_on:
|
depends_on:
|
||||||
- lint
|
- lint
|
||||||
- type-check
|
- type-check
|
||||||
commands:
|
commands:
|
||||||
- echo "Building production artifacts..."
|
- echo "=== Step 1: 构建生产产物 ==="
|
||||||
- npm run build
|
- npm run build
|
||||||
- echo "✅ Build completed"
|
- echo "✅ 构建完成"
|
||||||
- ls -la dist/
|
- ls -la dist/
|
||||||
volumes:
|
|
||||||
- /tmp/npm-cache:/root/.npm
|
|
||||||
- /tmp/node-modules-cache:/woodpecker/src/node_modules
|
|
||||||
when:
|
|
||||||
event:
|
|
||||||
- push
|
|
||||||
branch:
|
|
||||||
- release
|
|
||||||
- release/**
|
|
||||||
|
|
||||||
# ============================================
|
- echo "=== Step 2: 部署到生产环境 ==="
|
||||||
# 阶段4: 部署到生产环境 (release分支)
|
|
||||||
# ============================================
|
|
||||||
deploy-production:
|
|
||||||
image: alpine/git:latest
|
|
||||||
environment:
|
|
||||||
DEPLOY_ENV: production
|
|
||||||
SSH_PRIVATE_KEY:
|
|
||||||
from_secret: ssh_private_key
|
|
||||||
depends_on:
|
|
||||||
- build-artifacts
|
|
||||||
commands:
|
|
||||||
- echo "Deploying to production environment..."
|
|
||||||
- mkdir -p ~/.ssh
|
- mkdir -p ~/.ssh
|
||||||
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
- chmod 600 ~/.ssh/id_rsa
|
- chmod 600 ~/.ssh/id_rsa
|
||||||
@@ -244,7 +204,10 @@ steps:
|
|||||||
chmod +x scripts/deploy-production.sh
|
chmod +x scripts/deploy-production.sh
|
||||||
./scripts/deploy-production.sh
|
./scripts/deploy-production.sh
|
||||||
EOF
|
EOF
|
||||||
- echo "✅ Production deployment completed!"
|
- echo "✅ 生产环境部署完成!"
|
||||||
|
volumes:
|
||||||
|
- /tmp/npm-cache:/root/.npm
|
||||||
|
- /tmp/node-modules-cache:/woodpecker/src/node_modules
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
@@ -253,7 +216,7 @@ steps:
|
|||||||
- release/**
|
- release/**
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# 阶段5: 归档到main分支 (release分支)
|
# 阶段4: 归档到main分支 (仅release分支)
|
||||||
# ============================================
|
# ============================================
|
||||||
archive-to-main:
|
archive-to-main:
|
||||||
image: alpine/git:latest
|
image: alpine/git:latest
|
||||||
@@ -261,7 +224,7 @@ steps:
|
|||||||
SSH_PRIVATE_KEY:
|
SSH_PRIVATE_KEY:
|
||||||
from_secret: ssh_private_key
|
from_secret: ssh_private_key
|
||||||
depends_on:
|
depends_on:
|
||||||
- deploy-production
|
- build-and-deploy
|
||||||
commands:
|
commands:
|
||||||
- echo "Archiving to main branch..."
|
- echo "Archiving to main branch..."
|
||||||
- mkdir -p ~/.ssh
|
- mkdir -p ~/.ssh
|
||||||
@@ -303,11 +266,9 @@ steps:
|
|||||||
branch:
|
branch:
|
||||||
- release
|
- release
|
||||||
- release/**
|
- release/**
|
||||||
status:
|
|
||||||
- success
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# 阶段6: 企业微信通知
|
# 阶段5: 企业微信通知
|
||||||
# ============================================
|
# ============================================
|
||||||
notify-wechat-success:
|
notify-wechat-success:
|
||||||
image: curlimages/curl:latest
|
image: curlimages/curl:latest
|
||||||
@@ -324,8 +285,6 @@ steps:
|
|||||||
branch:
|
branch:
|
||||||
- release
|
- release
|
||||||
- release/**
|
- release/**
|
||||||
status:
|
|
||||||
- success
|
|
||||||
|
|
||||||
notify-wechat-failure:
|
notify-wechat-failure:
|
||||||
image: curlimages/curl:latest
|
image: curlimages/curl:latest
|
||||||
@@ -333,7 +292,7 @@ steps:
|
|||||||
WECHAT_WEBHOOK:
|
WECHAT_WEBHOOK:
|
||||||
from_secret: wechat_webhook
|
from_secret: wechat_webhook
|
||||||
depends_on:
|
depends_on:
|
||||||
- deploy-production
|
- build-and-deploy
|
||||||
commands:
|
commands:
|
||||||
- sh scripts/notify-wechat.sh failure
|
- sh scripts/notify-wechat.sh failure
|
||||||
when:
|
when:
|
||||||
@@ -342,8 +301,6 @@ steps:
|
|||||||
branch:
|
branch:
|
||||||
- release
|
- release
|
||||||
- release/**
|
- release/**
|
||||||
status:
|
|
||||||
- failure
|
|
||||||
|
|
||||||
workspace:
|
workspace:
|
||||||
base: /woodpecker
|
base: /woodpecker
|
||||||
|
|||||||
Reference in New Issue
Block a user