112 lines
2.3 KiB
YAML
112 lines
2.3 KiB
YAML
stages:
|
|
- install
|
|
- build
|
|
- deploy
|
|
|
|
variables:
|
|
NODE_ENV: production
|
|
|
|
# 仅 prod 分支触发
|
|
workflow:
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
when: never
|
|
- if: $CI_COMMIT_BRANCH == "prod"
|
|
|
|
# pnpm store 缓存
|
|
cache:
|
|
key:
|
|
files:
|
|
- pnpm-lock.yaml
|
|
paths:
|
|
- .pnpm-store
|
|
|
|
# ==================== INSTALL ====================
|
|
install_dependencies:
|
|
stage: install
|
|
tags:
|
|
- rent-deploy
|
|
script:
|
|
- npm install -g pnpm
|
|
- pnpm config set store-dir .pnpm-store
|
|
- pnpm install --frozen-lockfile
|
|
artifacts:
|
|
paths:
|
|
- node_modules/
|
|
- apps/*/node_modules/
|
|
- packages/*/node_modules/
|
|
expire_in: 1 hour
|
|
|
|
# ==================== BUILD ====================
|
|
build_server:
|
|
stage: build
|
|
tags:
|
|
- rent-deploy
|
|
needs: [install_dependencies]
|
|
script:
|
|
- npm install -g pnpm
|
|
- pnpm config set store-dir .pnpm-store
|
|
- pnpm --filter @rent/shared-types build
|
|
- pnpm --filter @rent/shared-utils build
|
|
- pnpm --filter @rent/server build
|
|
artifacts:
|
|
paths:
|
|
- apps/server/dist/
|
|
expire_in: 1 hour
|
|
|
|
build_merchant:
|
|
stage: build
|
|
tags:
|
|
- rent-deploy
|
|
needs: [install_dependencies]
|
|
script:
|
|
- npm install -g pnpm
|
|
- pnpm config set store-dir .pnpm-store
|
|
- pnpm --filter @rent/shared-types build
|
|
- pnpm --filter @rent/shared-utils build
|
|
- pnpm --filter @rent/merchant-admin build
|
|
artifacts:
|
|
paths:
|
|
- apps/merchant-admin/dist/
|
|
expire_in: 1 hour
|
|
|
|
build_platform:
|
|
stage: build
|
|
tags:
|
|
- rent-deploy
|
|
needs: [install_dependencies]
|
|
script:
|
|
- npm install -g pnpm
|
|
- pnpm config set store-dir .pnpm-store
|
|
- pnpm --filter @rent/shared-types build
|
|
- pnpm --filter @rent/shared-utils build
|
|
- pnpm --filter @rent/platform-admin build
|
|
artifacts:
|
|
paths:
|
|
- apps/platform-admin/dist/
|
|
expire_in: 1 hour
|
|
|
|
# ==================== DEPLOY ====================
|
|
deploy_production:
|
|
stage: deploy
|
|
tags:
|
|
- rent-deploy
|
|
needs:
|
|
- build_server
|
|
- build_merchant
|
|
- build_platform
|
|
script:
|
|
- echo "部署到生产环境..."
|
|
- cd deploy/docker
|
|
- docker-compose down --remove-orphans
|
|
- docker-compose build --parallel
|
|
- docker-compose up -d
|
|
- docker image prune -f
|
|
- echo "等待服务启动..."
|
|
- sleep 10
|
|
- docker-compose ps
|
|
environment:
|
|
name: production
|
|
only:
|
|
- prod
|