From d8a40cb3312a923ed1e2d5f7dca12b87ed25c809 Mon Sep 17 00:00:00 2001 From: niuyulin Date: Tue, 30 Jun 2026 15:50:01 +0800 Subject: [PATCH] Adapt to docker env --- .devcontainer/devcontainer.json | 22 +++++++++++++++ .dockerignore | 10 +++++++ .vscode/launch.json | 29 +++++++++++++++++++ Dockerfile | 50 +++++++++++++++++++++++++++++++++ docker-compose.yml | 10 +++++++ 5 files changed, 121 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .dockerignore create mode 100644 .vscode/launch.json create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..1f55693 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +{ + "name": "Multimodal Toolkit", + "dockerComposeFile": [ + "../docker-compose.yml" + ], + "service": "app", + "workspaceFolder": "/app", + "workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind,consistency=cached", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance" + ], + "settings": { + "python.defaultInterpreterPath": "/opt/venv/bin/python", + "python.testing.pytestEnabled": true + } + } + }, + "remoteUser": "root" +} diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fa56d2d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +.idea +__pycache__ +*.pyc +.venv +.env +data/ +*.db +*.sqlite +*.sqlite3 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6985145 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true + }, + { + "name": "Python: mmt-ingest", + "type": "python", + "request": "launch", + "module": "multimodal_toolkit.pipeline.ingest", + "console": "integratedTerminal", + "justMyCode": true + }, + { + "name": "Python: mmt-analyze", + "type": "python", + "request": "launch", + "module": "multimodal_toolkit.pipeline.analyze", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..447ca34 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM python:3.12-slim + +# Switch to Tsinghua mirror for faster APT downloads and to avoid 502 errors +RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources + +# Install necessary system dependencies for audio processing and build tools +RUN apt-get update && apt-get install -y \ + build-essential \ + libsndfile1 \ + ffmpeg \ + curl \ + git \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# Install uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +# Set working directory +WORKDIR /app + +# Enable bytecode compilation +ENV UV_COMPILE_BYTECODE=1 + +# Use Tsinghua mirror to speed up package downloads in China +ENV UV_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple" + +# Create virtual environment outside the workspace so it is not shadowed by host volume mounts +ENV UV_PROJECT_ENVIRONMENT="/opt/venv" + +# Copy dependency files first for caching +COPY pyproject.toml uv.lock ./ +COPY README.md ./ + +# Install dependencies into the virtualenv +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --no-install-project --no-dev + +# Copy the rest of the application code +COPY . . + +# Install the application +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --no-dev + +# Place executables in the environment at the front of the path +ENV PATH="/opt/venv/bin:$PATH" + +# Default command (can be overridden, e.g. for running scripts) +CMD ["/bin/bash"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6090f6b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + app: + build: . + container_name: multimodal-toolkit + environment: + - UV_COMPILE_BYTECODE=1 + volumes: + - .:/app + command: tail -f /dev/null +