From 28ab13e00613ebb59d52094c533fecd90ca1677e Mon Sep 17 00:00:00 2001 From: guolei <2931505649@qq.com> Date: Mon, 26 Jan 2026 15:34:32 +0800 Subject: [PATCH 1/2] feat: Add Docker support for patch-backporting - Added Dockerfile based on python:3.10-slim with necessary dependencies (git, ctags, docker-cli, build-essential, zlib). - Added .dockerignore to optimize build context. - Updated README.md with Docker build and run instructions. --- .dockerignore | 27 +++++++++++++++++++++++++++ Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 16 ++++++++++++++++ README.zh-CN.md | 16 ++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile 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..fad4c66 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,22 @@ 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 +``` + ## Config structure ```yml diff --git a/README.zh-CN.md b/README.zh-CN.md index 2aec50c..8dd419a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -26,6 +26,22 @@ 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 +``` + ## 配置结构 ```yml From fea4adc1070bf6799c1fd7e11a59826eff461e75 Mon Sep 17 00:00:00 2001 From: guolei <2931505649@qq.com> Date: Thu, 29 Jan 2026 17:13:50 +0800 Subject: [PATCH 2/2] docs: Add interactive Docker mode to README as requested --- README.md | 8 ++++++++ README.zh-CN.md | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index fad4c66..65fc294 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,14 @@ Run the container: 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 8dd419a..b95d5dc 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -42,6 +42,14 @@ docker build -t patch-backporting . 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