feat(docker): 重构Docker配置以支持生产环境部署
- 添加Dockerfile.dev用于开发环境 - 重构主Dockerfile使用多阶段构建 - 添加nginx配置和entrypoint脚本 - 更新docker-compose.yml配置 - 修改API基础路径为相对路径 - 更新vite配置支持环境变量
This commit is contained in:
@@ -11,3 +11,4 @@ coverage
|
|||||||
.nyc_output
|
.nyc_output
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
Dockerfile.dev
|
||||||
|
|||||||
7
.env.example
Normal file
7
.env.example
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# API Base URL
|
||||||
|
# 默认值: https://thinkflow.lz-t.top
|
||||||
|
API_BASE_URL=https://thinkflow.lz-t.top
|
||||||
|
|
||||||
|
# API Host (用于 Nginx 代理的 Host 头)
|
||||||
|
# 默认值: thinkflow.lz-t.top
|
||||||
|
API_HOST=thinkflow.lz-t.top
|
||||||
18
Dockerfile
18
Dockerfile
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-alpine
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -8,6 +8,18 @@ RUN npm install
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 5173
|
RUN npm run build
|
||||||
|
|
||||||
CMD ["npm", "run", "dev", "--", "--host"]
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
COPY nginx.conf.template /etc/nginx/templates/nginx.conf.template
|
||||||
|
|
||||||
|
COPY entrypoint.sh /docker-entrypoint.sh
|
||||||
|
|
||||||
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["/docker-entrypoint.sh"]
|
||||||
|
|||||||
13
Dockerfile.dev
Normal file
13
Dockerfile.dev
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
EXPOSE 5173
|
||||||
|
|
||||||
|
CMD ["npm", "run", "dev", "--", "--host"]
|
||||||
@@ -5,12 +5,10 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: thinkflow-app
|
container_name: thinkflow
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "80:80"
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
- /app/node_modules
|
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=development
|
- API_BASE_URL=${API_BASE_URL:-https://thinkflow.lz-t.top}
|
||||||
|
- API_HOST=${API_HOST:-thinkflow.lz-t.top}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
5
entrypoint.sh
Normal file
5
entrypoint.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
envsubst '${API_BASE_URL} ${API_HOST}' < /etc/nginx/templates/nginx.conf.template > /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
exec nginx -g 'daemon off;'
|
||||||
29
nginx.conf
Normal file
29
nginx.conf
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/chat {
|
||||||
|
proxy_pass https://thinkflow.lz-t.top/chat/completions;
|
||||||
|
proxy_set_header Host thinkflow.lz-t.top;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/image {
|
||||||
|
proxy_pass https://thinkflow.lz-t.top/images/generations;
|
||||||
|
proxy_set_header Host thinkflow.lz-t.top;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||||
|
}
|
||||||
29
nginx.conf.template
Normal file
29
nginx.conf.template
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/chat {
|
||||||
|
proxy_pass ${API_BASE_URL}/chat/completions;
|
||||||
|
proxy_set_header Host ${API_HOST};
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/image {
|
||||||
|
proxy_pass ${API_BASE_URL}/images/generations;
|
||||||
|
proxy_set_header Host ${API_HOST};
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||||
|
}
|
||||||
@@ -49,12 +49,12 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
*/
|
*/
|
||||||
const DEFAULT_CONFIG = {
|
const DEFAULT_CONFIG = {
|
||||||
chat: {
|
chat: {
|
||||||
baseUrl: 'https://thinkflow.lz-t.top/chat/completions',
|
baseUrl: '/api/chat',
|
||||||
model: 'glm-4-flash',
|
model: 'glm-4-flash',
|
||||||
apiKey: ''
|
apiKey: ''
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
baseUrl: 'https://thinkflow.lz-t.top/images/generations',
|
baseUrl: '/api/image',
|
||||||
model: 'cogview-3-flash',
|
model: 'cogview-3-flash',
|
||||||
apiKey: ''
|
apiKey: ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
export default defineConfig(({ mode }) => {
|
||||||
export default defineConfig({
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
plugins: [vue()],
|
|
||||||
server: {
|
return {
|
||||||
host: '0.0.0.0', // 允许通过 IP 访问
|
plugins: [vue()],
|
||||||
port: 5173, // 你可以根据需要修改端口
|
server: {
|
||||||
},
|
host: '0.0.0.0',
|
||||||
resolve: {
|
port: 5173,
|
||||||
alias: {
|
proxy: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
'/api/chat': {
|
||||||
|
target: env.VITE_API_BASE_URL || 'https://thinkflow.lz-t.top',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/api\/chat/, '/chat/completions')
|
||||||
|
},
|
||||||
|
'/api/image': {
|
||||||
|
target: env.VITE_API_BASE_URL || 'https://thinkflow.lz-t.top',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/api\/image/, '/images/generations')
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': path.resolve(__dirname, './src'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user