Show HN: 我的私有 GitHub 在 Postgres 上
发布: (2026年5月2日 GMT+8 01:40)
4 分钟阅读
原文: Hacker News
Source: Hacker News
概览
GitGres 是面向各团队代理需求的私有化 GitHub 重实现的起点。GitHub 是一个分享代码的绝佳平台,如果你是人类,正在阅读此页面时很可能就是通过它访问的。GitGres 旨在解决以下几个问题:
- 在成本与可用性之间权衡。 GitHub 提供免费代码存储,但可用性并不理想。使用 GitGres,你可以灵活地使用带分层存储的 Postgres DBMS [1] 来调节成本,同时保持高可用性。
- 在延迟与成本之间权衡。 GitHub 受当前系统负载的制约。使用 GitGres,只需选择你喜欢的 Postgres 缓存 [2] 即可。
- 在一致性与吞吐量之间权衡。 GitHub 是云服务。如果请求顺序错乱,可能会出现问题。GitGres 由 Postgres 支持的服务器,可本地运行或与多个代理同机部署。一致性和吞吐量均可完全调节。
所有内容——git 对象、引用、打包文件、增量、令牌、PR、议题、评论、审查、反应、团队、组织、事件——都存放在 Postgres 行中。服务器本身不在磁盘上保存任何数据。
安装
# 1. Build (binaries land in ./target/release/{gitgres,git-remote-gitgres,gitgres-server}).
cargo build --release --bins
# 2. Have a Postgres reachable, e.g.:
export GITGRES_DB='host=localhost user=postgres dbname=gitgres'
# 3. Apply the schema (idempotent).
gitgres init
# 4. Boot the server. The first --bootstrap-token mints an admin token tied
# to user 'demo' that you can use to manage everything else through the API.
gitgres serve --listen 0.0.0.0:8080 --bootstrap-token "$(openssl rand -hex 32)"
# (For TLS:)
gitgres serve --listen 0.0.0.0:8443 \
--tls /path/cert.pem /path/key.pem \
--bootstrap-token TOKEN
gitgres serve 环境变量
| 变量 | 默认值 | 用途 |
|---|---|---|
GITGRES_DB | — | 若未提供 --db,使用的 Postgres 连接字符串 |
GITGRES_PUBLIC_URL | https://gitgres.local | API 在 Repository.cloneUrl 中返回的基础 URL |
GITGRES_WORKERS | 8 | HTTP 工作线程数量 |
GITGRES_GQL_LOG | (未设置) | 若设置,则将每个 GraphQL 请求体记录到 stderr |
使用
纯 git(smart HTTP,v1 + v2)
git clone http://gitgres.host/owner/repo.git
git push http://demo:TOKEN@gitgres.host/owner/repo.git main
gh CLI
# Print a hosts.yml entry, drop into ~/.config/gh/hosts.yml:
gitgres gh-config --host gitgres.host --token TOKEN --user alice
# Or pipe a token into gh:
echo "TOKEN" | gh auth login --hostname gitgres.host --with-token
支持的 gh 命令(示例):
gh pr create / list / view / merge / comment / close / diffgh issue create / list / view / comment / closegh repo create / view / clone / fork / listgh release create / list / viewgh label create / list / edit / deletegh api /repos/owner/repo/...— 完整的 REST 接口
自定义远程助手(smart HTTP 的替代方案)
git clone "gitgres::host=db.local user=u dbname=gitgres#owner/repo"
限制
GitGres 目前 不 支持:
- 搜索
- Actions / 工作流 / 运行 / 密钥
- SSH 传输
- Webhooks
- HTTP/2
- Web UI
