diff --git a/docker-compose.yaml b/docker-compose.yaml index cb0f157..8386350 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,6 +5,7 @@ services: selenium-redis-service: image: redis:7.0.5 container_name: selenium-redis-container + restart: always ports: - "6380:6379" @@ -13,8 +14,9 @@ services: build: ./selenium image: selenium-crawl-image:1.0 container_name: selenium-crawl-container - ports: - - "5001:5000" + restart: always + expose: + - "5000" environment: API_MODEL: "glm-4.5" API_BASE_URL: "https://open.bigmodel.cn/api/paas/v4" @@ -24,12 +26,13 @@ services: build: ./selenium_django image: selenium-django-image:1.0 container_name: selenium-django-container + restart: always environment: PYTHONUNBUFFERED: 1 CELERY_BROKER_URL: redis://selenium-redis-container:6379/0 CELERY_RESULT_BACKEND: redis://selenium-redis-container:6379/0 # Django 调用爬虫服务的地址 - CRAWL_API_URL: http://47.83.141.164:5001 + CRAWL_API_URL: http://selenium-crawl-container:5000/crawl # API 配置 API_MODEL: "glm-4-long" API_BASE_URL: "https://open.bigmodel.cn/api/paas/v4" @@ -39,22 +42,26 @@ services: depends_on: - selenium-redis-service - selenium-crawl-service - ports: - - "8002:8000" + expose: + - "8000" # ---------- 前端 Vue ---------- selenium-vue-service: build: - context: ./selenium_vue # 上一级目录 + context: ./selenium_vue dockerfile: Dockerfile args: - VITE_API_BASE_URL: http://47.83.141.164:8002 # 改为远程 IP - VITE_CRAWL_URL: http://47.83.141.164:5001 # 改为远程 IP + VITE_BASE_URL: /selenium_web/ + VITE_API_BASE_URL: /selenium_api + VITE_CRAWL_URL: /selenium_crawl_api image: selenium-vue-image:1.0 container_name: selenium-vue-container + restart: always environment: PORT: 80 NGINX_SERVER_NAME: localhost + volumes: + - "./nginx.conf:/etc/nginx/conf.d/default.conf" depends_on: - selenium-crawl-service - selenium-django-service diff --git a/selenium_django/Dockerfile b/selenium_django/Dockerfile index b31f1f3..f101b0b 100755 --- a/selenium_django/Dockerfile +++ b/selenium_django/Dockerfile @@ -16,9 +16,9 @@ COPY . . EXPOSE 8000 # 设置默认环境变量 -ENV CELERY_BROKER_URL=${CELERY_BROKER_URL:-redis://redis:6379/0} -ENV CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND:-redis://redis:6379/0} -ENV CRAWL_API_URL=${CRAWL_API_URL:-http://47.83.141.164:5001/crawl} +ENV CELERY_BROKER_URL=${CELERY_BROKER_URL:-redis://selenium-redis-container:6379/0} +ENV CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND:-redis://selenium-redis-container:6379/0} +ENV CRAWL_API_URL=${CRAWL_API_URL:-http://selenium-crawl-container:5000/crawl} # 入口脚本 COPY entrypoint.sh /entrypoint.sh diff --git a/selenium_django/selenium_django/settings.py b/selenium_django/selenium_django/settings.py index 8e1b13b..8f0b5b9 100755 --- a/selenium_django/selenium_django/settings.py +++ b/selenium_django/selenium_django/settings.py @@ -24,7 +24,7 @@ CELERY_RESULT_SERIALIZER = 'json' CELERY_TIMEZONE = 'Asia/Shanghai' # 根据你本地时区调整 # 爬虫api地址 -CRAWL_API_URL = os.environ.get("CRAWL_API_URL", "http://selenium:5000/crawl") +CRAWL_API_URL = os.environ.get("CRAWL_API_URL", "http://selenium-crawl-container:5000/crawl") # 模型api配置 api_info = { diff --git a/selenium_vue/Dockerfile b/selenium_vue/Dockerfile index 5642cfd..baa0b80 100755 --- a/selenium_vue/Dockerfile +++ b/selenium_vue/Dockerfile @@ -4,10 +4,12 @@ FROM node:18-alpine as builder # 设置工作目录 WORKDIR /app +ARG VITE_BASE_URL ARG VITE_API_BASE_URL ARG VITE_CRAWL_URL # 设置给构建时 Vite +ENV VITE_BASE_URL=${VITE_BASE_URL} ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} ENV VITE_CRAWL_URL=${VITE_CRAWL_URL} diff --git a/selenium_vue/frontend-vite/index.html b/selenium_vue/frontend-vite/index.html index ef4c3ea..4be1adc 100755 --- a/selenium_vue/frontend-vite/index.html +++ b/selenium_vue/frontend-vite/index.html @@ -4,6 +4,10 @@