Speed up backend image build and fix Debian 12 ODBC setup.
Use libreoffice-nogui on bookworm, gpg keyring for msodbcsql18, and BuildKit apt/pip caches.
Co-authored-by: Cursor <cursoragent@cursor.com>
(cherry picked from commit 844eb30747)
This commit is contained in:
1 parent
8c877e871a
commit
fed26821b7
3 files changed
+21
-12
No files matched your search
+16
-10
@@ -1,4 +1,5 @@
|
|||||||
ARG PYTHON_BASE_IMAGE=python:3.12-slim
|
# syntax=docker/dockerfile:1.4
|
||||||
|
ARG PYTHON_BASE_IMAGE=python:3.12-slim-bookworm
|
||||||
FROM ${PYTHON_BASE_IMAGE}
|
FROM ${PYTHON_BASE_IMAGE}
|
||||||
|
|
||||||
ARG APT_MIRROR=https://mirrors.aliyun.com
|
ARG APT_MIRROR=https://mirrors.aliyun.com
|
||||||
@@ -7,7 +8,9 @@ ARG PIP_EXTRA_INDEX_URL
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN set -eux; \
|
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
|
set -eux; \
|
||||||
if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
|
if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
|
||||||
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}/debian|g" /etc/apt/sources.list.d/debian.sources; \
|
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}/debian|g" /etc/apt/sources.list.d/debian.sources; \
|
||||||
sed -i "s|http://deb.debian.org/debian-security|${APT_MIRROR}/debian-security|g" /etc/apt/sources.list.d/debian.sources; \
|
sed -i "s|http://deb.debian.org/debian-security|${APT_MIRROR}/debian-security|g" /etc/apt/sources.list.d/debian.sources; \
|
||||||
@@ -16,26 +19,30 @@ RUN set -eux; \
|
|||||||
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}/debian|g" /etc/apt/sources.list; \
|
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}/debian|g" /etc/apt/sources.list; \
|
||||||
sed -i "s|http://deb.debian.org/debian-security|${APT_MIRROR}/debian-security|g" /etc/apt/sources.list; \
|
sed -i "s|http://deb.debian.org/debian-security|${APT_MIRROR}/debian-security|g" /etc/apt/sources.list; \
|
||||||
fi; \
|
fi; \
|
||||||
apt-get update && apt-get install -y \
|
apt-get update && apt-get install -y --no-install-recommends \
|
||||||
libgl1 \
|
libgl1 \
|
||||||
libglib2.0-0 \
|
libglib2.0-0 \
|
||||||
libxcb1 \
|
libxcb1 \
|
||||||
libx11-6 \
|
libx11-6 \
|
||||||
libxext6 \
|
libxext6 \
|
||||||
libreoffice \
|
libreoffice-nogui \
|
||||||
fonts-noto-cjk \
|
fonts-noto-cjk \
|
||||||
curl \
|
curl \
|
||||||
gnupg2 \
|
ca-certificates \
|
||||||
|
gnupg \
|
||||||
unixodbc-dev \
|
unixodbc-dev \
|
||||||
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
|
&& install -d -m 0755 /etc/apt/keyrings \
|
||||||
&& curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \
|
&& curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /etc/apt/keyrings/microsoft-prod.gpg \
|
||||||
|
&& chmod a+r /etc/apt/keyrings/microsoft-prod.gpg \
|
||||||
|
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
|
&& ACCEPT_EULA=Y apt-get install -y --no-install-recommends msodbcsql18 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install Python dependencies
|
# Install Python dependencies
|
||||||
COPY backend/requirements.txt .
|
COPY backend/requirements.txt .
|
||||||
RUN set -eux; \
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
set -eux; \
|
||||||
PIP_ARGS="--no-cache-dir --retries 10 --timeout 60"; \
|
PIP_ARGS="--no-cache-dir --retries 10 --timeout 60"; \
|
||||||
if [ -n "${PIP_INDEX_URL:-}" ]; then \
|
if [ -n "${PIP_INDEX_URL:-}" ]; then \
|
||||||
PIP_ARGS="$PIP_ARGS --index-url ${PIP_INDEX_URL}"; \
|
PIP_ARGS="$PIP_ARGS --index-url ${PIP_INDEX_URL}"; \
|
||||||
@@ -62,4 +69,3 @@ EXPOSE 5000
|
|||||||
# Start Gunicorn
|
# Start Gunicorn
|
||||||
# Using the config file we created earlier
|
# Using the config file we created earlier
|
||||||
CMD ["gunicorn", "-c", "deploy/gunicorn_config.py", "run:app"]
|
CMD ["gunicorn", "-c", "deploy/gunicorn_config.py", "run:app"]
|
||||||
|
|
||||||
+2
-2
@@ -23,7 +23,7 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: backend/Dockerfile
|
dockerfile: backend/Dockerfile
|
||||||
args:
|
args:
|
||||||
PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim}
|
PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm}
|
||||||
PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple}
|
PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple}
|
||||||
PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-}
|
PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-}
|
||||||
container_name: hxops-backend
|
container_name: hxops-backend
|
||||||
@@ -65,7 +65,7 @@ services:
|
|||||||
context: ./backend
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
args:
|
args:
|
||||||
PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim}
|
PYTHON_BASE_IMAGE: ${PYTHON_BASE_IMAGE:-python:3.12-slim-bookworm}
|
||||||
PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple}
|
PIP_INDEX_URL: ${PIP_INDEX_URL:-https://mirrors.aliyun.com/pypi/simple}
|
||||||
PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-}
|
PIP_EXTRA_INDEX_URL: ${PIP_EXTRA_INDEX_URL:-}
|
||||||
container_name: hxops-kb-worker
|
container_name: hxops-kb-worker
|
||||||
|
|||||||
@@ -174,6 +174,9 @@ fi
|
|||||||
if [[ "${PREBUILT_MODE}" == "true" ]]; then
|
if [[ "${PREBUILT_MODE}" == "true" ]]; then
|
||||||
"${DC_CMD[@]}" "${compose_args[@]}" up -d --no-build "${services[@]}"
|
"${DC_CMD[@]}" "${compose_args[@]}" up -d --no-build "${services[@]}"
|
||||||
else
|
else
|
||||||
|
# Dockerfile 使用 apt/pip cache mount,需启用 BuildKit
|
||||||
|
export DOCKER_BUILDKIT=1
|
||||||
|
export COMPOSE_DOCKER_CLI_BUILD=1
|
||||||
"${DC_CMD[@]}" "${compose_args[@]}" up -d --build "${services[@]}"
|
"${DC_CMD[@]}" "${compose_args[@]}" up -d --build "${services[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user