统一部署配置文件规范

This commit is contained in:
537yaha
2026-01-07 18:00:19 +08:00
parent ed97b62eb3
commit 336a586679
8 changed files with 63 additions and 9 deletions
+6 -1
View File
@@ -29,6 +29,7 @@ jobs:
file: ./backend/Dockerfile
push: true
tags: 537yaha/ai-cs-backend:latest
platforms: linux/amd64,linux/arm64
build-frontend:
runs-on: ubuntu-latest
@@ -51,4 +52,8 @@ jobs:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: 537yaha/ai-cs-frontend:latest
tags: 537yaha/ai-cs-frontend:latest
platforms: linux/amd64,linux/arm64
build-args: |
NEXT_PUBLIC_API_BASE_URL=http://localhost:18080
NEXT_PUBLIC_BACKEND_PORT=18080
+23 -1
View File
@@ -80,6 +80,14 @@ docker-compose -f docker-compose.prod.yml up -d
- 用户名:`admin`(或 `.env` 中配置的 `ADMIN_USERNAME`
- 密码:`.env` 中配置的 `ADMIN_PASSWORD`
#### 端口配置
**默认端口**:后端 `18080`,前端 `3000`
**修改端口**:在 `.env` 文件中设置 `BACKEND_PORT``FRONTEND_PORT`
⚠️ **注意**:预构建镜像的图片加载已硬编码为 `18080` 端口,如需修改端口,请使用方式二(本地构建)重新构建镜像。
#### 常用命令
```bash
@@ -162,6 +170,15 @@ docker-compose ps
- 用户名:`admin`(或 `.env` 中配置的 `ADMIN_USERNAME`
- 密码:`.env` 中配置的 `ADMIN_PASSWORD`
#### 端口配置
**默认端口**:后端 `18080`,前端 `3000`
**修改端口**:在 `.env` 文件中设置 `BACKEND_PORT``FRONTEND_PORT`,然后重新构建:
```bash
docker-compose up -d --build
```
#### 常用命令
```bash
@@ -216,7 +233,7 @@ ADMIN_PASSWORD=your_admin_password
# 服务器配置
SERVER_HOST=0.0.0.0
SERVER_PORT=8080
SERVER_PORT=18080 # 默认端口 18080,可修改
GIN_MODE=debug
# 加密密钥(用于加密 AI API Keys,可选)
@@ -244,6 +261,11 @@ npm install
npm run dev
```
**端口配置**
- 后端端口:修改 `backend/.env` 中的 `SERVER_PORT`(默认 `8080`
- 前端端口:启动时通过 `PORT` 环境变量修改,如 `PORT=4000 npm run dev`
- 图片加载端口:创建 `frontend/.env.local`,设置 `NEXT_PUBLIC_BACKEND_PORT=你的后端端口`
#### 4. 访问应用
- **官网首页**: http://localhost:3000
+1 -1
View File
@@ -42,7 +42,7 @@ services:
GIN_MODE: ${GIN_MODE:-release}
ENCRYPTION_KEY: ${ENCRYPTION_KEY:-default-key}
ports:
- "${BACKEND_PORT:-8080}:8080"
- "${BACKEND_PORT:-18080}:8080"
volumes:
- ./backend/uploads:/app/uploads
depends_on:
+2 -1
View File
@@ -44,7 +44,7 @@ services:
GIN_MODE: ${GIN_MODE:-release}
ENCRYPTION_KEY: ${ENCRYPTION_KEY:-default-key}
ports:
- "${BACKEND_PORT:-8080}:8080"
- "${BACKEND_PORT:-18080}:8080"
volumes:
- ./backend/uploads:/app/uploads
depends_on:
@@ -61,6 +61,7 @@ services:
dockerfile: Dockerfile
args:
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL:-http://localhost:8080}
NEXT_PUBLIC_BACKEND_PORT: ${BACKEND_PORT:-18080}
container_name: ai-cs-frontend
ports:
- "${FRONTEND_PORT:-3000}:3000"
+4
View File
@@ -18,6 +18,10 @@ COPY . .
ARG NEXT_PUBLIC_API_BASE_URL
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
# 后端端口配置(用于图片加载等)
ARG NEXT_PUBLIC_BACKEND_PORT=18080
ENV NEXT_PUBLIC_BACKEND_PORT=$NEXT_PUBLIC_BACKEND_PORT
# 构建 Next.js 应用
RUN npm run build
+10
View File
@@ -21,6 +21,9 @@ export const metadata: Metadata = {
// Matomo 容器 URL(格式:container_*.js
const MATOMO_CONTAINER_URL = process.env.NEXT_PUBLIC_MATOMO_CONTAINER_URL || '';
// 后端端口配置(用于 widget.js)
const BACKEND_PORT = process.env.NEXT_PUBLIC_BACKEND_PORT || '18080';
export default function RootLayout({
children,
}: Readonly<{
@@ -28,6 +31,13 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<head>
<script
dangerouslySetInnerHTML={{
__html: `window.AICS_BACKEND_PORT = '${BACKEND_PORT}';`,
}}
/>
</head>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
+6 -3
View File
@@ -1,5 +1,8 @@
import type { NextConfig } from "next";
// 从环境变量读取后端端口,默认 18080(避免与常用端口冲突)
const backendPort = process.env.NEXT_PUBLIC_BACKEND_PORT || "18080";
const nextConfig: NextConfig = {
eslint: {
ignoreDuringBuilds: true, // 临时禁用构建时的 ESLint 检查
@@ -9,19 +12,19 @@ const nextConfig: NextConfig = {
{
protocol: "http",
hostname: "192.168.124.9",
port: "8080",
port: backendPort,
pathname: "/uploads/**",
},
{
protocol: "http",
hostname: "localhost",
port: "8080",
port: backendPort,
pathname: "/uploads/**",
},
{
protocol: "http",
hostname: "127.0.0.1",
port: "8080",
port: backendPort,
pathname: "/uploads/**",
},
],
+11 -2
View File
@@ -15,9 +15,18 @@
(function() {
'use strict';
// 配置
// 配置(从全局变量或默认值读取后端端口)
const getDefaultBackendPort = () => {
// 优先使用全局变量(可在页面中通过 script 标签设置)
if (typeof window !== 'undefined' && window.AICS_BACKEND_PORT) {
return window.AICS_BACKEND_PORT;
}
// 默认端口 18080(避免与常用端口冲突)
return '18080';
};
const defaultConfig = {
apiUrl: 'http://localhost:8080',
apiUrl: 'http://localhost:' + getDefaultBackendPort(),
position: 'bottom-right', // 'bottom-right' | 'bottom-left'
theme: 'default'
};