feat: 修改docker配置添加AI的微服务

This commit is contained in:
zerosaturation 2026-05-29 21:37:08 +08:00
parent 1aca524f99
commit 64809ea308
6 changed files with 123 additions and 9 deletions

View File

@ -48,7 +48,10 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
echo "Built taskservice" && \ echo "Built taskservice" && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
-o /tmp/starbookservice services/starbookService/main.go && \ -o /tmp/starbookservice services/starbookService/main.go && \
echo "Built starbookservice" echo "Built starbookservice" && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
-o /tmp/aichatservice services/aiChatService/main.go && \
echo "Built aichatservice"
# ---- Runtime Stage: Gateway ---- # ---- Runtime Stage: Gateway ----
FROM --platform=linux/amd64 alpine:3.19 AS gateway FROM --platform=linux/amd64 alpine:3.19 AS gateway
@ -171,3 +174,18 @@ HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:21005 || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:21005 || exit 1
ENTRYPOINT ["/app/starbookservice"] ENTRYPOINT ["/app/starbookservice"]
# ---- Runtime Stage: AIChatService ----
FROM --platform=linux/amd64 alpine:3.19 AS aichatservice
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
COPY --from=builder /tmp/aichatservice /app/aichatservice
EXPOSE 20008
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:21008 || exit 1
ENTRYPOINT ["/app/aichatservice"]

View File

@ -77,7 +77,7 @@ while [[ $# -gt 0 ]]; do
echo "" echo ""
echo "服务名 (可选):" echo "服务名 (可选):"
echo " gateway, userService, socialService, assetService," echo " gateway, userService, socialService, assetService,"
echo " galleryService, activityService, taskService, starbookService" echo " galleryService, activityService, taskService, starbookService, aiChatService"
echo "" echo ""
echo "示例:" echo "示例:"
echo " $0 # 构建所有服务" echo " $0 # 构建所有服务"
@ -98,6 +98,7 @@ while [[ $# -gt 0 ]]; do
activity|activityService) SERVICES+=("activityService") ;; activity|activityService) SERVICES+=("activityService") ;;
task|taskService) SERVICES+=("taskService") ;; task|taskService) SERVICES+=("taskService") ;;
starbook|starbookService) SERVICES+=("starbookService") ;; starbook|starbookService) SERVICES+=("starbookService") ;;
ai|aiChatService|aichatservice) SERVICES+=("aiChatService") ;;
all) all)
# all 关键字,构建所有服务 # all 关键字,构建所有服务
SERVICES=() SERVICES=()
@ -116,7 +117,7 @@ done
# ==================== 服务列表 ==================== # ==================== 服务列表 ====================
# 所有可用服务及其配置(使用小写 target 名) # 所有可用服务及其配置(使用小写 target 名)
ALL_SERVICES_NAME=("gateway" "userservice" "socialservice" "assetservice" "galleryservice" "activityservice" "taskservice" "starbookservice") ALL_SERVICES_NAME=("gateway" "userservice" "socialservice" "assetservice" "galleryservice" "activityservice" "taskservice" "starbookservice" "aichatservice")
# 确定要构建的服务 # 确定要构建的服务
if [ ${#SERVICES[@]} -eq 0 ]; then if [ ${#SERVICES[@]} -eq 0 ]; then
@ -205,6 +206,7 @@ main() {
activityservice) docker_target="activityservice" ;; activityservice) docker_target="activityservice" ;;
taskservice) docker_target="taskservice" ;; taskservice) docker_target="taskservice" ;;
starbookservice) docker_target="starbookservice" ;; starbookservice) docker_target="starbookservice" ;;
aichatservice) docker_target="aichatservice" ;;
# 兼容旧的大写服务名 # 兼容旧的大写服务名
userService) docker_target="userservice" ;; userService) docker_target="userservice" ;;
socialService) docker_target="socialservice" ;; socialService) docker_target="socialservice" ;;

View File

@ -78,6 +78,7 @@ SERVICES=(
"activityservice" "activityservice"
"taskservice" "taskservice"
"starbookservice" "starbookservice"
"aichatservice"
) )
# ==================== 服务器配置 ==================== # ==================== 服务器配置 ====================

View File

@ -259,6 +259,45 @@ services:
reservations: reservations:
memory: 256M memory: 256M
# ==================== AI Chat Service ====================
aichatservice:
image: topfans/aichatservice:latest
build:
context: ..
dockerfile: docker/Dockerfile.services
target: aichatservice
container_name: topfans-aichatservice
restart: unless-stopped
environment:
<<: *common-env
PORT: 20008
DB_HOST: host.docker.internal
DB_PORT: 15432
REDIS_HOST: host.docker.internal
REDIS_PORT: 6379
REDIS_DB: 0
MINIMAX_API_KEY: ${MINIMAX_API_KEY:-}
MINIMAX_API_URL: ${MINIMAX_API_URL:-https://api.minimaxi.com/v1}
MINIMAX_MODEL: ${MINIMAX_MODEL:-M2-her}
QWEN_API_KEY: ${QWEN_API_KEY:-}
QWEN_API_URL: ${QWEN_API_URL:-https://dashscope.aliyuncs.com/compatible-mode/v1}
QWEN_MODEL: ${QWEN_MODEL:-qwen-plus}
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- topfans-net
expose:
- "20008"
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 20008 || exit 1"]
<<: *healthcheck
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
# ==================== API Gateway ==================== # ==================== API Gateway ====================
gateway: gateway:
image: topfans/gateway:latest image: topfans/gateway:latest
@ -279,6 +318,7 @@ services:
DUBBO_ACTIVITY_SERVICE_URL: tri://activityservice:20005 DUBBO_ACTIVITY_SERVICE_URL: tri://activityservice:20005
DUBBO_TASK_SERVICE_URL: tri://taskservice:20006 DUBBO_TASK_SERVICE_URL: tri://taskservice:20006
DUBBO_STARBOOK_SERVICE_URL: tri://starbookservice:20007 DUBBO_STARBOOK_SERVICE_URL: tri://starbookservice:20007
DUBBO_AI_CHAT_SERVICE_URL: tri://aichatservice:20008
depends_on: depends_on:
userservice: userservice:
condition: service_healthy condition: service_healthy
@ -294,6 +334,8 @@ services:
condition: service_healthy condition: service_healthy
starbookservice: starbookservice:
condition: service_healthy condition: service_healthy
aichatservice:
condition: service_healthy
networks: networks:
- topfans-net - topfans-net
ports: ports:

View File

@ -389,6 +389,54 @@ services:
memory: 64M memory: 64M
cpus: '0.25' cpus: '0.25'
# ==================== AI Chat Service ====================
aichatservice:
image: topfans/aichatservice:latest
build:
context: ..
dockerfile: docker/Dockerfile.services
target: aichatservice
container_name: topfans-aichatservice
restart: always
environment:
<<: *common-env
PORT: 20008
DB_HOST: postgres
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: ${DB_PASSWORD:-postgres123}
DB_NAME: topfans
REDIS_HOST: topfans-redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-123456}
REDIS_DB: 0
MINIMAX_API_KEY: ${MINIMAX_API_KEY:-}
MINIMAX_API_URL: ${MINIMAX_API_URL:-https://api.minimaxi.com/v1}
MINIMAX_MODEL: ${MINIMAX_MODEL:-M2-her}
QWEN_API_KEY: ${QWEN_API_KEY:-}
QWEN_API_URL: ${QWEN_API_URL:-https://dashscope.aliyuncs.com/compatible-mode/v1}
QWEN_MODEL: ${QWEN_MODEL:-qwen-plus}
depends_on:
userservice:
condition: service_started
redis:
condition: service_healthy
networks:
- topfans-net
expose:
- "20008"
healthcheck:
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:21008 || exit 1"]
<<: *healthcheck
deploy:
resources:
limits:
memory: 512M
cpus: '1'
reservations:
memory: 256M
cpus: '0.5'
# ==================== API Gateway ==================== # ==================== API Gateway ====================
gateway: gateway:
image: topfans/gateway:latest image: topfans/gateway:latest
@ -411,6 +459,7 @@ services:
DUBBO_ACTIVITY_SERVICE_URL: tri://activityservice:20004 DUBBO_ACTIVITY_SERVICE_URL: tri://activityservice:20004
DUBBO_TASK_SERVICE_URL: tri://taskservice:20006 DUBBO_TASK_SERVICE_URL: tri://taskservice:20006
DUBBO_STARBOOK_SERVICE_URL: tri://starbookservice:20005 DUBBO_STARBOOK_SERVICE_URL: tri://starbookservice:20005
DUBBO_AI_CHAT_SERVICE_URL: tri://aichatservice:20008
REDIS_HOST: topfans-redis REDIS_HOST: topfans-redis
REDIS_PORT: 6379 REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-123456} REDIS_PASSWORD: ${REDIS_PASSWORD:-123456}
@ -430,6 +479,8 @@ services:
condition: service_started condition: service_started
starbookservice: starbookservice:
condition: service_started condition: service_started
aichatservice:
condition: service_started
redis: redis:
condition: service_healthy condition: service_healthy
networks: networks:

View File

@ -11,31 +11,31 @@
<!-- 功能按钮区域 --> <!-- 功能按钮区域 -->
<view class="action-buttons"> <view class="action-buttons">
<!-- 装扮按钮 --> <!-- 装扮按钮 -->
<view class="action-btn dressup-btn" @click="handleDressup"> <!-- <view class="action-btn dressup-btn" @click="handleDressup">
<image class="btn-icon" src="/static/AIimg/zhuanban.png" mode="aspectFit" /> <image class="btn-icon" src="/static/AIimg/zhuanban.png" mode="aspectFit" />
<view class="btn-label-wrap"> <view class="btn-label-wrap">
<image class="btn-label-bg" src="/static/nft/dingbutubiao_an.png" mode="aspectFit" /> <image class="btn-label-bg" src="/static/nft/dingbutubiao_an.png" mode="aspectFit" />
<text class="btn-label-text">装扮</text> <text class="btn-label-text">装扮</text>
</view> </view>
</view> </view> -->
<!-- 场景按钮 --> <!-- 场景按钮 -->
<view class="action-btn scene-btn" @click="handleScene"> <!-- <view class="action-btn scene-btn" @click="handleScene">
<image class="btn-icon" src="/static/AIimg/changjing.png" mode="aspectFit" /> <image class="btn-icon" src="/static/AIimg/changjing.png" mode="aspectFit" />
<view class="btn-label-wrap"> <view class="btn-label-wrap">
<image class="btn-label-bg" src="/static/nft/dingbutubiao_an.png" mode="aspectFit" /> <image class="btn-label-bg" src="/static/nft/dingbutubiao_an.png" mode="aspectFit" />
<text class="btn-label-text">场景</text> <text class="btn-label-text">场景</text>
</view> </view>
</view> </view> -->
<!-- 追星历程按钮 --> <!-- 追星历程按钮 -->
<view class="action-btn history-btn" @click="handleHistory"> <!-- <view class="action-btn history-btn" @click="handleHistory">
<image class="btn-icon" src="/static/AIimg/zhuixinglicheng.png" mode="aspectFit" /> <image class="btn-icon" src="/static/AIimg/zhuixinglicheng.png" mode="aspectFit" />
<view class="btn-label-wrap"> <view class="btn-label-wrap">
<image class="btn-label-bg" src="/static/nft/dingbutubiao_an.png" mode="aspectFit" /> <image class="btn-label-bg" src="/static/nft/dingbutubiao_an.png" mode="aspectFit" />
<text class="btn-label-text">追星历程</text> <text class="btn-label-text">追星历程</text>
</view> </view>
</view> </view> -->
</view> </view>
<!-- AI角色对话气泡 --> <!-- AI角色对话气泡 -->