最新文章只发在:https://zjp-cn.github.io/posts/ktra-cargo-registry/

使用工具:

  • ktra:纯 Rust 编写的,用于搭建 Cargo registry 的命令行工具

安装它:

cargo install ktra

注意:

  • 这开启了 secure-authdb-sled,数据库是内置的 sled
  • 如果你需要 redis 或者 mongo 作为后端数据库,自行添加 features,见 https://book.ktra.dev/installation/cargo.html
  • 如果你不想通过命令行运行,而是通过 docker 部署,见 https://book.ktra.dev/installation/docker.html

步骤一:创建 Git Index 仓库

由于 Cargo 使用 git 或者 sparse 协议,后者是最近才稳定的(2023 年),而 ktra
出现得比较早,所以目前只基于 git 协议。

在 gitee 上创建新仓库,比如 ktra-cargo-registry,然后在本地新建这个仓库(主分支为 main),创建仓库配置文件,并提交和推送:

mkdir ktra-cargo-registry
cd ktra-cargo-registry
git remote add origin git@gitee.com:xxx/ktra-cargo-registry.git
echo '{"dl":"http://localhost:8000/dl","api":"http://localhost:8000"}' > config.json
git add config.json
git commit -am "initial commit"
git push origin main

注意:

  • 本文描述的是私有 registry 部署(Index 仓库是私有的,发布的 crate 存于自己的私有服务器)
  • 如果你想基于私有 registry 进行更大范围的公开使用,那么可能会对 ktra 的 OpenId 感兴趣(它更复杂)

步骤二:增加本地 Cargo registry

在 Cargo 的配置文件中,比如全局配置文件 ~/.cargo/config

[registries]
ktra = { index = "git@gitee.com:xxx/ktra-cargo-registry.git" }

注意: