You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
# ======================
|
|
# Build Stage(含 gcc)
|
|
# ======================
|
|
FROM python:3.10.16-slim AS builder
|
|
|
|
# 使用清华源(Debian 12 Bookworm)
|
|
RUN printf "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware\n\
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware\n\
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware\n" \
|
|
> /etc/apt/sources.list
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
gcc g++ unixodbc-dev default-libmysqlclient-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /build
|
|
COPY requirements.txt .
|
|
|
|
RUN pip install --no-cache-dir --prefix=/python_install \
|
|
-r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
|
|
# ======================
|
|
# Runtime Stage(无 gcc)
|
|
# ======================
|
|
FROM python:3.10.16-slim
|
|
|
|
# 使用清华源(HTTPS)
|
|
RUN printf "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware\n\
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware\n\
|
|
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware\n" \
|
|
> /etc/apt/sources.list
|
|
|
|
# pyodbc 必须安装 libodbc1(提供 libodbc.so.2)
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
libodbc1 unixodbc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
# 复制已编译好的依赖
|
|
COPY --from=builder /python_install /usr/local
|
|
|
|
# 复制代码
|
|
COPY . .
|
|
|
|
RUN mkdir -p /opt/alert/model-lab \
|
|
&& cp /app/config.py /opt/alert/model-lab/config.py
|
|
|
|
CMD ["python", "app.py"]
|
|
|