harbor-rayrun 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ python-version: ["3.12", "3.13"]
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ - name: Install package and test dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ python -m pip install -e '.[test]'
27
+ - name: Run tests
28
+ run: python -m pytest tests -q
29
+
30
+ pypi:
31
+ needs: test
32
+ runs-on: ubuntu-latest
33
+ environment: pypi
34
+ permissions:
35
+ contents: read
36
+ id-token: write
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - uses: actions/setup-python@v5
40
+ with:
41
+ python-version: "3.13"
42
+ - name: Verify tag matches package version
43
+ run: |
44
+ python - <<'PY'
45
+ import os
46
+ import tomllib
47
+
48
+ version = tomllib.load(open("pyproject.toml", "rb"))["project"]["version"]
49
+ tag = os.environ["GITHUB_REF_NAME"]
50
+ assert tag == f"v{version}", f"tag {tag} != v{version}"
51
+ PY
52
+ - name: Build sdist and wheel
53
+ run: |
54
+ python -m pip install --upgrade pip build twine
55
+ python -m build
56
+ python -m twine check dist/*
57
+ - name: Smoke import from the built wheel
58
+ run: |
59
+ python -m pip install dist/*.whl
60
+ python -c "import harbor_rayrun; print(harbor_rayrun.RayrunEnvironment.__name__)"
61
+ - name: Publish to PyPI
62
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,7 @@
1
+ # Python 工程的生成物
2
+ .venv/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ *.egg-info/
6
+ dist/
7
+ build/
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,28 @@
1
+ # harbor-rayrun —— 构建配方(仓库根:make <target>)
2
+ #
3
+ # 本仓库只有 provider 这一个 Python 包,所以它的「构建」= 建 venv + 装依赖,
4
+ # 「测试」= pytest。依赖网络与 PyPI 镜像,显式跑 `make test`。
5
+
6
+ VENV ?= .venv
7
+ PYTHON ?= python3
8
+ # 与仓库其它地方一致:国内直连 PyPI 不稳,走清华镜像(可用 PIP_INDEX 覆盖)。
9
+ PIP_INDEX ?= https://pypi.tuna.tsinghua.edu.cn/simple
10
+
11
+ .PHONY: venv test lint clean
12
+
13
+ venv: $(VENV)/.installed
14
+
15
+ $(VENV)/.installed: pyproject.toml src/harbor_rayrun/*.py
16
+ $(PYTHON) -m venv $(VENV)
17
+ $(VENV)/bin/pip install -q -i $(PIP_INDEX) -e '.[test]'
18
+ @touch $@
19
+
20
+ test: venv ## 单测(httpx.MockTransport 打桩,不打真网络)
21
+ $(VENV)/bin/python -m pytest tests -q
22
+
23
+ lint: venv ## 语法/导入自检(没有引入 ruff:不为一个包加新工具链)
24
+ $(VENV)/bin/python -m compileall -q src tests
25
+ $(VENV)/bin/python -c "import harbor_rayrun; print('import OK:', harbor_rayrun.RayrunEnvironment.__name__)"
26
+
27
+ clean:
28
+ rm -rf $(VENV) .pytest_cache src/*.egg-info src/harbor_rayrun/__pycache__ tests/__pycache__
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.5
2
+ Name: harbor-rayrun
3
+ Version: 0.1.0
4
+ Summary: Harbor provider:把 Rayrun 沙箱云接成 Harbor 的评测环境
5
+ Project-URL: Homepage, https://github.com/RayrunOS/harbor-rayrun
6
+ Project-URL: Repository, https://github.com/RayrunOS/harbor-rayrun
7
+ License: Apache-2.0
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.12
10
+ Requires-Dist: harbor<0.24,>=0.23.0
11
+ Requires-Dist: httpx>=0.27
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
14
+ Requires-Dist: pytest>=8; extra == 'test'
15
+ Description-Content-Type: text/markdown
16
+
17
+ # harbor-rayrun —— Rayrun 的 Harbor provider
18
+
19
+ 把 **Rayrun 沙箱云**接成 [Harbor](https://docs.harborframework.com) 的评测环境:Harbor 每个
20
+ trial 的隔离环境由 provider 实现,本包把它落到 Rayrun 的 HTTP API 上。
21
+
22
+ 本仓库是 **独立仓库**(2026-11-15 从 Rayrun 主仓库的 `integrations/harbor-rayrun/` 拆出)。
23
+ 下文出现的 `docs/...`、`images/...`、`CLAUDE.md` 都指
24
+ [Rayrun 主仓库](https://github.com/RayrunOS/RayrunOS) 内的路径:设计真相源
25
+ `docs/plans/harbor-integration.md`(M3),外部契约取证见 `docs/15` §2.1。
26
+
27
+ ## 它负责什么
28
+
29
+ | Harbor 契约 | 落到 Rayrun |
30
+ |---|---|
31
+ | `start(force_build)` | 校验镜像在宿主机上 → `POST /v1/sandboxes`(201 即 Running) |
32
+ | `stop(delete=True/False)` | `DELETE /sandboxes/{id}` / `POST …/stop`(**ADR-005 冷停**:留盘、停表、IP 不变) |
33
+ | `exec(command, cwd, env, timeout_sec, user)` | `POST /sandboxes/{id}/exec`(**同步**;M1 新落的原语,ADR-007) |
34
+ | `upload_file` / `upload_dir` | `PUT /sandboxes/{id}/files/{path}`(先 `mkdir -p` —— guestd 写文件不建父目录) |
35
+ | `download_file` / `download_dir` | `GET …/files/{path}`;列目录是**单层**的,provider 自己走递归 |
36
+ | `is_dir` / `is_file` | 用基类默认实现(走 `exec` 的 `test -d/-f`),不覆写 |
37
+
38
+ **它不负责什么**:不构建镜像(镜像由平台 builder `POST /v1/builds` 或离线 builder 产出,见下)、
39
+ 不做 SSH/流式(`stream` 档位未开)、不支持 GPU / TPU / Windows / docker-compose。
40
+
41
+ ## 用法
42
+
43
+ ```bash
44
+ # 1. 装(Harbor 与 provider 在同一个 Python 环境里)
45
+ uv pip install harbor-rayrun
46
+ # 或从源码:uv pip install git+ssh://git@github.com/RayrunOS/harbor-rayrun.git
47
+ # 或在本仓库根目录:uv pip install .
48
+
49
+ # 2. 凭证(沿用 CLI 的 env 名,docs/07 §2.5)
50
+ # 托管环境(2026-10-28 起):https://api.rayrunos.com/v1
51
+ # 自托管 / dev: http://<daemon 主机>:8080/v1
52
+ # ⚠️ dashboard.rayrunos.com/v1 已 410,不是 API 入口
53
+ export RAYRUN_API_URL=https://api.rayrunos.com/v1
54
+ export RAYRUN_TOKEN=rayrun_<token_id>_<secret>
55
+
56
+ # 3. 跑(provider 用 --env 的 module:Class 入口,不需要改 Harbor 上游)
57
+ harbor run -t <task> -a oracle -e harbor_rayrun:RayrunEnvironment
58
+ ```
59
+
60
+ 镜像名默认取 `<environment_name>@1`,可用两个环境变量覆盖:
61
+ `RAYRUN_IMAGE_PREFIX`(前缀,例如 `tb-`)与 `RAYRUN_IMAGE_VERSION`。
62
+
63
+ ## 两条必须先知道的前提
64
+
65
+ **1. 镜像要先在目标 Rayrun 环境里备好。** 两条路:
66
+
67
+ - **线上/托管**:用平台 builder 现场构建(`POST /v1/builds`,ADR-024),产物是
68
+ `<name>@<version>`,跑完删除。**不要把本地 `rootfs.ext4` / 镜像目录传到线上**
69
+ (`docs/howto/harbor-on-rayrun.md` §1.2;CLAUDE.md §6)。
70
+ - **本地 dev**:用离线 builder `images/build-task-image.sh` 产出到本机
71
+ `RAYRUN_IMAGES_DIR`,见 `docs/plans/harbor-integration.md` §10。
72
+
73
+ 镜像缺失时 `start()` 会直接报错并附一条**可直接复制**的构建命令,不猜、不静默。
74
+
75
+ **构建时带 `--root-writable`**(旧的「三个 `--writable-dir`」方案已被它取代):
76
+
77
+ ```bash
78
+ images/build-task-image.sh --dockerfile <任务的 Dockerfile> \
79
+ --name <name> --version 1 --out /tmp/task-images --root-writable
80
+ ```
81
+
82
+ 这不是可选优化。沙箱里**清单外的目录一律只读**(ADR-006:可写面是固定 7 个子树
83
+ `/usr /etc /var /opt /root /home /srv` + `/workspace` 盘),而 Harbor 的
84
+ `/logs`(reward 写在这里)`/tests` `/solution` 全在清单外 ⇒ 少了可写面,verifier 连
85
+ `/logs/verifier/reward.txt` 都写不出来,症状只是「reward 文件不存在」。`--root-writable`
86
+ 用 overlay + pivot_root 让 `/` 与 docker 语义一致;任务镜像自己的 `WORKDIR`(典型 `/app`)
87
+ 也由 guestd 按 manifest 的 `[run].workdir` 自动补挂。见 `docs/plans/harbor-integration.md`
88
+ §13.3 / §13.11 与 ADR-006 修订。
89
+
90
+ **2. 网络策略的映射是精确的**(2026-09-27 起):
91
+
92
+ | Harbor `NetworkPolicy` | Rayrun `egress` |
93
+ |---|---|
94
+ | `no-network` | `allow: []`(完全断网) |
95
+ | `allowlist` | `allow: [...]`(域名精确匹配 + IPv4 CIDR) |
96
+ | `public`(**Harbor 的默认**) | `allow_all: true`(显式档位,Rayrun 侧会进审计) |
97
+
98
+ 三者都**精确执行**、不做静默近似。`public` 那一档曾经只能被拒绝(Rayrun 当时没有「允许
99
+ 全部」),为此产品侧补了 `egress.allow_all`(`06` §4.3)—— 于是默认任务也能跑,而「这台
100
+ 沙箱开了全出网」在 Rayrun 的 journal(`sandbox.created.payload.egress.allow_all`)里看得见。
101
+
102
+ ## 依赖
103
+
104
+ - 运行时:`harbor>=0.23,<0.24`(提供 `BaseEnvironment` 抽象面)+ `httpx`(打 Rayrun API)。
105
+ **刻意不引 Rayrun 的生成式 SDK** —— provider 只用 8 个端点,薄客户端足够;SDK 生成是独立
106
+ 立项(`docs/15` §10-Q7),将来若落地,换掉 `client.py` 即可、provider 契约不变。
107
+ - 开发/测试:`pytest` + `pytest-asyncio`(见 `[project.optional-dependencies]`)。
108
+
109
+ ## 测试
110
+
111
+ ```bash
112
+ make test # 首次会建 .venv 并从 PyPI 镜像装依赖(需要网络)
113
+ ```
114
+
115
+ 单测用 `httpx.MockTransport` 打桩,覆盖的都是**会静默出错**的地方:能力虚报、PUBLIC 被悄悄
116
+ 降级、镜像缺失没有可操作提示、超时没有可判定退出码、写文件不建父目录。基线用**真**
117
+ `BaseEnvironment`(不是 stub),所以能力声明的字段名是**对着装好的 harbor 版本**核过的 ——
118
+ `main` 分支与 0.23.0 的 `EnvironmentCapabilities` 字段并不相同(0.23.0 没有 `stream`),
119
+ pydantic 会静默忽略未知字段,写错不会报错。
120
+
121
+ ## 与真机验收的分工
122
+
123
+ 单测钉 provider 的判断;**真沙箱链路**(建沙箱 → exec → 文件 → 销毁)归
124
+ `docs/plans/harbor-integration.md` 的 **M4**(Harbor 端到端 reward 比对)。
@@ -0,0 +1,108 @@
1
+ # harbor-rayrun —— Rayrun 的 Harbor provider
2
+
3
+ 把 **Rayrun 沙箱云**接成 [Harbor](https://docs.harborframework.com) 的评测环境:Harbor 每个
4
+ trial 的隔离环境由 provider 实现,本包把它落到 Rayrun 的 HTTP API 上。
5
+
6
+ 本仓库是 **独立仓库**(2026-11-15 从 Rayrun 主仓库的 `integrations/harbor-rayrun/` 拆出)。
7
+ 下文出现的 `docs/...`、`images/...`、`CLAUDE.md` 都指
8
+ [Rayrun 主仓库](https://github.com/RayrunOS/RayrunOS) 内的路径:设计真相源
9
+ `docs/plans/harbor-integration.md`(M3),外部契约取证见 `docs/15` §2.1。
10
+
11
+ ## 它负责什么
12
+
13
+ | Harbor 契约 | 落到 Rayrun |
14
+ |---|---|
15
+ | `start(force_build)` | 校验镜像在宿主机上 → `POST /v1/sandboxes`(201 即 Running) |
16
+ | `stop(delete=True/False)` | `DELETE /sandboxes/{id}` / `POST …/stop`(**ADR-005 冷停**:留盘、停表、IP 不变) |
17
+ | `exec(command, cwd, env, timeout_sec, user)` | `POST /sandboxes/{id}/exec`(**同步**;M1 新落的原语,ADR-007) |
18
+ | `upload_file` / `upload_dir` | `PUT /sandboxes/{id}/files/{path}`(先 `mkdir -p` —— guestd 写文件不建父目录) |
19
+ | `download_file` / `download_dir` | `GET …/files/{path}`;列目录是**单层**的,provider 自己走递归 |
20
+ | `is_dir` / `is_file` | 用基类默认实现(走 `exec` 的 `test -d/-f`),不覆写 |
21
+
22
+ **它不负责什么**:不构建镜像(镜像由平台 builder `POST /v1/builds` 或离线 builder 产出,见下)、
23
+ 不做 SSH/流式(`stream` 档位未开)、不支持 GPU / TPU / Windows / docker-compose。
24
+
25
+ ## 用法
26
+
27
+ ```bash
28
+ # 1. 装(Harbor 与 provider 在同一个 Python 环境里)
29
+ uv pip install harbor-rayrun
30
+ # 或从源码:uv pip install git+ssh://git@github.com/RayrunOS/harbor-rayrun.git
31
+ # 或在本仓库根目录:uv pip install .
32
+
33
+ # 2. 凭证(沿用 CLI 的 env 名,docs/07 §2.5)
34
+ # 托管环境(2026-10-28 起):https://api.rayrunos.com/v1
35
+ # 自托管 / dev: http://<daemon 主机>:8080/v1
36
+ # ⚠️ dashboard.rayrunos.com/v1 已 410,不是 API 入口
37
+ export RAYRUN_API_URL=https://api.rayrunos.com/v1
38
+ export RAYRUN_TOKEN=rayrun_<token_id>_<secret>
39
+
40
+ # 3. 跑(provider 用 --env 的 module:Class 入口,不需要改 Harbor 上游)
41
+ harbor run -t <task> -a oracle -e harbor_rayrun:RayrunEnvironment
42
+ ```
43
+
44
+ 镜像名默认取 `<environment_name>@1`,可用两个环境变量覆盖:
45
+ `RAYRUN_IMAGE_PREFIX`(前缀,例如 `tb-`)与 `RAYRUN_IMAGE_VERSION`。
46
+
47
+ ## 两条必须先知道的前提
48
+
49
+ **1. 镜像要先在目标 Rayrun 环境里备好。** 两条路:
50
+
51
+ - **线上/托管**:用平台 builder 现场构建(`POST /v1/builds`,ADR-024),产物是
52
+ `<name>@<version>`,跑完删除。**不要把本地 `rootfs.ext4` / 镜像目录传到线上**
53
+ (`docs/howto/harbor-on-rayrun.md` §1.2;CLAUDE.md §6)。
54
+ - **本地 dev**:用离线 builder `images/build-task-image.sh` 产出到本机
55
+ `RAYRUN_IMAGES_DIR`,见 `docs/plans/harbor-integration.md` §10。
56
+
57
+ 镜像缺失时 `start()` 会直接报错并附一条**可直接复制**的构建命令,不猜、不静默。
58
+
59
+ **构建时带 `--root-writable`**(旧的「三个 `--writable-dir`」方案已被它取代):
60
+
61
+ ```bash
62
+ images/build-task-image.sh --dockerfile <任务的 Dockerfile> \
63
+ --name <name> --version 1 --out /tmp/task-images --root-writable
64
+ ```
65
+
66
+ 这不是可选优化。沙箱里**清单外的目录一律只读**(ADR-006:可写面是固定 7 个子树
67
+ `/usr /etc /var /opt /root /home /srv` + `/workspace` 盘),而 Harbor 的
68
+ `/logs`(reward 写在这里)`/tests` `/solution` 全在清单外 ⇒ 少了可写面,verifier 连
69
+ `/logs/verifier/reward.txt` 都写不出来,症状只是「reward 文件不存在」。`--root-writable`
70
+ 用 overlay + pivot_root 让 `/` 与 docker 语义一致;任务镜像自己的 `WORKDIR`(典型 `/app`)
71
+ 也由 guestd 按 manifest 的 `[run].workdir` 自动补挂。见 `docs/plans/harbor-integration.md`
72
+ §13.3 / §13.11 与 ADR-006 修订。
73
+
74
+ **2. 网络策略的映射是精确的**(2026-09-27 起):
75
+
76
+ | Harbor `NetworkPolicy` | Rayrun `egress` |
77
+ |---|---|
78
+ | `no-network` | `allow: []`(完全断网) |
79
+ | `allowlist` | `allow: [...]`(域名精确匹配 + IPv4 CIDR) |
80
+ | `public`(**Harbor 的默认**) | `allow_all: true`(显式档位,Rayrun 侧会进审计) |
81
+
82
+ 三者都**精确执行**、不做静默近似。`public` 那一档曾经只能被拒绝(Rayrun 当时没有「允许
83
+ 全部」),为此产品侧补了 `egress.allow_all`(`06` §4.3)—— 于是默认任务也能跑,而「这台
84
+ 沙箱开了全出网」在 Rayrun 的 journal(`sandbox.created.payload.egress.allow_all`)里看得见。
85
+
86
+ ## 依赖
87
+
88
+ - 运行时:`harbor>=0.23,<0.24`(提供 `BaseEnvironment` 抽象面)+ `httpx`(打 Rayrun API)。
89
+ **刻意不引 Rayrun 的生成式 SDK** —— provider 只用 8 个端点,薄客户端足够;SDK 生成是独立
90
+ 立项(`docs/15` §10-Q7),将来若落地,换掉 `client.py` 即可、provider 契约不变。
91
+ - 开发/测试:`pytest` + `pytest-asyncio`(见 `[project.optional-dependencies]`)。
92
+
93
+ ## 测试
94
+
95
+ ```bash
96
+ make test # 首次会建 .venv 并从 PyPI 镜像装依赖(需要网络)
97
+ ```
98
+
99
+ 单测用 `httpx.MockTransport` 打桩,覆盖的都是**会静默出错**的地方:能力虚报、PUBLIC 被悄悄
100
+ 降级、镜像缺失没有可操作提示、超时没有可判定退出码、写文件不建父目录。基线用**真**
101
+ `BaseEnvironment`(不是 stub),所以能力声明的字段名是**对着装好的 harbor 版本**核过的 ——
102
+ `main` 分支与 0.23.0 的 `EnvironmentCapabilities` 字段并不相同(0.23.0 没有 `stream`),
103
+ pydantic 会静默忽略未知字段,写错不会报错。
104
+
105
+ ## 与真机验收的分工
106
+
107
+ 单测钉 provider 的判断;**真沙箱链路**(建沙箱 → exec → 文件 → 销毁)归
108
+ `docs/plans/harbor-integration.md` 的 **M4**(Harbor 端到端 reward 比对)。
@@ -0,0 +1,33 @@
1
+ [project]
2
+ name = "harbor-rayrun"
3
+ version = "0.1.0"
4
+ description = "Harbor provider:把 Rayrun 沙箱云接成 Harbor 的评测环境"
5
+ readme = "README.md"
6
+ license = { text = "Apache-2.0" }
7
+ requires-python = ">=3.12"
8
+ # 依赖只有两个:Harbor 本体(提供 BaseEnvironment 抽象面)与 httpx(打 Rayrun 的
9
+ # HTTP API)。**刻意不引 Rayrun 的生成式 SDK** —— provider 只用 8 个端点,薄客户端
10
+ # 足够,且 SDK 生成是独立立项(15 §10-Q7)。将来若 SDK 落地,换掉 client.py 即可,
11
+ # provider 的契约不变。
12
+ dependencies = [
13
+ "harbor>=0.23.0,<0.24",
14
+ "httpx>=0.27",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ test = ["pytest>=8", "pytest-asyncio>=0.24"]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/RayrunOS/harbor-rayrun"
22
+ Repository = "https://github.com/RayrunOS/harbor-rayrun"
23
+
24
+ [build-system]
25
+ requires = ["hatchling"]
26
+ build-backend = "hatchling.build"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/harbor_rayrun"]
30
+
31
+ [tool.pytest.ini_options]
32
+ asyncio_mode = "auto"
33
+ testpaths = ["tests"]
@@ -0,0 +1,17 @@
1
+ """harbor-rayrun —— 把 Rayrun 沙箱云接成 Harbor 的评测环境。
2
+
3
+ Harbor 的 `BaseEnvironment.type()` 显式允许返回任意字符串(它的注释写明是为了让
4
+ 仓库之外的第三方环境不必改 `EnvironmentType` 枚举),所以本 provider **不需要**
5
+ Harbor 上游改动即可用 `--env` 入口加载:
6
+
7
+ uv pip install ./integrations/harbor-rayrun
8
+ export RAYRUN_API_URL=https://api.rayrunos.com/v1 # 自托管:http://<daemon>:8080/v1
9
+ export RAYRUN_TOKEN=rayrun_<token_id>_<secret>
10
+ harbor run -t <task> -a oracle -e harbor_rayrun:RayrunEnvironment
11
+
12
+ 环境变量沿用 CLI 的同名约定(`07` §2.5),不新造一套 key 体系。
13
+ """
14
+
15
+ from harbor_rayrun.environment import RayrunEnvironment
16
+
17
+ __all__ = ["RayrunEnvironment"]