Lu Xianghui 3 днів тому
батько
коміт
e52ce3d389
3 змінених файлів з 42 додано та 19 видалено
  1. 19 0
      .dockerignore
  2. 1 0
      .gitignore
  3. 22 19
      Dockerfile

+ 19 - 0
.dockerignore

@@ -0,0 +1,19 @@
+.git
+.gitignore
+.idea
+.venv
+__pycache__
+*.py[cod]
+*.pyo
+*.pyd
+.pytest_cache
+.mypy_cache
+.ruff_cache
+.coverage
+htmlcov
+logs
+*.log
+Dockerfile
+README.md
+wiki
+tests

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 .venv
 .idea
 logs
+.git

+ 22 - 19
Dockerfile

@@ -1,24 +1,27 @@
-FROM python:3.10-alpine
+FROM python:3.10-slim
 
-WORKDIR /root/workspace/
-COPY ./pyproject.toml ./
+ENV PYTHONUNBUFFERED=1 \
+    PYTHONDONTWRITEBYTECODE=1 \
+    PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ \
+    PIP_TRUSTED_HOST=mirrors.aliyun.com \
+    POETRY_VERSION=1.8.4 \
+    POETRY_NO_INTERACTION=1 \
+    TZ=Asia/Shanghai
 
-RUN MAIN_VERSION=$(cat /etc/alpine-release | cut -d '.' -f 0-2) \
-        && mv /etc/apk/repositories /etc/apk/repositories-bak \
-        && { echo "https://mirrors.aliyun.com/alpine/v${MAIN_VERSION}/main"; \
-        echo "https://mirrors.aliyun.com/alpine/v${MAIN_VERSION}/community"; } >> /etc/apk/repositories \
-        && apk add --update --no-cache tzdata gcc build-base libffi-dev curl && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
-        && mkdir ~/.pip \
-        && printf '[global]\nindex-url=https://mirrors.aliyun.com/pypi/simple/' > ~/.pip/pip.conf \
-        && python3 -m pip install --upgrade pip \
-        && curl -o poetry-install.py -SL https://install.python-poetry.org \
-        && python3 -u poetry-install.py \
-        && rm poetry-install.py \
-        && export PATH="/root/.local/bin:$PATH" \
-        && poetry config virtualenvs.create false --local \
-        && poetry install
+WORKDIR /root/workspace
 
-COPY . .
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends tzdata \
+    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
+    && echo $TZ > /etc/timezone \
+    && rm -rf /var/lib/apt/lists/* \
+    && python -m pip install --upgrade pip \
+    && pip install "poetry==$POETRY_VERSION" \
+    && poetry config virtualenvs.create false
+
+COPY pyproject.toml poetry.lock ./
+RUN poetry install --only main --no-root --no-ansi
 
+COPY . .
 
-CMD ["python", "-u", "main.py"]
+CMD ["python", "-u", "main.py"]