Skip to content

Commit 083e622

Browse files
authored
[app-builder] feat: add quick start (#423)
1 parent 038e720 commit 083e622

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2647
-6
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77

88
# Common
99
target/
10-
build/
10+
build/
11+
12+
# docker
13+
docker/app-platform-tmp
14+
docker/.env
15+
docker/sql/init/data/tr_init_models.sql

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,33 @@
2525

2626
---------
2727

28-
## 安装数据库
28+
## 快速启动
29+
30+
### 1. 前置条件
31+
32+
| 名称 | 规格 |
33+
|--------|----------------------------|
34+
| CPU | 2+ 核心 |
35+
| CPU 架构 | x86 |
36+
| 内存 | 4+ GB |
37+
| 软件 | 安装 Docker & Docker Compose |
38+
39+
### 2. Docker Compose 启动
40+
克隆项目并进入项目根目录,执行以下命令:/ Clone the repository and enter the project root directory, then run the following commands:
41+
```shell
42+
# 用户按需配置环境变量,例如模型名称、基础 URL 和 APIKEY等 / Configure environment variables as needed, including model name, base URL and APIKEY
43+
cp docker/.env.example docker/.env
44+
bash docker/deploy.sh
45+
```
46+
> 容器全部 Running 后,浏览器打开 http://localhost:8001 体验
47+
48+
> 如需修改数据库密码,二次启动前需要删除`docker/app-platform-tmp`目录
49+
50+
## 源码编译启动
51+
52+
### 安装数据库
2953

30-
### Windows 系统
54+
#### Windows 系统
3155

3256
- 下载并安装 [PostgresSQL](https://www.postgresql.org/download/)**支持版本 ≥ 14**
3357
- 初始化数据。进入 `shell` 目录,使用 `bash` 工具执行 `build_win.sh`(当前不支持 `cmd` 执行,待规划):
@@ -39,11 +63,11 @@ sh build_win.sh ${ip} ${port} ${username} ${password}
3963

4064
其中参数 ip、port、username、password 分别指的是数据库主机地址、数据库端口、数据用户名、数据库密码。该文件会初始化数据库内置数据,以及人工表单功能所需的数据。
4165

42-
### Linux 系统
66+
#### Linux 系统
4367

4468
待规划
4569

46-
## 后端环境配置
70+
### 后端环境配置
4771

4872
开发环境配置
4973

@@ -149,7 +173,7 @@ fit start -Dfit.profiles.active=prod
149173
150174
---------
151175
152-
## 前端环境配置
176+
### 前端环境配置
153177
154178
- 开发环境:`WebStorm`、`Visual Studio Code`
155179

docker/.env.example

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 模型配置,部署前,用户自定义修改 / Model configuration, please config before deploying
2+
# 模型名称 / Model name
3+
MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
4+
5+
# 基础 URL / Base URL
6+
BASE_URL=https://api.siliconflow.cn/v1
7+
8+
# API 密钥 / Apikey
9+
APIKEY=${APIKEY}
10+
11+
# 部署配置 / Deployment configuration
12+
# ModelEngine 开源版本号 / ModelEngine opensource version
13+
VERSION=opensource-1.2.2
14+
15+
# 用户自定义数据库密码 / User-configured database password
16+
DB_PASSWORD=ModelEngine@123
17+
18+
# 数据库容器绑定的宿主机端口 / Host machine port bound to the database container
19+
DB_PORT=5433
20+
21+
# 前端容器绑定的宿主机端口 / Host machine port bound to the frontend container
22+
WEB_PORT=8001
23+
24+
# 是否升级模式 / Upgrade or not
25+
IS_UPGRADE=false

docker/deploy.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -eux
3+
export WORKSPACE=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)
4+
5+
bash ${WORKSPACE}/import_model.sh
6+
echo "=== Deploying... ==="
7+
cd ${WORKSPACE}
8+
mkdir -p app-platform-tmp/app-builder
9+
mkdir -p app-platform-tmp/fit-runtime
10+
mkdir -p app-platform-tmp/jade-db
11+
mkdir -p app-platform-tmp/log
12+
echo "Starting service..."
13+
docker-compose up -d
14+
echo "Service started"
15+
echo "=== Finished ==="

docker/docker-compose.yml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
services:
2+
jade-db:
3+
container_name: jade-db
4+
hostname: jade-db
5+
image: modelengine/postgres:15.2-${VERSION}
6+
healthcheck:
7+
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
8+
interval: 10s
9+
timeout: 5s
10+
retries: 30
11+
start_period: 30s
12+
networks:
13+
my-net:
14+
ipv4_address: 172.0.0.98
15+
environment:
16+
POSTGRES_USER: postgres
17+
POSTGRES_PASSWORD: ${DB_PASSWORD}
18+
LOG_HOME: /log/app
19+
volumes:
20+
- ./sql:/home/sql
21+
- ./shell/initDB.sh:/home/initDB.sh
22+
- "./app-platform-tmp/jade-db:/var/lib/postgresql/data"
23+
- "./app-platform-tmp/log:/log/app/postgresql"
24+
ports:
25+
- "${DB_PORT}:5432"
26+
27+
db-initializer:
28+
container_name: db-initializer
29+
hostname: db-initializer
30+
image: modelengine/postgres:15.2-${VERSION}
31+
networks:
32+
my-net:
33+
ipv4_address: 172.0.0.99
34+
environment:
35+
POSTGRES_USER: postgres
36+
POSTGRES_PASSWORD: "ModelEngine@123"
37+
LOG_HOME: /log/app
38+
DB_HOST: jade-db
39+
DB_PORT: 5432
40+
DB_USER: postgres
41+
IS_UPGRADE: ${IS_UPGRADE}
42+
volumes:
43+
- ./shell/initDB.sh:/home/initDB.sh
44+
- ./sql:/home/sql
45+
entrypoint: ["/bin/bash", "-c"]
46+
command: |
47+
" chmod +x /home/initDB.sh
48+
bash /home/initDB.sh app_builder /home/sql
49+
"
50+
restart: "no"
51+
52+
app-builder:
53+
container_name: app-builder
54+
hostname: app-builder
55+
image: modelengine/app-builder:${VERSION}
56+
depends_on:
57+
jade-db:
58+
condition: service_healthy
59+
healthcheck:
60+
test: ["CMD", "curl", "-f", "http://app-builder:8004/fit/check"]
61+
interval: 30s
62+
timeout: 10s
63+
retries: 20
64+
start_period: 180s
65+
networks:
66+
my-net:
67+
ipv4_address: 172.0.0.100
68+
environment:
69+
worker.host: localhost
70+
server.http.port: 8004
71+
matata.registry.host: localhost
72+
matata.registry.port: 8004
73+
fit.profiles.active: prod
74+
fit.datasource.primary: app-engine
75+
fit.datasource.instances.app-engine.mode: shared
76+
fit.datasource.instances.app-engine.url: jdbc:postgresql://jade-db/app_builder?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=true&allowPublicKeyRetrieval=true&useAffectedRows=true&connectTimeout=60000&socketTimeout=60000
77+
fit.datasource.instances.app-engine.username: postgres
78+
fit.datasource.instances.app-engine.password: "ModelEngine@123"
79+
openai-urls.internal: https://model-lite-router:8009/v1
80+
app-engine.pathPrefix: /api/jober
81+
LOG_HOME: /log/app
82+
LOG_NUM: 4320
83+
LOG_SIZE: "50M"
84+
app-engine.ttl.businessData: 15
85+
app-engine.ttl.nonBusinessData: 1
86+
volumes:
87+
- "./app-platform-tmp/fit-runtime:/var/store/tools"
88+
- "./app-platform-tmp/log:/log/app/app-builder"
89+
- "./app-platform-tmp/jade-db:/var/jade-db"
90+
- "./app-platform-tmp/app-builder:/var/share"
91+
ports:
92+
- "8004:8004"
93+
94+
fit-runtime-java:
95+
container_name: fit-runtime-java
96+
hostname: fit-runtime-java
97+
image: modelengine/fit-runtime-java:${VERSION}
98+
depends_on:
99+
app-builder:
100+
condition: service_healthy
101+
networks:
102+
my-net:
103+
ipv4_address: 172.0.0.101
104+
environment:
105+
worker.id: fit-runtime-java
106+
worker.environment: prod
107+
worker.host: 172.0.0.101
108+
matata.registry.host: app-builder
109+
matata.registry.port: 8004
110+
matata.registry.environment: prod
111+
ENTRY_PLUGINS_PATH: /entry
112+
LOG_HOME: /log/app
113+
volumes:
114+
- "./app-platform-tmp/app-builder:/var/share"
115+
- "./app-platform-tmp/fit-runtime:/entry"
116+
- "./app-platform-tmp/log:/log/app/runtime-java"
117+
ports:
118+
- "8090:8090"
119+
120+
fit-runtime-python:
121+
container_name: fit-runtime-python
122+
hostname: fit-runtime-python
123+
image: modelengine/fit-runtime-python:${VERSION}
124+
depends_on:
125+
app-builder:
126+
condition: service_healthy
127+
networks:
128+
my-net:
129+
ipv4_address: 172.0.0.102
130+
environment:
131+
WORKER_ID: fit-runtime-python
132+
WORK_ENV: prod
133+
LOCAL_IP: 172.0.0.102
134+
REGISTRY_HOST: app-builder
135+
REGISTRY_PORT: 8004
136+
matata.registry.environment: prod
137+
USER_PLUGINS_PATH: 'custom_dynamic_plugins/python'
138+
LOG_HOME: /log/app
139+
volumes:
140+
- "./app-platform-tmp/app-builder:/var/share"
141+
- "./app-platform-tmp/fit-runtime:/app/python/custom_dynamic_plugins"
142+
- "./app-platform-tmp/log:/log/app/runtime-python"
143+
ports:
144+
- "9666:9666"
145+
146+
web:
147+
container_name: web
148+
hostname: web
149+
image: modelengine/jade-web:${VERSION}
150+
depends_on:
151+
app-builder:
152+
condition: service_healthy
153+
networks:
154+
my-net:
155+
ipv4_address: 172.0.0.103
156+
environment:
157+
LOG_HOME: /log/app
158+
volumes:
159+
- "./app-platform-tmp/log:/log/app/web"
160+
ports:
161+
- "${WEB_PORT}:8001"
162+
163+
networks:
164+
my-net:
165+
driver: bridge
166+
ipam:
167+
config:
168+
- subnet: 172.0.0.0/24
169+
gateway: 172.0.0.1

docker/import_model.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -eux
3+
4+
export WORKSPACE=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)
5+
source ${WORKSPACE}/.env
6+
7+
export OS_TYPE=$(uname -s)
8+
if [[ "${OS_TYPE}" == "Darwin" ]]; then
9+
export SED="sed -i '.bak' "
10+
else
11+
export SED="sed -i"
12+
fi
13+
cp ${WORKSPACE}/sql/init/data/tr_init_models.sql.example ${WORKSPACE}/sql/init/data/tr_init_models.sql
14+
${SED} "s#MODEL_NAME#${MODEL_NAME}#g" ${WORKSPACE}/sql/init/data/tr_init_models.sql
15+
${SED} "s#BASE_URL#${BASE_URL}#g" ${WORKSPACE}/sql/init/data/tr_init_models.sql
16+
${SED} "s#APIKEY#${APIKEY}#g" ${WORKSPACE}/sql/init/data/tr_init_models.sql
17+
18+
if [[ "${OS_TYPE}" == "Darwin" ]]; then
19+
rm -f docker/sql/init/data/tr_init_models.sql\'.bak\'
20+
fi

docker/shell/initDB.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
export PGPASSWORD="$POSTGRES_PASSWORD"
4+
5+
DB_NAME=$1
6+
SQL_DIR=$2
7+
SCHEMA_SQL_DIR="$SQL_DIR/init/schema"
8+
DATA_SQL_DIR="$SQL_DIR/init/data"
9+
UPGRADE_SQL_DIR="$SQL_DIR/upgrade"
10+
11+
# 尝试连接数据库
12+
while true
13+
do
14+
psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -c "\dn"
15+
if [ "$?" -eq 0 ];then
16+
if [ "$( psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -c "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" )" = '1' ];then
17+
echo "Database ${DB_NAME} already exists"
18+
else
19+
psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -c "CREATE DATABASE ${DB_NAME};"
20+
echo "Database ${DB_NAME} already created"
21+
fi
22+
echo "Contect ${DB_HOST} success and check db ${DB_NAME} is exists"
23+
break
24+
fi
25+
26+
sleep 1
27+
done
28+
echo "----------------"
29+
30+
if [ "$IS_UPGRADE" = "true" ]; then
31+
echo "Executing upgrade.sql..."
32+
# 执行升级脚本
33+
if [ ! -z "${UPGRADE_SQL_DIR}" ]; then
34+
files=$(ls ${UPGRADE_SQL_DIR}/*.sql | sort)
35+
for sql_file in $files;do
36+
echo "Executing $sql_file..."
37+
psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME} -f ${sql_file} -v ON_ERROR_STOP=1
38+
if [ "$?" -ne 0 ]; then
39+
echo "Error: executing $sql_file failed"
40+
exit 1
41+
fi
42+
done
43+
fi
44+
echo "Finished executing upgrade.sql "
45+
fi
46+
echo "----------------"
47+
48+
if [ ! -z "${SCHEMA_SQL_DIR}" ]; then
49+
files=$(ls ${SCHEMA_SQL_DIR}/*.sql | sort)
50+
for sql_file in $files;do
51+
echo "Executing $sql_file..."
52+
# 执行 schema 相关的 sql 文件
53+
psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME} -f ${sql_file} -v ON_ERROR_STOP=1
54+
if [ "$?" -ne 0 ]; then
55+
echo "Error: executing $sql_file failed"
56+
exit 1
57+
fi
58+
done
59+
fi
60+
echo "----------------"
61+
62+
if [ ! -z "${DATA_SQL_DIR}" ]; then
63+
files=$(ls ${DATA_SQL_DIR}/*.sql | sort)
64+
for sql_file in $files;do
65+
echo "Executing $sql_file..."
66+
# 执行 data 相关的 sql 文件
67+
psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME} -f ${sql_file} -v ON_ERROR_STOP=1
68+
if [ "$?" -ne 0 ]; then
69+
echo "Error: executing $sql_file failed"
70+
exit 1
71+
fi
72+
done
73+
fi
74+
echo "----------------"
75+
76+
echo "Completed init DB ${DB_NAME}"
77+
exit 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
UPDATE
2+
t_app_engine_model
3+
SET
4+
base_url = CONCAT(
5+
base_url,
6+
CASE WHEN RIGHT(base_url, 1) = '/' THEN 'v1' ELSE '/v1' END
7+
)
8+
WHERE
9+
base_url NOT LIKE '%/v1%';

0 commit comments

Comments
 (0)