Files

53 lines
2.2 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# syntax=docker/dockerfile:1.7
# CAT-BODHI Sprite Segmentation API
# Node.js + Python + PyTorch in one container
#
# Build (CPU, default):
# docker build -t cat-bodhi .
# Build (GPU, requires nvidia-container-toolkit):
# docker build --build-arg TORCH_INDEX=https://download.pytorch.org/whl/cu126 -t cat-bodhi .
FROM python:3.11-slim
ARG NODE_MAJOR=22
ARG TORCH_INDEX=https://download.pytorch.org/whl/cpu
ARG PIP_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
ARG CAT_BODHI_REF=eaf9d27b4ebe3821da983106a78aa1c745532527
ARG CAT_BODHI_ARCHIVE_SHA256=73257f7c9832dd06f958e43cc41d1dccff91788fe49d5384c104d24c75862d4d
# 中科大 Debian 镜像源
RUN sed -i 's|http://deb.debian.org/debian|https://mirrors.ustc.edu.cn/debian|g' /etc/apt/sources.list.d/debian.sources \
&& sed -i 's|http://deb.debian.org/debian-security|https://mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list.d/debian.sources
# 安装 Node.js LTS
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& apt-get update && apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
# 安装 PyTorch(从官方 index+ 其他 Python 包(从清华镜像)
RUN pip install --no-cache-dir \
--index-url ${TORCH_INDEX} \
--extra-index-url ${PIP_MIRROR} \
torch torchvision \
opencv-python-headless \
numpy \
Pillow
WORKDIR /app
RUN curl -fL --retry 5 --retry-all-errors --connect-timeout 20 \
"https://codeload.github.com/ziyuezhou1/CAT-BODHI/tar.gz/${CAT_BODHI_REF}" \
-o /tmp/cat-bodhi.tar.gz \
&& echo "${CAT_BODHI_ARCHIVE_SHA256} /tmp/cat-bodhi.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/cat-bodhi.tar.gz --strip-components=1 -C /app \
&& rm /tmp/cat-bodhi.tar.gz \
&& mkdir -p assets/ai/cats assets/ai/beads
EXPOSE 8080
ENV PORT=8080
CMD ["node", "server.mjs"]