From 24169bd27723149c2034739fc499b65c98efa765 Mon Sep 17 00:00:00 2001 From: Huarch Date: Thu, 11 Jun 2026 10:26:36 +0800 Subject: [PATCH] fix(docker): align customer image build --- .dockerignore | 18 ++++++++++++++++++ Dockerfile | 18 +++++++++++------- infra/docker/docker-compose.yml | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..44aa59a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +.git +.github +.gitea +__pycache__/ +.pytest_cache/ +.mypy_cache/ +.venv/ +venv/ +build/ +dist/ +package/ +temp/ +data/ +# db_inp/ +inp/ +# .env +*.pyc +*.dump diff --git a/Dockerfile b/Dockerfile index 7182cac..b10b3b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,25 @@ -FROM continuumio/miniconda3:latest +FROM condaforge/miniforge3:latest WORKDIR /app +ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \ + PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn \ + UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple + # 安装 Python 3.12 和 pymetis (通过 conda-forge 避免编译问题) -RUN conda install -y -c conda-forge python=3.12 pymetis && \ - conda clean -afy +RUN mamba install -y python=3.12 pymetis && \ + mamba clean -afy COPY requirements.txt . -RUN pip install uv -RUN uv pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir uv +RUN uv pip install --system --no-cache-dir -r requirements.txt # 将代码放入子目录 'app',将数据放入子目录 'db_inp' # 这样临时文件默认会生成在 /app 下,而代码在 /app/app 下,实现了分离 COPY app ./app -COPY db_inp ./db_inp -COPY temp ./temp +# COPY db_inp ./db_inp COPY .env . +RUN mkdir -p db_inp temp data inp # 设置 PYTHONPATH 以便 uvicorn 找到 app 模块 ENV PYTHONPATH=/app diff --git a/infra/docker/docker-compose.yml b/infra/docker/docker-compose.yml index abbd2c7..6b938fa 100644 --- a/infra/docker/docker-compose.yml +++ b/infra/docker/docker-compose.yml @@ -5,7 +5,7 @@ services: api: build: context: ../.. - dockerfile: infra/docker/Dockerfile + dockerfile: Dockerfile container_name: tjwater_api restart: always ports: