Skip to content

Instantly share code, notes, and snippets.

@akkuman
Created November 8, 2023 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkuman/0e9eb24d38bf78411a75aa31d1dd71e5 to your computer and use it in GitHub Desktop.
Save akkuman/0e9eb24d38bf78411a75aa31d1dd71e5 to your computer and use it in GitHub Desktop.
poetry poetry 项目 Dockerfile
# syntax=docker/dockerfile:experimental
FROM python:3.9.5-buster as base
ENV POETRY_HOME=/opt/poetry
RUN python3 -m venv $POETRY_HOME && \
python3 -m pip install --upgrade pip -i https://mirror.sjtu.edu.cn/pypi/web/simple && \
$POETRY_HOME/bin/pip install poetry==1.2.2 -i https://mirror.sjtu.edu.cn/pypi/web/simple && \
$POETRY_HOME/bin/poetry --version && \
python3 -m pip install --no-cache-dir --no-compile wheel -i https://mirror.sjtu.edu.cn/pypi/web/simple
COPY pyproject.toml poetry.lock /deps/
RUN cd /deps/ && \
# 生成依赖文件
$POETRY_HOME/bin/poetry export -f requirements.txt --output requirements.txt --without-hashes && \
# 修复 https://github.com/pypa/pip/issues/11511,等待 pr https://github.com/pypa/pip/pull/11621
# 将extra-index-url移至index-url后面
sed -i -e '$!N;s/\(--extra-index-url.*\)\(\n\)\(--index-url.*\)/\3\2\1/;t' -e 'P;D' requirements.txt && \
# 将依赖打包
python3 -m pip wheel -r requirements.txt --wheel-dir=/svc/wheels
FROM python:3.9.5-slim-buster
LABEL maintainer="Akkuman<akkumans@qq.com> (http://akkuman.cnblogs.com)"
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai \
PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
# pip:
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100
WORKDIR /app
# 安装依赖
RUN --mount=type=bind,from=base,source=/svc/wheels,target=/tmp/wheels pip3 install --no-cache-dir --no-compile /tmp/wheels/*
# 复制应用文件到目录下
COPY config /app/config
COPY core /app/core
COPY log /app/log
COPY task /app/task
COPY utils /app/utils
COPY main.py /app/
CMD ["python", "main.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment