ether-docs/07-DEPLOYMENT/DEPLOYMENT.md

114 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Ether 项目部署指南
## 环境变量配置
### 开发/测试环境
开发环境使用 `.env.development` 文件,已预配置测试环境变量:
```bash
# ether-ui-admin/.env.development
VITE_API_BASE_URL=http://localhost:8080
VITE_ENCRYPT_SECRET_KEY=ether-test-2024-secret-key-32ch
# ether-app-owner/.env.development
# ether-app-employee/.env.development
VITE_API_BASE_URL=http://localhost:8080
```
### 生产环境
生产环境使用占位符,在部署时动态替换:
```bash
# .env.production 中的占位符
__VITE_API_BASE_URL__
__VITE_ENCRYPT_SECRET_KEY__
```
## 部署方式
### 方式一:使用部署脚本(推荐)
```bash
# 设置环境变量
export API_BASE_URL="https://api.your-domain.com"
export ENCRYPT_SECRET_KEY="your-32-char-secret-key"
# 执行构建(会自动替换环境变量)
./scripts/build.sh
```
### 方式二Docker 部署
```dockerfile
# 构建阶段
FROM node:20-alpine AS builder
WORKDIR /app
COPY . .
# 通过 build-arg 传入环境变量
ARG API_BASE_URL
ARG ENCRYPT_SECRET_KEY
ENV API_BASE_URL=${API_BASE_URL}
ENV ENCRYPT_SECRET_KEY=${ENCRYPT_SECRET_KEY}
RUN chmod +x scripts/*.sh && ./scripts/build.sh
# 生产阶段
FROM nginx:alpine
COPY --from=builder /app/ether-ui-admin/dist /usr/share/nginx/html
```
构建命令:
```bash
docker build \
--build-arg API_BASE_URL="https://api.your-domain.com" \
--build-arg ENCRYPT_SECRET_KEY="your-secret-key" \
-t ether-admin .
```
### 方式三Jenkins Pipeline
```groovy
pipeline {
agent any
environment {
API_BASE_URL = credentials('prod-api-base-url')
ENCRYPT_SECRET_KEY = credentials('prod-encrypt-secret-key')
}
stages {
stage('Build') {
steps {
sh 'chmod +x scripts/*.sh'
sh './scripts/build.sh'
}
}
stage('Deploy') {
steps {
// 部署到服务器
}
}
}
}
```
### 方式四:手动部署
```bash
# 1. 替换环境变量
./scripts/deploy-env.sh "https://api.your-domain.com" "your-secret-key"
# 2. 分别构建各项目
cd ether-ui-admin && npm ci && npm run build
cd ../ether-app-owner && npm ci && npm run build:h5
cd ../ether-app-employee && npm ci && npm run build:h5
```
## 安全注意事项
1. **切勿**将生产环境密钥提交到代码仓库
2. 使用 CI/CD 系统的 Secrets 管理敏感信息
3. `ENCRYPT_SECRET_KEY` 建议使用 32 位以上随机字符串
4. 定期轮换密钥