From cd5d0a668d4d8661f083cdba56f80782953ecd94 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Sun, 8 Feb 2026 22:37:30 +0800 Subject: [PATCH] Update docker compose for frontend --- docker/docker-compose.yml | 27 ++++++++++++++++++--------- web/.dockerignore | 7 +++++++ web/Dockerfile | 24 ++++++++++++++++++++++++ web/services/apiClient.ts | 2 +- 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 web/.dockerignore create mode 100644 web/Dockerfile diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f38b875..70b0923 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,10 +4,10 @@ services: # 后端 API backend: build: - context: ./backend + context: ../api dockerfile: Dockerfile ports: - - "8000:8000" + - "8100:8100" environment: - DATABASE_URL=sqlite:///./data/app.db - MINIO_ENDPOINT=minio:9000 @@ -15,20 +15,32 @@ services: - MINIO_SECRET_KEY=password123 - MINIO_BUCKET=ai-audio volumes: - - ./backend:/app - - ./backend/data:/app/data + - ../api:/app + - ../api/data:/app/data depends_on: - minio # 对话引擎 (py-active-call) engine: build: - context: ../py-active-call + context: ../engine dockerfile: Dockerfile ports: - "8001:8001" environment: - - BACKEND_URL=http://backend:8000 + - BACKEND_URL=http://backend:8100 + depends_on: + - backend + + # 前端 (Vite + React) + frontend: + build: + context: ../web + dockerfile: Dockerfile + args: + - VITE_API_BASE_URL=http://localhost:8100/api + ports: + - "6000:6000" depends_on: - backend @@ -44,6 +56,3 @@ services: MINIO_ROOT_USER: admin MINIO_ROOT_PASSWORD: password123 command: server /data --console-address ":9001" - -volumes: - minio-data: diff --git a/web/.dockerignore b/web/.dockerignore new file mode 100644 index 0000000..b2fef1e --- /dev/null +++ b/web/.dockerignore @@ -0,0 +1,7 @@ +node_modules +dist +.git +.gitignore +*.md +.env +.env.* diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..ed27eea --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,24 @@ +# Build stage +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . +ARG VITE_API_BASE_URL=http://localhost:8100/api +ENV VITE_API_BASE_URL=$VITE_API_BASE_URL +RUN npm run build + +# Serve stage (no nginx – Node + serve on port 6000) +FROM node:20-alpine + +RUN npm install -g serve + +WORKDIR /app +COPY --from=builder /app/dist ./dist + +EXPOSE 6000 + +CMD ["serve", "-s", "dist", "-l", "6000"] diff --git a/web/services/apiClient.ts b/web/services/apiClient.ts index 3008828..57b04fd 100644 --- a/web/services/apiClient.ts +++ b/web/services/apiClient.ts @@ -1,4 +1,4 @@ -const DEFAULT_API_BASE_URL = 'http://localhost:8000/api'; +const DEFAULT_API_BASE_URL = 'http://localhost:8100/api'; const trimTrailingSlash = (value: string): string => value.replace(/\/+$/, '');