feat: add java control plane container baseline
This commit is contained in:
1 parent
2897354dd8
commit
1615401185
18 files changed
+566
No files matched your search
@@ -301,11 +301,14 @@ MaaS 模型服务与应用开发
|
|||||||
- [信息准备与阶段门禁清单](docs/05-information-readiness-checklist.md)
|
- [信息准备与阶段门禁清单](docs/05-information-readiness-checklist.md)
|
||||||
- [D4 密钥与模型目录实施计划](docs/06-d4-integration-plan.md)
|
- [D4 密钥与模型目录实施计划](docs/06-d4-integration-plan.md)
|
||||||
- [首批模型供应商接入节点](docs/07-provider-integration.md)
|
- [首批模型供应商接入节点](docs/07-provider-integration.md)
|
||||||
|
- [Java 后端与容器化部署基线](docs/08-java-container-deployment.md)
|
||||||
|
|
||||||
## 前端原型
|
## 前端原型
|
||||||
|
|
||||||
阶段 2 的可交互 Vue 原型位于 `prototype/`,包含用户控制台、模型广场、Playground、API Key、任务中心、用量与账单、接入文档和运营后台。
|
阶段 2 的可交互 Vue 原型位于 `prototype/`,包含用户控制台、模型广场、Playground、API Key、任务中心、用量与账单、接入文档和运营后台。
|
||||||
|
|
||||||
|
Java 后端迁移基线位于 `control-plane-java/`,前后端生产容器编排位于 `infra/moyi/`。现有 TypeScript Control Plane 在 Java 接口迁移完成前继续作为过渡实现。
|
||||||
|
|
||||||
Otari 本地网关基座位于 `infra/otari/`,仅用于后续联调和开发环境,不包含真实供应商密钥。
|
Otari 本地网关基座位于 `infra/otari/`,仅用于后续联调和开发环境,不包含真实供应商密钥。
|
||||||
|
|
||||||
身份与权限服务位于 `control-plane/`,本地 PostgreSQL 基座位于 `infra/control-plane/`;认证接口、邀请码和角色守卫将在 D3 逐步接入前端。
|
身份与权限服务位于 `control-plane/`,本地 PostgreSQL 基座位于 `infra/control-plane/`;认证接口、邀请码和角色守卫将在 D3 逐步接入前端。
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.git
|
||||||
|
.idea
|
||||||
|
target
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
FROM maven:3.9-eclipse-temurin-21-alpine AS build
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
COPY pom.xml .
|
||||||
|
RUN mvn -B -q dependency:go-offline
|
||||||
|
COPY src ./src
|
||||||
|
RUN mvn -B -q clean package -DskipTests
|
||||||
|
|
||||||
|
FROM eclipse-temurin:21-jre-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apk add --no-cache wget
|
||||||
|
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75 -XX:+ExitOnOutOfMemoryError"
|
||||||
|
COPY --from=build /workspace/target/moyi-control-plane.jar /app/moyi-control-plane.jar
|
||||||
|
EXPOSE 8787
|
||||||
|
ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar /app/moyi-control-plane.jar"]
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# MOYI Java Control Plane
|
||||||
|
|
||||||
|
这是 MOYI Control Plane 的 Java 迁移基线,目标运行时为 Java 21,框架为 Spring Boot。当前提供健康检查、Flyway 数据库迁移和容器启动骨架,后续按接口契约逐步迁移现有 TypeScript 服务的认证、模型目录、API Key、路由和任务能力。
|
||||||
|
|
||||||
|
目标依赖边界:
|
||||||
|
|
||||||
|
- PostgreSQL:用户、工作区、供应商、模型目录、Key、计费和审计等持久化数据。
|
||||||
|
- Redis:会话、限流、并发计数、幂等键和异步任务队列。
|
||||||
|
- OSS:3D、图片、视频等任务结果和用户上传文件;只保存对象元数据,应用不保存大文件本体。
|
||||||
|
- Provider Adapter:服务端调用 DeepSeek、Kimi、GLM、Seedance、Tripo/VAST 和后续中转渠道。
|
||||||
|
|
||||||
|
Flyway 脚本位于 `src/main/resources/db/migration/`,与现有 TypeScript 服务使用同一套基础表命名,后续迁移数据时可以按表逐步切换。
|
||||||
|
|
||||||
|
本目录的镜像由 `infra/moyi/docker-compose.yml` 构建。当前 TypeScript Control Plane 仍是迁移期间的可用实现,不要在 Java 接口尚未完成前直接切换生产流量。
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.4.5</version>
|
||||||
|
<relativePath />
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>com.moyi</groupId>
|
||||||
|
<artifactId>moyi-control-plane</artifactId>
|
||||||
|
<version>0.1.0</version>
|
||||||
|
<name>moyi-control-plane</name>
|
||||||
|
<description>MOYI Model Intelligence Hub Java Control Plane</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>21</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-database-postgresql</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>moyi-control-plane</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.moyi.controlplane;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class HealthController {
|
||||||
|
@GetMapping("/health")
|
||||||
|
public Map<String, Object> health() {
|
||||||
|
return Map.of(
|
||||||
|
"status", "ok",
|
||||||
|
"service", "moyi-control-plane-java",
|
||||||
|
"migration", "bootstrap"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.moyi.controlplane;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class MoyiControlPlaneApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MoyiControlPlaneApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: moyi-control-plane
|
||||||
|
datasource:
|
||||||
|
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5434/moyi_control}
|
||||||
|
username: ${SPRING_DATASOURCE_USERNAME:moyi}
|
||||||
|
password: ${SPRING_DATASOURCE_PASSWORD:}
|
||||||
|
hikari:
|
||||||
|
maximum-pool-size: ${DB_POOL_MAX_SIZE:15}
|
||||||
|
minimum-idle: ${DB_POOL_MIN_IDLE:2}
|
||||||
|
data:
|
||||||
|
redis:
|
||||||
|
url: ${SPRING_DATA_REDIS_URL:redis://localhost:6379}
|
||||||
|
flyway:
|
||||||
|
enabled: ${FLYWAY_ENABLED:true}
|
||||||
|
baseline-on-migrate: true
|
||||||
|
|
||||||
|
server:
|
||||||
|
address: ${CONTROL_PLANE_HOST:0.0.0.0}
|
||||||
|
port: ${CONTROL_PLANE_PORT:8787}
|
||||||
|
shutdown: graceful
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: health,info,prometheus
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
probes:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
moyi:
|
||||||
|
auth:
|
||||||
|
session-ttl-hours: ${SESSION_TTL_HOURS:168}
|
||||||
|
password-pepper: ${AUTH_PASSWORD_PEPPER:}
|
||||||
|
storage:
|
||||||
|
oss-endpoint: ${OSS_ENDPOINT:}
|
||||||
|
oss-region: ${OSS_REGION:}
|
||||||
|
oss-bucket: ${OSS_BUCKET:}
|
||||||
|
oss-access-key-id: ${OSS_ACCESS_KEY_ID:}
|
||||||
|
oss-access-key-secret: ${OSS_ACCESS_KEY_SECRET:}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
account varchar(320) NOT NULL UNIQUE,
|
||||||
|
account_kind varchar(16) NOT NULL CHECK (account_kind IN ('email', 'phone', 'username')),
|
||||||
|
password_hash text NOT NULL,
|
||||||
|
display_name varchar(80) NOT NULL,
|
||||||
|
role varchar(16) NOT NULL DEFAULT 'user' CHECK (role IN ('user', 'admin')),
|
||||||
|
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
last_login_at timestamptz
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS invitation_codes (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
code_hash char(64) NOT NULL UNIQUE,
|
||||||
|
code_prefix varchar(12) NOT NULL,
|
||||||
|
label varchar(100) NOT NULL,
|
||||||
|
max_uses integer NOT NULL DEFAULT 1 CHECK (max_uses > 0),
|
||||||
|
used_count integer NOT NULL DEFAULT 0 CHECK (used_count >= 0 AND used_count <= max_uses),
|
||||||
|
expires_at timestamptz,
|
||||||
|
disabled_at timestamptz,
|
||||||
|
created_by uuid NOT NULL REFERENCES users(id),
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS invitation_redemptions (
|
||||||
|
invitation_id uuid NOT NULL REFERENCES invitation_codes(id),
|
||||||
|
user_id uuid NOT NULL REFERENCES users(id),
|
||||||
|
redeemed_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
PRIMARY KEY (invitation_id, user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS auth_sessions (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
token_hash char(64) NOT NULL UNIQUE,
|
||||||
|
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
expires_at timestamptz NOT NULL,
|
||||||
|
revoked_at timestamptz,
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
last_seen_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
user_agent text,
|
||||||
|
ip_address inet
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS auth_sessions_user_id_idx ON auth_sessions(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS auth_sessions_expires_at_idx ON auth_sessions(expires_at);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS auth_audit_log (
|
||||||
|
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
|
actor_user_id uuid REFERENCES users(id),
|
||||||
|
event_type varchar(64) NOT NULL,
|
||||||
|
target_type varchar(32),
|
||||||
|
target_id text,
|
||||||
|
ip_address inet,
|
||||||
|
user_agent text,
|
||||||
|
details jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS auth_audit_log_created_at_idx ON auth_audit_log(created_at DESC);
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS model_providers (
|
||||||
|
id varchar(64) PRIMARY KEY,
|
||||||
|
code varchar(64) NOT NULL UNIQUE,
|
||||||
|
name varchar(120) NOT NULL,
|
||||||
|
protocol varchar(32) NOT NULL CHECK (protocol IN ('openai-compatible', 'http', 'sdk')),
|
||||||
|
base_url text,
|
||||||
|
description text,
|
||||||
|
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS model_catalog (
|
||||||
|
id varchar(64) PRIMARY KEY,
|
||||||
|
provider_id varchar(64) NOT NULL REFERENCES model_providers(id),
|
||||||
|
public_name varchar(160) NOT NULL,
|
||||||
|
upstream_model varchar(160) NOT NULL,
|
||||||
|
model_type varchar(24) NOT NULL CHECK (model_type IN ('text', 'code', 'multimodal', 'image', 'audio', 'video', 'embedding', '3d')),
|
||||||
|
call_mode varchar(16) NOT NULL CHECK (call_mode IN ('sync', 'stream', 'async')),
|
||||||
|
description text NOT NULL DEFAULT '',
|
||||||
|
input_types jsonb NOT NULL DEFAULT '[]'::jsonb,
|
||||||
|
output_types jsonb NOT NULL DEFAULT '[]'::jsonb,
|
||||||
|
capabilities jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||||
|
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS model_catalog_provider_id_idx ON model_catalog(provider_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS model_catalog_status_idx ON model_catalog(status);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS platform_api_keys (
|
||||||
|
id uuid PRIMARY KEY,
|
||||||
|
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
name varchar(80) NOT NULL,
|
||||||
|
key_prefix varchar(24) NOT NULL,
|
||||||
|
key_hash char(64) NOT NULL UNIQUE,
|
||||||
|
scopes jsonb NOT NULL DEFAULT '["invoke"]'::jsonb,
|
||||||
|
model_ids jsonb NOT NULL DEFAULT '[]'::jsonb,
|
||||||
|
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
last_used_at timestamptz,
|
||||||
|
revoked_at timestamptz
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS platform_api_keys_user_id_idx ON platform_api_keys(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS platform_api_keys_status_idx ON platform_api_keys(status);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS model_projects (
|
||||||
|
id varchar(64) PRIMARY KEY,
|
||||||
|
owner_user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
name varchar(80) NOT NULL,
|
||||||
|
description text NOT NULL DEFAULT '',
|
||||||
|
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE platform_api_keys ADD COLUMN IF NOT EXISTS project_id varchar(64) REFERENCES model_projects(id) ON DELETE CASCADE;
|
||||||
|
CREATE INDEX IF NOT EXISTS model_projects_owner_user_id_idx ON model_projects(owner_user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS platform_api_keys_project_id_idx ON platform_api_keys(project_id);
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# Java 后端与容器化部署基线
|
||||||
|
|
||||||
|
## 一、技术决策
|
||||||
|
|
||||||
|
MOYI 后端从当前 TypeScript Control Plane 迁移到 Java 21 + Spring Boot。迁移采用并行替换:先保持现有 API 契约和前端不变,再按认证、目录、Key、路由、队列和任务顺序迁移接口。旧实现只有在 Java 版本完成同等接口、数据迁移和 UAT 后才下线。
|
||||||
|
|
||||||
|
目标组件:
|
||||||
|
|
||||||
|
| 组件 | 责任 | 第一版部署方式 |
|
||||||
|
|---|---|---|
|
||||||
|
| Vue + Nginx | 用户端和管理端静态页面、同源反向代理 | `frontend` 容器 |
|
||||||
|
| Java Control Plane | 认证、目录、Key、路由、计量和管理 API | `moyi-api` 容器 |
|
||||||
|
| PostgreSQL | 业务数据和审计数据持久化 | `postgres` 容器或云数据库 |
|
||||||
|
| Redis | 会话、限流、并发计数、幂等和任务队列 | `redis` 容器或云 Redis |
|
||||||
|
| OSS | 图片、视频、3D 文件和用户上传文件 | 云 OSS,不放进应用镜像 |
|
||||||
|
| Otari / Provider Adapter | 网关、模型上游和供应商适配 | 独立服务,按联调需要接入 |
|
||||||
|
|
||||||
|
## 二、容器边界
|
||||||
|
|
||||||
|
前端使用生产构建,不在生产运行 Vite dev server。Nginx 将 `/api/` 和 `/v1/` 代理到 Java 服务,浏览器只访问一个域名,因此不需要把数据库、Redis、供应商 Key 暴露给前端。
|
||||||
|
|
||||||
|
Java 服务使用环境变量读取数据库、Redis、OSS 和供应商配置。数据库密码、Redis 密码、管理员密码、OSS Secret 和供应商 API Key 不进入镜像、前端静态资源或 Git 仓库。
|
||||||
|
|
||||||
|
## 三、迁移节点
|
||||||
|
|
||||||
|
1. Java 工程启动、健康检查和基础配置。
|
||||||
|
2. PostgreSQL Flyway 迁移:用户、邀请码、会话、工作区、供应商、模型、Key、用量、审计。
|
||||||
|
3. Redis 会话与限流:替换内存 session、登录限流和幂等键。
|
||||||
|
4. 认证接口迁移:保持 `/api/auth/*` 返回结构兼容。
|
||||||
|
5. 模型目录和供应商来源迁移:保持 `/api/models`、`/api/admin/providers`、`/api/admin/models` 兼容。
|
||||||
|
6. API Key、模型权限、统一 `/v1/*` 调用和供应商适配迁移。
|
||||||
|
7. 异步任务、队列、OSS 结果文件和 Webhook 迁移。
|
||||||
|
8. 监控、备份、压测、灰度和回滚验证。
|
||||||
|
|
||||||
|
## 四、云环境信息清单
|
||||||
|
|
||||||
|
### 现在必须提供
|
||||||
|
|
||||||
|
本阶段只需要确认部署边界,不需要把真实密码或 API Key 发到聊天中:
|
||||||
|
|
||||||
|
- 云服务器是否使用现有服务器;操作系统、CPU/内存/磁盘、CPU 架构和 Docker / Compose 版本。
|
||||||
|
- 计划使用的域名、DNS 管理方式、是否已有 Nginx/Caddy、HTTPS 证书和备案状态。
|
||||||
|
- PostgreSQL 使用云数据库还是 Docker;版本、内网地址、端口、数据库名、账号和网络白名单。
|
||||||
|
- Redis 使用云 Redis 还是 Docker;版本、内网地址、端口、是否 TLS、ACL 用户和网络白名单。
|
||||||
|
- OSS 使用哪家云厂商;Region、Endpoint、Bucket、内网访问 Endpoint、对象公开/私有策略和生命周期规则。
|
||||||
|
|
||||||
|
### 开始真实联调前需要提供
|
||||||
|
|
||||||
|
- DeepSeek、Kimi、GLM、Seedance、Tripo/VAST 以及其他中转渠道的测试环境 Key、Base URL、模型 ID 和限额。
|
||||||
|
- 测试域名、回调/Webhook 地址、允许访问的 IP、日志和数据留存要求。
|
||||||
|
- 4—5 名内部测试用户、3—4 个项目的验收场景和预计并发。
|
||||||
|
- 额度、价格、失败扣费、退款、任务文件保留和超限策略。
|
||||||
|
|
||||||
|
### 生产开放前再确认
|
||||||
|
|
||||||
|
- 生产域名、证书自动续期、备份周期、恢复目标、监控告警和应急联系人。
|
||||||
|
- 云数据库/Redis/OSS 的高可用、备份、跨可用区和访问审计方案。
|
||||||
|
- 供应商授权、数据出境/地区限制、隐私政策、用户协议、内容安全和日志脱敏边界。
|
||||||
|
- 发布审批、镜像签名或 digest、漏洞扫描、灰度发布和回滚方案。
|
||||||
|
|
||||||
|
## 五、密钥交付方式
|
||||||
|
|
||||||
|
不要把 PostgreSQL 密码、Redis 密码、OSS AccessKey Secret 或模型 API Key 直接粘贴到聊天或 Git。建议由你在服务器上创建 `infra/moyi/.env`,或使用云厂商 Secrets Manager / KMS 注入;我只需要变量名、网络连通性和脱敏后的连接信息来完成配置和验证。
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Copy to .env on the target server. Do not commit the real file.
|
||||||
|
MOYI_HTTP_PORT=8080
|
||||||
|
|
||||||
|
POSTGRES_USER=moyi
|
||||||
|
POSTGRES_PASSWORD=replace-with-a-long-random-password
|
||||||
|
POSTGRES_DB=moyi_control
|
||||||
|
|
||||||
|
REDIS_PASSWORD=replace-with-a-long-random-password
|
||||||
|
|
||||||
|
SESSION_TTL_HOURS=168
|
||||||
|
AUTH_PASSWORD_PEPPER=replace-with-a-long-random-secret-at-least-32-chars
|
||||||
|
ADMIN_ACCOUNT=adimin
|
||||||
|
ADMIN_PASSWORD=replace-with-a-strong-initial-password
|
||||||
|
ADMIN_DISPLAY_NAME=平台管理员
|
||||||
|
|
||||||
|
# Optional upstream gateway endpoint used after Otari/adapter integration.
|
||||||
|
OTARI_BASE_URL=http://otari:8000
|
||||||
|
|
||||||
|
# Object storage: external Alibaba Cloud OSS or an S3-compatible service.
|
||||||
|
OSS_ENDPOINT=
|
||||||
|
OSS_REGION=
|
||||||
|
OSS_BUCKET=
|
||||||
|
OSS_ACCESS_KEY_ID=
|
||||||
|
OSS_ACCESS_KEY_SECRET=
|
||||||
|
|
||||||
|
# Provider credentials: only injected into the API container.
|
||||||
|
TRIPO_API_KEY=
|
||||||
|
DEEPSEEK_API_KEY=
|
||||||
|
KIMI_API_KEY=
|
||||||
|
ZHIPU_API_KEY=
|
||||||
|
VOLCENGINE_API_KEY=
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# MOYI 容器化部署基线
|
||||||
|
|
||||||
|
这套 Compose 用于 MOYI 的 Java 后端迁移基线:Vue 前端以 Nginx 生产构建运行,Java Control Plane 以 Spring Boot 运行,PostgreSQL 和 Redis 使用独立持久化卷。OSS 不在 Compose 中自建,生产环境连接云厂商 OSS;本地如需模拟对象存储,可另行增加 MinIO profile。
|
||||||
|
|
||||||
|
## 当前迁移状态
|
||||||
|
|
||||||
|
`control-plane-java/` 当前提供 Java 21 / Spring Boot 的启动和健康检查骨架。现有 TypeScript Control Plane 仍是接口迁移期间的可用实现,Java 服务完成认证、模型目录、Key、路由和任务接口迁移并通过 UAT 前,不要直接把生产流量切到 Java 服务。
|
||||||
|
|
||||||
|
## 启动
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
cd infra/moyi
|
||||||
|
Copy-Item .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
编辑 `.env` 中的数据库、Redis、管理员和密钥变量,然后执行:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
docker compose build
|
||||||
|
docker compose up -d
|
||||||
|
docker compose ps
|
||||||
|
Invoke-WebRequest http://localhost:8080/health
|
||||||
|
```
|
||||||
|
|
||||||
|
前端入口为 `http://localhost:8080`。当前 Java 骨架阶段只保证 `/health` 可用;业务接口仍需完成迁移后才适合用此 Compose 做完整用户验收。
|
||||||
|
|
||||||
|
## 停止与数据
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
docker compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
不要在没有备份的情况下使用 `docker compose down -v`,它会删除 PostgreSQL 和 Redis 的本地卷。
|
||||||
|
|
||||||
|
## 生产注意事项
|
||||||
|
|
||||||
|
- 生产环境把 `MOYI_HTTP_PORT` 放在反向代理之后,只暴露 HTTPS 入口,不直接公网暴露 PostgreSQL 和 Redis。
|
||||||
|
- `POSTGRES_PASSWORD`、`REDIS_PASSWORD`、`AUTH_PASSWORD_PEPPER`、管理员密码、供应商 Key 和 OSS Secret 不提交 Git,也不要写入前端构建参数。
|
||||||
|
- OSS AccessKey 只授予目标 Bucket 的最小权限,应用使用临时凭证或 RAM 子账号优先。
|
||||||
|
- 正式上线前固定基础镜像 digest,执行漏洞扫描、依赖许可证审计、数据库备份恢复演练和回滚演练。
|
||||||
|
- Java 服务完成业务迁移后,再把数据库迁移、Redis 队列、OSS 对象元数据和监控告警纳入发布流水线。
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
name: moyi
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER:-moyi}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in infra/moyi/.env}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB:-moyi_control}
|
||||||
|
volumes:
|
||||||
|
- moyi_postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 12
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD:?Set REDIS_PASSWORD in infra/moyi/.env}"]
|
||||||
|
volumes:
|
||||||
|
- moyi_redis_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "-a", "$${REDIS_PASSWORD}", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 12
|
||||||
|
|
||||||
|
moyi-api:
|
||||||
|
build:
|
||||||
|
context: ../../control-plane-java
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file:
|
||||||
|
- path: .env
|
||||||
|
required: false
|
||||||
|
environment:
|
||||||
|
CONTROL_PLANE_HOST: 0.0.0.0
|
||||||
|
CONTROL_PLANE_PORT: 8787
|
||||||
|
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB:-moyi_control}
|
||||||
|
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER:-moyi}
|
||||||
|
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
SPRING_DATA_REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
|
||||||
|
FLYWAY_ENABLED: true
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "wget -q -O - http://127.0.0.1:8787/health | grep -q 'status'"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 12
|
||||||
|
start_period: 20s
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ../../prototype
|
||||||
|
args:
|
||||||
|
VITE_CONTROL_PLANE_URL: /
|
||||||
|
VITE_AUTH_MODE: remote
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "${MOYI_HTTP_PORT:-8080}:80"
|
||||||
|
depends_on:
|
||||||
|
moyi-api:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
moyi_postgres_data:
|
||||||
|
moyi_redis_data:
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.git
|
||||||
|
.idea
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
FROM node:22-alpine AS build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN corepack enable
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
COPY . .
|
||||||
|
ARG VITE_CONTROL_PLANE_URL=/
|
||||||
|
ARG VITE_AUTH_MODE=remote
|
||||||
|
ENV VITE_CONTROL_PLANE_URL=$VITE_CONTROL_PLANE_URL
|
||||||
|
ENV VITE_AUTH_MODE=$VITE_AUTH_MODE
|
||||||
|
RUN pnpm build
|
||||||
|
|
||||||
|
FROM nginx:1.27-alpine
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
|
EXPOSE 80
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://moyi-api:8787;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Cookie $http_cookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /v1/ {
|
||||||
|
proxy_pass http://moyi-api:8787;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Authorization $http_authorization;
|
||||||
|
proxy_set_header Content-Type $http_content_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /health {
|
||||||
|
proxy_pass http://moyi-api:8787/health;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user