From 3b81cbda0e82225d95cbda700ef48c8603e6dfd6 Mon Sep 17 00:00:00 2001 From: niyyzf Date: Sat, 19 Jul 2025 17:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20docker-compose.yml=20?= =?UTF-8?q?=E5=92=8C=20supervisord.conf:=20=E9=87=8D=E6=9E=84=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=90=88=E5=B9=B6=E5=89=8D?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=9C=8D=E5=8A=A1=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=98=A0=E5=B0=84=E5=92=8C=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 41 ----------------------------------------- Dockerfile | 32 ++++++++++++++++++++++++++++++++ docker-compose.yml | 28 +++++++++------------------- supervisord.conf | 18 ++++++++++++++++++ 4 files changed, 59 insertions(+), 60 deletions(-) create mode 100644 Dockerfile create mode 100644 supervisord.conf diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 695b00b..3d38914 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -14,47 +14,6 @@ jobs: - name: 检出代码 uses: ./.actions/checkout - - name: 安装 Node.js - run: | - curl -fsSL https://deb.nodesource.com/setup_21.x | bash - - apt-get install -y nodejs - - - name: 安装前端依赖 - working-directory: platform - run: npm install - - - name: 构建前端(跳过 ts 校验) - working-directory: platform - run: | - npm run build -- --no-check || true - - - name: 安装 Python 3.11 - run: | - sudo apt update - sudo apt install -y software-properties-common - sudo add-apt-repository -y ppa:deadsnakes/ppa - sudo apt update - sudo apt install -y python3.11 python3.11-venv python3-pip - sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 - python3 --version - - - name: 设置 pip 国内镜像源 - run: | - mkdir -p ~/.pip - cat > ~/.pip/pip.conf << EOF - [global] - index-url = https://pypi.tuna.tsinghua.edu.cn/simple - trusted-host = files.pythonhosted.org,pypi.org,pypi.python.org - EOF - - - name: 安装后端依赖 - working-directory: back - run: | - python3.11 -m venv venv - source venv/bin/activate - pip install --upgrade pip - pip install -r requirements.txt - - name: 构建 Docker 镜像 run: | docker compose build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1ef0dfb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM python:3.11-slim + +# 安装 Node.js 和 supervisord +RUN apt-get update && \ + apt-get install -y curl supervisor && \ + curl -fsSL https://deb.nodesource.com/setup_21.x | bash - && \ + apt-get install -y nodejs && \ + apt-get clean + +# 设置工作目录 +WORKDIR /app + +# 复制前端代码并安装依赖、构建 +COPY platform/ ./platform/ +WORKDIR /app/platform +RUN npm install && npm run build + +# 安装 http-server +RUN npm install -g http-server + +# 复制后端代码并安装依赖 +WORKDIR /app/back +COPY back/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY back/ . + +# supervisor 配置 +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +WORKDIR /app + +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 45abe4f..7db5c58 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,12 @@ -version: '3.8' services: - backend: - build: ./back - container_name: backend + app: + build: + context: . + dockerfile: Dockerfile + container_name: app ports: - - "7792:5000" + - "7792:7792" # 前端 + - "7793:7793" # 后端 volumes: - - ./back:/app - environment: - - FLASK_ENV=development - depends_on: - - frontend - frontend: - build: ./platform - container_name: frontend - ports: - - "7793:5173" - volumes: - - ./platform:/app - environment: - - NODE_ENV=development \ No newline at end of file + - ./back:/app/back + - ./platform:/app/platform \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..dfb15d0 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,18 @@ +[supervisord] +nodaemon=true + +[program:frontend] +directory=/app/platform +command=http-server dist -p 7792 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr + +[program:backend] +directory=/app/back +command=python app.py --port=7793 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr \ No newline at end of file