70 lines
3.2 KiB
Docker
70 lines
3.2 KiB
Docker
ARG NODE_IMAGE=docker.m.daocloud.io/library/node:22-bookworm-slim
|
|
ARG PYTHON_IMAGE=docker.m.daocloud.io/library/python:3.12-slim-bookworm
|
|
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
|
ARG NPM_REGISTRY=https://registry.npmmirror.com
|
|
|
|
FROM ${NODE_IMAGE} AS frontend-build
|
|
ARG NPM_REGISTRY
|
|
WORKDIR /src/frontend
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
RUN npm ci --registry="$NPM_REGISTRY"
|
|
COPY frontend/ ./
|
|
RUN npm run build
|
|
|
|
FROM ${PYTHON_IMAGE} AS wheel-build
|
|
ARG PIP_INDEX_URL
|
|
WORKDIR /src
|
|
COPY pyproject.toml README.md ./
|
|
COPY backend/ ./backend/
|
|
RUN python -m pip install --no-cache-dir --index-url "$PIP_INDEX_URL" 'hatchling>=1.25,<2' \
|
|
&& python -m hatchling build -t wheel -d /wheels
|
|
|
|
FROM ${PYTHON_IMAGE}
|
|
ARG PIP_INDEX_URL
|
|
ARG DEBIAN_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/debian
|
|
ARG DEBIAN_SECURITY_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/debian-security
|
|
ARG PGVECTOR_VERSION=0.8.6
|
|
ARG PGVECTOR_PACKAGE_VERSION_URL=0.8.6-1.pgdg12%2B1
|
|
ARG PGVECTOR_SHA256=b27ff894d1e2d23ebd7528fcb986923391977cbd5c5379ed74527875246854ca
|
|
RUN sed -i \
|
|
-e "s|http://deb.debian.org/debian-security|$DEBIAN_SECURITY_MIRROR|g" \
|
|
-e "s|http://deb.debian.org/debian|$DEBIAN_MIRROR|g" \
|
|
/etc/apt/sources.list /etc/apt/sources.list.d/*.sources 2>/dev/null || true \
|
|
&& apt-get update \
|
|
&& apt-get install -y --no-install-recommends ca-certificates curl ffmpeg postgresql-15 postgresql-client-15 rclone tini \
|
|
&& verified=0 \
|
|
&& for attempt in 1 2 3 4; do \
|
|
rm -f /tmp/pgvector.deb; \
|
|
curl --fail --location --connect-timeout 20 --max-time 120 \
|
|
"https://apt.postgresql.org/pub/repos/apt/pool/main/p/pgvector/postgresql-15-pgvector_${PGVECTOR_PACKAGE_VERSION_URL}_amd64.deb" \
|
|
--output /tmp/pgvector.deb \
|
|
&& printf '%s %s\n' "$PGVECTOR_SHA256" /tmp/pgvector.deb | sha256sum --check --status \
|
|
&& verified=1 && break; \
|
|
sleep "$attempt"; \
|
|
done \
|
|
&& test "$verified" = 1 \
|
|
&& dpkg -i /tmp/pgvector.deb \
|
|
&& rm -f /tmp/pgvector.deb \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
COPY requirements/runtime-core.txt /opt/imagefind/runtime-core.txt
|
|
COPY --from=wheel-build /wheels/imagefind-*.whl /opt/imagefind/
|
|
RUN python -m pip install --no-cache-dir --index-url "$PIP_INDEX_URL" \
|
|
-r /opt/imagefind/runtime-core.txt /opt/imagefind/imagefind-*.whl \
|
|
&& useradd --system --home-dir /nonexistent --shell /usr/sbin/nologin imagefind
|
|
COPY --from=frontend-build /src/frontend/dist/ /opt/imagefind/frontend/
|
|
COPY scripts/docker-entrypoint.sh /usr/local/bin/imagefind-entrypoint
|
|
RUN chmod 0755 /usr/local/bin/imagefind-entrypoint && mkdir -p /data
|
|
ENV IMAGEFIND_DATA_DIR=/data/imagefind \
|
|
IMAGEFIND_FRONTEND_DIR=/opt/imagefind/frontend \
|
|
IMAGEFIND_HOST=0.0.0.0 \
|
|
IMAGEFIND_PORT=8765 \
|
|
IMAGEFIND_DIRECT_ACCESS=true \
|
|
IMAGEFIND_POSTGRES_CONF=/data/postgres-client.conf \
|
|
TZ=Asia/Shanghai
|
|
VOLUME ["/data"]
|
|
EXPOSE 8765
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=4 \
|
|
CMD pg_isready -h 127.0.0.1 -p 5432 -d imagefind -q \
|
|
&& curl -fsS http://127.0.0.1:8765/ >/dev/null || exit 1
|
|
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/imagefind-entrypoint"]
|