ether-docs/_archive/07-DEPLOYMENT/DEPLOYMENT.md

2.4 KiB
Raw Blame History

Ether 项目部署指南

环境变量配置

开发/测试环境

开发环境使用 .env.development 文件,已预配置测试环境变量:

# 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

生产环境

生产环境使用占位符,在部署时动态替换:

# .env.production 中的占位符
__VITE_API_BASE_URL__
__VITE_ENCRYPT_SECRET_KEY__

部署方式

方式一:使用部署脚本(推荐)

# 设置环境变量
export API_BASE_URL="https://api.your-domain.com"
export ENCRYPT_SECRET_KEY="your-32-char-secret-key"

# 执行构建(会自动替换环境变量)
./scripts/build.sh

方式二Docker 部署

# 构建阶段
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

构建命令:

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

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 {
                // 部署到服务器
            }
        }
    }
}

方式四:手动部署

# 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. 定期轮换密钥