Skip to content

Commit 8a37343

Browse files
author
William Yang
committed
feat: add Docker installation scripts and multi-platform support
- Add install-docker.sh: one-click installation script for Docker version - Add bootcs-wrapper.sh: wrapper script for seamless Docker usage - Update build-cli-image.yml: add linux/arm64 platform support via QEMU - Update README.md: add Docker installation instructions Docker version features: - Credential persistence via ~/.bootcs volume mount - Checks cache persistence for 24h TTL - Interactive login support - Same UX as native installation (via wrapper/alias)
1 parent 1ff1aa4 commit 8a37343

File tree

4 files changed

+336
-61
lines changed

4 files changed

+336
-61
lines changed

.github/workflows/build-cli-image.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
username: ${{ github.actor }}
5151
password: ${{ secrets.GITHUB_TOKEN }}
5252

53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v3
55+
5356
- name: Set up Docker Buildx
5457
uses: docker/setup-buildx-action@v3
5558

@@ -78,6 +81,7 @@ jobs:
7881
with:
7982
context: ./docker
8083
file: ./docker/Dockerfile
84+
platforms: linux/amd64,linux/arm64
8185
push: ${{ github.event_name != 'pull_request' && (inputs.push == true || inputs.push == null) }}
8286
tags: ${{ steps.meta.outputs.tags }}
8387
labels: ${{ steps.meta.outputs.labels }}

README.md

Lines changed: 117 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,55 @@ BootCS 命令行工具 - 用于代码检查和提交
1717

1818
## 安装
1919

20-
### 推荐方式:从 GitHub 安装
20+
### 🐳 推荐方式:Docker 版(无需配置环境)
2121

22-
\`\`\`bash
22+
Docker 版开箱即用,包含 C/Python/Java 完整开发环境,与评测环境完全一致。
23+
24+
**一键安装:**
25+
26+
```bash
27+
curl -fsSL https://raw.githubusercontent.com/bootcs-cn/bootcs-cli/main/scripts/install-docker.sh | bash
28+
```
29+
30+
**手动安装:**
31+
32+
```bash
33+
# 1. 拉取镜像
34+
docker pull ghcr.io/bootcs-cn/bootcs-cli:latest
35+
36+
# 2. 下载 wrapper 脚本
37+
sudo curl -fsSL -o /usr/local/bin/bootcs \
38+
https://raw.githubusercontent.com/bootcs-cn/bootcs-cli/main/scripts/bootcs-wrapper.sh
39+
sudo chmod +x /usr/local/bin/bootcs
40+
```
41+
42+
安装后,使用方式与本地安装完全一致:
43+
44+
```bash
45+
bootcs login # 登录(仅需一次)
46+
bootcs check cs50/hello # 检查代码
47+
bootcs submit cs50/hello # 提交代码
48+
```
49+
50+
> 💡 **提示**: Docker 版会自动持久化凭证到 `~/.bootcs/`,登录一次即可长期使用。
51+
52+
### 本地安装:pip
53+
54+
如果你更喜欢本地安装(需要自行配置 C/Python 环境):
55+
56+
```bash
2357
pip install git+https://github.com/bootcs-cn/bootcs-cli.git
24-
\`\`\`
58+
```
2559

2660
### 开发模式安装
2761

28-
\`\`\`bash
62+
```bash
2963
git clone https://github.com/bootcs-cn/bootcs-cli.git
3064
cd bootcs-cli
3165
python -m venv .venv
3266
source .venv/bin/activate
3367
pip install -e .
34-
\`\`\`
68+
```
3569

3670
## 快速开始
3771

@@ -46,126 +80,148 @@ bootcs login
4680
### 2. 检查代码
4781

4882
\`\`\`bash
83+
4984
# 进入你的代码目录
85+
5086
cd ~/projects/hello
5187

5288
# 检查代码(自动下载 checks,自动检测语言)
89+
5390
bootcs check cs50/hello
5491

5592
# 指定语言
93+
5694
bootcs check cs50/hello -L python
5795

5896
# 强制更新 checks
97+
5998
bootcs check cs50/hello -u
6099

61100
# 输出 JSON 格式
101+
62102
bootcs check cs50/hello --output json
63103
\`\`\`
64104

65105
### 3. 提交代码
66106

67107
\`\`\`bash
108+
68109
# 提交代码到 BootCS 平台
110+
69111
bootcs submit cs50/hello
70112

71113
# 跳过确认
114+
72115
bootcs submit cs50/hello -y
73116

74117
# 自定义提交消息
118+
75119
bootcs submit cs50/hello -m "Fix bug"
76120
\`\`\`
77121

78122
### 4. 管理缓存
79123

80124
\`\`\`bash
125+
81126
# 查看已缓存的 checks
127+
82128
bootcs cache list
83129

84130
# 清空所有缓存
131+
85132
bootcs cache clear
86133

87134
# 清空特定课程的缓存
135+
88136
bootcs cache clear cs50
89137
\`\`\`
90138

91139
### 5. 账户管理
92140

93141
\`\`\`bash
142+
94143
# 查看当前登录用户
144+
95145
bootcs whoami
96146

97147
# 登出
148+
98149
bootcs logout
99150
\`\`\`
100151

101152
## 命令参考
102153

103-
| 命令 | 说明 |
104-
| ---------------------- | ---------------- |
105-
| \`bootcs --version\` | 显示版本号 |
106-
| \`bootcs --help\` | 显示帮助信息 |
107-
| \`bootcs login\` | 使用 GitHub 登录 |
108-
| \`bootcs logout\` | 登出 |
109-
| \`bootcs whoami\` | 显示当前登录用户 |
110-
| \`bootcs check <slug>\` | 检查代码 |
111-
| \`bootcs submit <slug>\` | 提交代码 |
112-
| \`bootcs cache <action>\`| 管理缓存 |
154+
| 命令 | 说明 |
155+
| ------------------------- | ---------------- |
156+
| \`bootcs --version\` | 显示版本号 |
157+
| \`bootcs --help\` | 显示帮助信息 |
158+
| \`bootcs login\` | 使用 GitHub 登录 |
159+
| \`bootcs logout\` | 登出 |
160+
| \`bootcs whoami\` | 显示当前登录用户 |
161+
| \`bootcs check <slug>\` | 检查代码 |
162+
| \`bootcs submit <slug>\` | 提交代码 |
163+
| \`bootcs cache <action>\` | 管理缓存 |
113164

114165
### check 命令选项
115166

116-
| 选项 | 说明 |
117-
| ----------------------- | ----------------------------- |
118-
| \`-L, --language LANG\` | 指定语言 (自动检测如不指定) |
119-
| \`-u, --update\` | 强制更新 checks |
120-
| \`--output [ansi|json]\` | 输出格式 (默认: ansi) |
121-
| \`--log\` | 显示详细日志 |
122-
| \`--target NAME\` | 只运行指定的检查 |
123-
| \`--local PATH\` | 使用本地检查脚本目录 |
167+
| 选项 | 说明 |
168+
| ----------------------- | --------------------------- | --------------------- |
169+
| \`-L, --language LANG\` | 指定语言 (自动检测如不指定) |
170+
| \`-u, --update\` | 强制更新 checks |
171+
| \`--output [ansi | json]\` | 输出格式 (默认: ansi) |
172+
| \`--log\` | 显示详细日志 |
173+
| \`--target NAME\` | 只运行指定的检查 |
174+
| \`--local PATH\` | 使用本地检查脚本目录 |
124175

125176
### submit 命令选项
126177

127-
| 选项 | 说明 |
128-
| ------------------- | ------------------------ |
129-
| \`-L, --language\` | 指定语言 (自动检测) |
130-
| \`-m, --message MSG\` | 自定义提交消息 |
131-
| \`-y, --yes\` | 跳过确认提示 |
132-
| \`--local PATH\` | 使用本地配置目录 |
178+
| 选项 | 说明 |
179+
| --------------------- | ------------------- |
180+
| \`-L, --language\` | 指定语言 (自动检测) |
181+
| \`-m, --message MSG\` | 自定义提交消息 |
182+
| \`-y, --yes\` | 跳过确认提示 |
183+
| \`--local PATH\` | 使用本地配置目录 |
133184

134185
### cache 命令选项
135186

136-
| 选项 | 说明 |
137-
| ----------------- | ------------------------ |
138-
| \`list\` | 列出所有缓存的 checks |
139-
| \`clear [slug]\` | 清空缓存 (可选指定课程) |
140-
| \`-L, --language\` | 指定语言 |
187+
| 选项 | 说明 |
188+
| ------------------ | ----------------------- |
189+
| \`list\` | 列出所有缓存的 checks |
190+
| \`clear [slug]\` | 清空缓存 (可选指定课程) |
191+
| \`-L, --language\` | 指定语言 |
141192

142193
## 语言自动检测
143194

144195
CLI 会根据当前目录的文件自动检测编程语言:
145196

146-
| 文件扩展名 | 检测为 |
147-
|------------|--------|
148-
| \`.c\`, \`.h\` | C |
149-
| \`.py\` | Python |
197+
| 文件扩展名 | 检测为 |
198+
| ----------------- | ---------- |
199+
| \`.c\`, \`.h\` | C |
200+
| \`.py\` | Python |
150201
| \`.js\`, \`.mjs\` | JavaScript |
151-
| \`.go\` | Go |
152-
| \`.rs\` | Rust |
202+
| \`.go\` | Go |
203+
| \`.rs\` | Rust |
153204

154205
如果目录有多种语言的文件,会选择文件数量最多的语言。
155206

156207
## 开发
157208

158209
\`\`\`bash
210+
159211
# 安装开发依赖
212+
160213
pip install -e ".[dev]"
161214

162215
# 运行单元测试
216+
163217
pytest tests/unit/ -v
164218

165219
# 运行所有测试
220+
166221
pytest
167222

168223
# 代码格式化
224+
169225
black bootcs/
170226
ruff check bootcs/
171227
\`\`\`
@@ -175,34 +231,34 @@ ruff check bootcs/
175231
\`\`\`
176232
bootcs-cli/
177233
├── bootcs/
178-
├── __init__.py # 版本信息
179-
├── __main__.py # CLI 入口
180-
├── auth/ # 认证模块
181-
├── credentials.py
182-
└── device_flow.py
183-
├── api/ # API 客户端
184-
├── client.py
185-
├── submit.py
186-
└── checks.py # 远程 checks 管理
187-
├── check/ # 检查模块 (基于 check50)
188-
├── _api.py
189-
├── runner.py
190-
└── c.py
191-
└── lib50/ # 工具库 (基于 lib50)
192-
├── config.py
193-
└── ...
234+
│ ├── **init**.py # 版本信息
235+
│ ├── **main**.py # CLI 入口
236+
│ ├── auth/ # 认证模块
237+
├── credentials.py
238+
└── device_flow.py
239+
│ ├── api/ # API 客户端
240+
├── client.py
241+
├── submit.py
242+
└── checks.py # 远程 checks 管理
243+
│ ├── check/ # 检查模块 (基于 check50)
244+
├── \_api.py
245+
├── runner.py
246+
└── c.py
247+
│ └── lib50/ # 工具库 (基于 lib50)
248+
│ ├── config.py
249+
│ └── ...
194250
├── tests/
195-
└── unit/ # 单元测试
251+
│ └── unit/ # 单元测试
196252
├── pyproject.toml
197253
└── README.md
198254
\`\`\`
199255

200256
## 环境变量
201257

202-
| 变量 | 说明 | 默认值 |
203-
| ------------------ | ---------------- | ----------------------- |
204-
| \`BOOTCS_API_URL\` | API 服务地址 | \`https://api.bootcs.cn\` |
205-
| \`BOOTCS_CHECKS_PATH\` | 本地 checks 路径 (评测环境用) | - |
258+
| 变量 | 说明 | 默认值 |
259+
| ---------------------- | ----------------------------- | ------------------------- |
260+
| \`BOOTCS_API_URL\` | API 服务地址 | \`https://api.bootcs.cn\` |
261+
| \`BOOTCS_CHECKS_PATH\` | 本地 checks 路径 (评测环境用) | - |
206262

207263
## 许可证
208264

scripts/bootcs-wrapper.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# bootcs-cli Docker wrapper
3+
#
4+
# 这个脚本让你可以像使用本地安装的 bootcs 一样使用 Docker 版本
5+
# 凭证和缓存会自动持久化到 ~/.bootcs 目录
6+
#
7+
# 安装方式:
8+
# sudo cp scripts/bootcs-wrapper.sh /usr/local/bin/bootcs
9+
# sudo chmod +x /usr/local/bin/bootcs
10+
#
11+
# 或者添加 alias 到 ~/.zshrc 或 ~/.bashrc:
12+
# alias bootcs='/path/to/bootcs-wrapper.sh'
13+
14+
set -e
15+
16+
# 配置
17+
IMAGE="${BOOTCS_CLI_IMAGE:-ghcr.io/bootcs-cn/bootcs-cli:latest}"
18+
CONFIG_DIR="${HOME}/.bootcs"
19+
20+
# 确保配置目录存在
21+
mkdir -p "${CONFIG_DIR}"
22+
23+
# 检查 Docker 是否可用
24+
if ! command -v docker &> /dev/null; then
25+
echo "Error: Docker is not installed or not in PATH" >&2
26+
exit 1
27+
fi
28+
29+
if ! docker info &> /dev/null 2>&1; then
30+
echo "Error: Docker is not running. Please start Docker." >&2
31+
exit 1
32+
fi
33+
34+
# 检查镜像是否存在,如果不存在则自动拉取
35+
if ! docker image inspect "${IMAGE}" &> /dev/null; then
36+
echo "First run: pulling bootcs-cli image..." >&2
37+
docker pull "${IMAGE}"
38+
fi
39+
40+
# 运行容器
41+
# 参数说明:
42+
# -v $(pwd):/workspace 挂载当前目录为工作目录
43+
# -v ~/.bootcs:/root/.bootcs 持久化凭证和缓存
44+
# --rm 运行后删除容器
45+
# -it 交互模式 (login 需要)
46+
47+
# 根据命令决定是否需要交互模式
48+
case "${1:-}" in
49+
login)
50+
# login 需要交互输入
51+
exec docker run -it --rm \
52+
-v "$(pwd)":/workspace \
53+
-v "${CONFIG_DIR}":/root/.bootcs \
54+
"${IMAGE}" "$@"
55+
;;
56+
*)
57+
# 其他命令不需要交互
58+
exec docker run --rm \
59+
-v "$(pwd)":/workspace \
60+
-v "${CONFIG_DIR}":/root/.bootcs \
61+
"${IMAGE}" "$@"
62+
;;
63+
esac

0 commit comments

Comments
 (0)