feat(core): 重构项目并添加 Docker 支持
- 重命名应用名称和包名,统一使用 llmx 前缀- 添加生产环境和测试环境的 Docker 配置文件 - 新增环境变量配置,用于 Docker部署 - 更新构建脚本,支持多模块构建 - 优化应用配置,适配 Docker 环境
This commit is contained in:
parent
0515b8d5e4
commit
8b17f6cb84
1
.gitignore
vendored
1
.gitignore
vendored
@ -27,6 +27,7 @@ out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
gradle.properties
|
||||
docker/.env.dev
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
|
||||
@ -99,7 +99,6 @@ subprojects {
|
||||
plugin(libs.plugins.kotlin.jvm.get().pluginId)
|
||||
plugin(libs.plugins.jibLocalPlugin.get().pluginId)
|
||||
}
|
||||
println(project.name + ":" + project.getPropertyByBoolean(ProjectFlags.USE_SPRING_BOOT))
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
@ -107,10 +106,20 @@ subprojects {
|
||||
}
|
||||
}
|
||||
jibConfig {
|
||||
val env=System.getenv("SPRING_PROFILES_ACTIVE")
|
||||
project {
|
||||
projectName = "llmx-core-service"
|
||||
ports = listOf("9002")
|
||||
environment = mapOf("SPRING_PROFILES_ACTIVE" to "prod")
|
||||
environment = mapOf("SPRING_PROFILES_ACTIVE" to env)
|
||||
imageName = "llmx-core-service"
|
||||
// paths = listOf(File(rootProject.projectDir, "scripts").absolutePath)
|
||||
}
|
||||
project{
|
||||
projectName="llmx-impl-bailian"
|
||||
ports=listOf("9003")
|
||||
environment=mapOf("SPRING_PROFILES_ACTIVE" to env)
|
||||
imageName="llmx-impl-bailian"
|
||||
// paths = listOf(File(rootProject.projectDir, "scripts").absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,8 +12,8 @@ dependencies {
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
register("jib-plugin") {
|
||||
id = "org.jcnc.llmhub.plugin.jib"
|
||||
implementationClass = "org.jcnc.llmhub.plugin.jib.JibPlugin"
|
||||
id = "org.jcnc.llmx.plugin.jib"
|
||||
implementationClass = "org.jcnc.llmx.plugin.jib.JibPlugin"
|
||||
description =
|
||||
"提供简单的配置构建镜像"
|
||||
}
|
||||
|
||||
@ -52,12 +52,13 @@ class JibPlugin : Plugin<Project> {
|
||||
}
|
||||
to {
|
||||
image =
|
||||
"${System.getenv("LUKE_SERVER_DOCKER_REGISTRY_URL")}/${jibProject.imageName}:${jibProject.version}"
|
||||
"${System.getenv("DOCKER_REGISTRY_URL")}/${jibProject.imageName}:${jibProject.version}"
|
||||
auth {
|
||||
username = "root"
|
||||
password = System.getenv("LUKE_SERVER_DOCKER_REGISTRY_PASSWORD")
|
||||
password = System.getenv("SERVER_PASSWORD")
|
||||
}
|
||||
}
|
||||
setAllowInsecureRegistries(true)
|
||||
// 动态配置容器参数
|
||||
container {
|
||||
ports = jibProject.ports
|
||||
@ -69,7 +70,9 @@ class JibPlugin : Plugin<Project> {
|
||||
|
||||
// 动态配置额外目录
|
||||
extraDirectories {
|
||||
if(jibProject.paths.isNotEmpty()){
|
||||
setPaths(jibProject.paths)
|
||||
}
|
||||
permissions.putAll(jibProject.permissions)
|
||||
}
|
||||
// 将动态部分移到任务配置中
|
||||
|
||||
@ -19,14 +19,14 @@ data class JibProject(
|
||||
var ports: List<String> = listOf("8080"),
|
||||
var environment: Map<String, String> = mapOf("SPRING_PROFILES_ACTIVE" to "prod"),
|
||||
var entrypoint: List<String> = emptyList(),
|
||||
var paths: List<String> = listOf("llmhub-base/scripts/entrypoint.sh"),
|
||||
var paths: List<String> = listOf(),
|
||||
var imageName: String = "",
|
||||
var version: String = "latest",
|
||||
var permissions: Map<String, String> = mapOf("/scripts/entrypoint.sh" to "755"),
|
||||
var baseImage: String = "docker://bellsoft/liberica-openjdk-debian:21"
|
||||
) {
|
||||
init {
|
||||
if (imageName.isEmpty()) {
|
||||
if (imageName.isBlank()) {
|
||||
imageName = projectName
|
||||
}
|
||||
}
|
||||
|
||||
3
docker/.env.prod
Normal file
3
docker/.env.prod
Normal file
@ -0,0 +1,3 @@
|
||||
Docker_REGISTRY_URL=49.235.96.75:5000
|
||||
SERVER_PASSWORD=L4s6f9y3
|
||||
SPRING_PROFILES_ACTIVE=prod
|
||||
3
docker/.env.test
Normal file
3
docker/.env.test
Normal file
@ -0,0 +1,3 @@
|
||||
Docker_REGISTRY_URL=49.235.96.75:5000
|
||||
SERVER_PASSWORD=L4s6f9y3
|
||||
SPRING_PROFILES_ACTIVE=test
|
||||
42
docker/docker-compose.dev.yml
Normal file
42
docker/docker-compose.dev.yml
Normal file
@ -0,0 +1,42 @@
|
||||
services:
|
||||
llmx-core-database:
|
||||
image: postgres:16-alpine # 长期支持版本推荐用 16
|
||||
container_name: llmx-core-database
|
||||
restart: always
|
||||
ports:
|
||||
- "5432:9052"
|
||||
networks:
|
||||
- llmx-net
|
||||
environment:
|
||||
POSTGRES_DB: llmx_core
|
||||
POSTGRES_USER: llmx
|
||||
POSTGRES_PASSWORD: L4s6f9y3,
|
||||
volumes:
|
||||
- llmx-core-db-volume:/var/lib/postgresql/data
|
||||
llmx-core-service:
|
||||
image: ${Docker_REGISTRY_URL}/llmx-core-service
|
||||
container_name: llmx-core-service
|
||||
ports:
|
||||
- "9002:9002"
|
||||
networks:
|
||||
- llmx-net
|
||||
volumes:
|
||||
- llmx-core-service-volume:/app/volume
|
||||
restart: always
|
||||
llmx-impl-baiLian:
|
||||
image: ${Docker_REGISTRY_URL}/llmx-impl-bailian
|
||||
container_name: llmx-impl-bailian
|
||||
ports:
|
||||
- "9003:9003"
|
||||
networks:
|
||||
- llmx-net
|
||||
volumes:
|
||||
- llmx-impl-baiLian-volume:/app/volume
|
||||
restart: always
|
||||
networks:
|
||||
llmx-net:
|
||||
driver: bridge
|
||||
volumes:
|
||||
llmx-core-service-volume:
|
||||
llmx-impl-baiLian-volume:
|
||||
llmx-core-db-volume:
|
||||
42
docker/docker-compose.test.yml
Normal file
42
docker/docker-compose.test.yml
Normal file
@ -0,0 +1,42 @@
|
||||
services:
|
||||
llmx-core-database:
|
||||
image: postgres:16-alpine # 长期支持版本推荐用 16
|
||||
container_name: llmx-core-database
|
||||
restart: always
|
||||
ports:
|
||||
- "5432:9052"
|
||||
networks:
|
||||
- llmx-net
|
||||
environment:
|
||||
POSTGRES_DB: llmx_core
|
||||
POSTGRES_USER: llmx
|
||||
POSTGRES_PASSWORD: L4s6f9y3,
|
||||
volumes:
|
||||
- llmx-core-db-volume:/var/lib/postgresql/data
|
||||
llmx-core-service:
|
||||
image: ${Docker_REGISTRY_URL}/llmx-core-service
|
||||
container_name: llmx-core-service
|
||||
ports:
|
||||
- "9002:9002"
|
||||
networks:
|
||||
- llmx-net
|
||||
volumes:
|
||||
- llmx-core-service-volume:/app/volume
|
||||
restart: always
|
||||
llmx-impl-baiLian:
|
||||
image: ${Docker_REGISTRY_URL}/llmx-impl-baiLian
|
||||
container_name: llmx-impl-baiLian
|
||||
ports:
|
||||
- "9003:9003"
|
||||
networks:
|
||||
- llmx-net
|
||||
volumes:
|
||||
- llmx-impl-baiLian-volume:/app/volume
|
||||
restart: always
|
||||
networks:
|
||||
llmx-net-dev:
|
||||
driver: bridge
|
||||
volumes:
|
||||
llmx-core-service-volume:
|
||||
llmx-impl-baiLian-volume:
|
||||
llmx-core-db-volume:
|
||||
@ -26,7 +26,7 @@ spring-dependency-management = { id = "io.spring.dependency-management", version
|
||||
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot-version" }
|
||||
|
||||
jib = { id = "com.google.cloud.tools.jib", version.ref = "jib-version" }
|
||||
jibLocalPlugin = { id = "org.jcnc.llmhub.plugin.jib" }
|
||||
jibLocalPlugin = { id = "org.jcnc.llmx.plugin.jib" }
|
||||
[libraries]
|
||||
jib-gradlePlugin = { module = "com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin", version.ref = "jib-version" }
|
||||
# bom
|
||||
|
||||
@ -9,7 +9,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope
|
||||
* @since 2025-04-26 18:01:48
|
||||
* @author gewuyou
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "llmhub.model-route")
|
||||
@ConfigurationProperties(prefix = "llmx.model-route")
|
||||
@RefreshScope
|
||||
open class ModelProperties {
|
||||
/**
|
||||
|
||||
@ -3,11 +3,11 @@ server:
|
||||
spring:
|
||||
config:
|
||||
import: classpath:bootstrap-dev.yml
|
||||
llmhub:
|
||||
llmx:
|
||||
model-route:
|
||||
modelServiceMap:
|
||||
qwen-turbo: llmhub-impl-baiLian
|
||||
qwen-max: llmhub-impl-baiLian
|
||||
qwen-plus: llmhub-impl-baiLian
|
||||
qwen-turbo: llmx-impl-baiLian
|
||||
qwen-max: llmx-impl-baiLian
|
||||
qwen-plus: llmx-impl-baiLian
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
spring:
|
||||
application:
|
||||
name: llmhub-core-service
|
||||
name: llmx-core-service
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
@ -4,7 +4,7 @@ spring:
|
||||
config:
|
||||
import: classpath:bootstrap-dev.yml
|
||||
application:
|
||||
name: llmhub-impl-baiLian
|
||||
name: llmx-impl-baiLian
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
@ -2,7 +2,7 @@ server:
|
||||
port: 9003
|
||||
spring:
|
||||
application:
|
||||
name: llmhub-impl-baiLian
|
||||
name: llmx-impl-baiLian
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: llmhub-impl-baiLian
|
||||
name: llmx-impl-baiLian
|
||||
profiles:
|
||||
active: dev
|
||||
# 阿里云配置
|
||||
99
scripts/entrypoint.sh
Normal file
99
scripts/entrypoint.sh
Normal file
@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
#set -x # 调试模式,可以启用以打印每行脚本的执行情况
|
||||
|
||||
# 设置默认的等待时间间隔,默认值为2秒
|
||||
: "${SLEEP_SECOND:=2}"
|
||||
# 设置默认的超时时间,默认值为60秒
|
||||
: "${TIMEOUT:=60}"
|
||||
|
||||
# 带时间戳+emoji的小型日志函数
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
|
||||
}
|
||||
|
||||
# 等待服务函数
|
||||
wait_for() {
|
||||
local host="$1"
|
||||
local port="$2"
|
||||
local timeout="$TIMEOUT"
|
||||
local start_time
|
||||
local current_time
|
||||
local elapsed_time
|
||||
local attempt=0
|
||||
|
||||
start_time=$(date +%s)
|
||||
log "🔄 开始等待依赖服务 $host:$port 可用 (超时时间: ${timeout}s, 间隔: ${SLEEP_SECOND}s)"
|
||||
|
||||
while ! nc -z "$host" "$port" 2>/dev/null; do
|
||||
current_time=$(date +%s)
|
||||
elapsed_time=$((current_time - start_time))
|
||||
attempt=$((attempt + 1))
|
||||
|
||||
if [ "$elapsed_time" -ge "$timeout" ]; then
|
||||
log "🛑 [ERROR] 等待超时!依赖服务 $host:$port 在 ${timeout}s 内未启动"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "🔄 第 ${attempt} 次检测:$host:$port 未就绪,已等待 ${elapsed_time}s..."
|
||||
sleep "$SLEEP_SECOND"
|
||||
done
|
||||
|
||||
total_time=$(( $(date +%s) - start_time ))
|
||||
log "✅ [SUCCESS] 依赖服务 $host:$port 已启动,耗时 ${total_time}s"
|
||||
return 0
|
||||
}
|
||||
|
||||
# 声明变量
|
||||
declare DEPENDS
|
||||
declare CMD
|
||||
|
||||
# 解析参数
|
||||
while getopts "d:c:" arg; do
|
||||
case "$arg" in
|
||||
d)
|
||||
DEPENDS="$OPTARG"
|
||||
;;
|
||||
c)
|
||||
CMD="$OPTARG"
|
||||
;;
|
||||
?)
|
||||
log "🛑 [ERROR] 未知参数"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# 检查依赖
|
||||
if [ -n "$DEPENDS" ]; then
|
||||
log "📦 检测到依赖服务列表: $DEPENDS"
|
||||
for var in ${DEPENDS//,/ }; do
|
||||
host=${var%:*}
|
||||
port=${var#*:}
|
||||
if [ -z "$host" ] || [ -z "$port" ]; then
|
||||
log "🛑 [ERROR] 依赖项格式错误: $var,应为 host:port"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! wait_for "$host" "$port"; then
|
||||
log "❌ [ERROR] 依赖服务 $host:$port 启动失败,终止执行"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
log "⚡️ 未配置依赖服务,跳过依赖检测"
|
||||
fi
|
||||
|
||||
# 执行命令
|
||||
if [ -n "$CMD" ]; then
|
||||
log "🚀 准备执行命令: $CMD"
|
||||
eval "$CMD"
|
||||
cmd_exit_code=$?
|
||||
if [ $cmd_exit_code -eq 0 ]; then
|
||||
log "✅ [SUCCESS] 命令执行完成,退出码: $cmd_exit_code"
|
||||
else
|
||||
log "❌ [ERROR] 命令执行失败,退出码: $cmd_exit_code"
|
||||
exit $cmd_exit_code
|
||||
fi
|
||||
else
|
||||
log "⚠️ [WARNING] 未指定要执行的命令,脚本结束"
|
||||
fi
|
||||
@ -13,8 +13,8 @@ project(":llmx-core:llmx-core-spi").name = "llmx-core-spi"
|
||||
|
||||
include(
|
||||
"llmx-impl",
|
||||
"llmx-impl:llmx-impl-baiLian",
|
||||
"llmx-impl:llmx-impl-bailian",
|
||||
// "llmx-impl:llmx-impl-openAi",
|
||||
)
|
||||
project(":llmx-impl:llmx-impl-baiLian").name = "llmx-impl-baiLian"
|
||||
project(":llmx-impl:llmx-impl-bailian").name = "llmx-impl-bailian"
|
||||
//project(":llmx-impl:llmx-impl-openAi").name = "llmx-impl-openAi"
|
||||
Loading…
x
Reference in New Issue
Block a user