diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1ea958b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# Git +.git +.gitignore + +# Python +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env/ +venv/ +.venv/ +pip-log.txt +pip-delete-this-directory.txt + +# PDM +pdm.lock +.pdm-python + +# IDEs +.idea/ +.vscode/ + +# Project specific +logs/ +.claude/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f5c7668 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# Use an official Python runtime as a parent image +FROM python:3.10-slim + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +# Install system dependencies +# git: for GitPython +# curl: for downloading files +# universal-ctags: for code indexing +# build-essential, cmake, autoconf, automake, libtool, pkg-config: for compiling target projects (like libtiff) +RUN apt-get update && apt-get install -y --no-install-recommends \ + git \ + curl \ + universal-ctags \ + build-essential \ + cmake \ + autoconf \ + automake \ + libtool \ + pkg-config \ + zlib1g-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install Docker CLI manually +RUN curl -fsSL https://download.docker.com/linux/static/stable/$(uname -m)/docker-24.0.5.tgz -o docker.tgz \ + && tar xzvf docker.tgz \ + && mv docker/docker /usr/local/bin/ \ + && rm -rf docker docker.tgz + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements file into the container +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code +COPY . . + +# Change working directory to src as per usage instructions +WORKDIR /app/src + +# Default command to run the application (prints help) +CMD ["python", "backporting.py", "--help"] diff --git a/README.md b/README.md index 52cbe7d..65fc294 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,30 @@ cd src python backporting.py --config example.yml --debug # Remember fill out the config. ``` +## Docker Usage + +Build the docker image: + +```shell +docker build -t patch-backporting . +``` + +Run the container: + +```shell +# Ensure you mount the necessary directories (code, config, datasets) +# Example: assuming config.yml is in current dir and datasets are in /data +docker run --rm -v $(pwd):/app/src -v /path/to/dataset:/path/to/dataset patch-backporting python backporting.py --config config.yml +``` + +Alternatively, you can use the interactive mode to execute scripts inside the container: + +```shell +docker run --rm -it -v $(pwd):/app/src -v /path/to/dataset:/path/to/dataset patch-backporting /bin/bash +# Inside the container +python backporting.py --config config.yml +``` + ## Config structure ```yml diff --git a/README.zh-CN.md b/README.zh-CN.md index 2aec50c..b95d5dc 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -26,6 +26,30 @@ cd src python backporting.py --config example.yml --debug # 记得填写配置文件 ``` +## Docker 使用方法 + +构建 Docker 镜像: + +```shell +docker build -t patch-backporting . +``` + +运行容器: + +```shell +# 请确保挂载了必要的目录(项目代码、配置文件、数据集) +# 示例:假设当前目录下有 config.yml,数据集位于 /path/to/dataset +docker run --rm -v $(pwd):/app/src -v /path/to/dataset:/path/to/dataset patch-backporting python backporting.py --config config.yml +``` + +或者,您可以使用交互模式在容器内执行脚本: + +```shell +docker run --rm -it -v $(pwd):/app/src -v /path/to/dataset:/path/to/dataset patch-backporting /bin/bash +# 在容器内部执行 +python backporting.py --config config.yml +``` + ## 配置结构 ```yml