54 lines
2.1 KiB
Docker
54 lines
2.1 KiB
Docker
FROM python:3.11-slim
|
||
|
||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||
PYTHONUNBUFFERED=1
|
||
|
||
WORKDIR /app
|
||
|
||
# APT 镜像源(默认使用清华 TUNA;如需切回官方源可在 build 时覆盖该参数)
|
||
# 示例:docker build --build-arg APT_MIRROR=deb.debian.org -t connecthub .
|
||
ARG APT_MIRROR=mirrors.tuna.tsinghua.edu.cn
|
||
|
||
RUN set -eux; \
|
||
# 兼容 Debian 新旧 sources 格式(/etc/apt/sources.list 或 deb822 的 /etc/apt/sources.list.d/debian.sources)
|
||
if [ -f /etc/apt/sources.list ]; then \
|
||
sed -i "s|http://deb.debian.org/debian|https://${APT_MIRROR}/debian|g" /etc/apt/sources.list; \
|
||
sed -i "s|http://security.debian.org/debian-security|https://${APT_MIRROR}/debian-security|g" /etc/apt/sources.list; \
|
||
fi; \
|
||
if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
|
||
sed -i "s|URIs: http://deb.debian.org/debian|URIs: https://${APT_MIRROR}/debian|g" /etc/apt/sources.list.d/debian.sources; \
|
||
sed -i "s|URIs: http://security.debian.org/debian-security|URIs: https://${APT_MIRROR}/debian-security|g" /etc/apt/sources.list.d/debian.sources; \
|
||
fi; \
|
||
apt-get update; \
|
||
apt-get install -y --no-install-recommends \
|
||
build-essential \
|
||
ca-certificates \
|
||
curl \
|
||
gnupg \
|
||
unixodbc \
|
||
unixodbc-dev \
|
||
apt-transport-https \
|
||
&& rm -rf /var/lib/apt/lists/*; \
|
||
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg; \
|
||
. /etc/os-release; \
|
||
arch="$(dpkg --print-architecture)"; \
|
||
codename="${VERSION_CODENAME:-bookworm}"; \
|
||
echo "deb [arch=${arch} signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/${VERSION_ID}/prod ${codename} main" \
|
||
> /etc/apt/sources.list.d/microsoft-prod.list; \
|
||
apt-get update; \
|
||
ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
|
||
msodbcsql18 \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
COPY pyproject.toml /app/pyproject.toml
|
||
|
||
RUN pip install --no-cache-dir -U pip && \
|
||
pip install --no-cache-dir .
|
||
|
||
COPY app /app/app
|
||
COPY extensions /app/extensions
|
||
|
||
ENV PYTHONPATH=/app
|
||
|
||
|