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