Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ deploy-sidecar.sh 写容器内路径)就不会有这个问题;把两者合
五个 shell 脚本已全部改成 CLI 子命令,并随包发布到 npm(`git-credential-broker`):`setup`
(原 container-setup.sh)、`init`(原 host-setup.sh)、`compose`(原 deploy-sidecar.sh 的
compose 生成)、`probe`、`diagnose`。宿主不再需要 checkout 或构建 —— `compose` 产出的 sidecar
直接 `npx` 拉取已发布的包。同一个 bin 既是 git 的 credential helper(`get|store|erase`),
使用已发布 host 镜像里的 `gcb`。同一个 bin 既是 git 的 credential helper(`get|store|erase`),
也是管理 CLI。

**新增 `stage`:把"代码在哪"变成一条命令。** 原 `deploy-sidecar.sh` 会拒绝脏工作树,合并成 CLI 时我把
Expand Down
7 changes: 7 additions & 0 deletions .changeset/compose-host-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"gcb-host": patch
---

`compose` now emits the released `ghcr.io/code-vaults/gcb-host:<version>` image and runs its installed
`gcb daemon` binary. It no longer generates an `npx --package gcb-host` command or accepts `--package`.
The `--code` staged-code mode is unchanged.
6 changes: 6 additions & 0 deletions .renovaterc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>1stG/configs"
]
}
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ sources must stay erasable (`erasableSyntaxOnly` is on: no enums, no parameter p
- **Only cover the deployment shapes this project actually supports.** The supported shapes are
the installed `gcb-client` in the container, the installed `gcb-host` (or a staged commit with
its production dependencies) on the host, the rendered sidecar, and a source checkout with a
`gcb` shim for development. Do not add guards, probes, commands or tests for one-off `npx`
`gcb` shim for development. Do not add guards, probes, commands or tests for one-off execution
setup, direct imports of command modules, arbitrary later PATH changes, or native Windows beyond
the existing refusal and its real-platform CI job.
`setup` cannot know the PATH of a later git process; do not pretend a setup-time check is a
Expand Down
6 changes: 0 additions & 6 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ gcb compose --dir "$DEPLOY" --socket-dir "$SOCKET_DIR" \
> "$DEPLOY/docker-compose.yml"
```

Change only the `exec npx --yes --package … gcb` prefix to `exec gcb`, keeping `daemon --config …`:

```sh
exec gcb daemon --config /etc/git-cred-broker/config/broker.config.yml
```

The dev image already installs the package; do **not** keep a staged `/opt/gcb` mount, or the
image's code is ignored.
Then recreate from the deployment directory, choosing the proxy at runtime:
Expand Down
51 changes: 38 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ npm install -g gcb-host

`gcb-client` has no runtime dependencies. `gcb-host` depends on `yaml`; npm installs it there. Do not
install both globally on the same machine: they race for the same `gcb` bin. Run `setup` from the
installed client; one-off `npx` execution is not a supported installation shape.
installed client; one-off execution is not a supported installation shape.

Or run from a checkout. Node 24 strips TypeScript types, but the workspaces still need their
dependencies:
Expand All @@ -108,10 +108,8 @@ the compose command in [Quick start](#quick-start-sidecar):
docker build --target host -t code-vaults/gcb-host:dev .
```

The image's `CMD` starts `gcb daemon`, but `compose` still renders the registry-fetching `npx`
command by default. Keep the rendered `sh -c` wrapper (it applies `GCB_PROXY`) and change only its
final `exec npx ...` to `exec gcb daemon --config ...`; see
[DEVELOPMENT.md](DEVELOPMENT.md#use-your-build).
The image's `CMD` starts `gcb daemon`; the rendered command runs that installed binary and keeps the
`sh -c` wrapper that applies `GCB_PROXY`. See [DEVELOPMENT.md](DEVELOPMENT.md#use-your-build).

Debian packages use the Aliyun mirror by default in this image; pass
`--build-arg APT_MIRROR=<host>` to build against another mirror.
Expand Down Expand Up @@ -177,9 +175,8 @@ The exact command, flags and required values come from

## Quick start: sidecar

Docker only. Run `init` and `compose` from an installed `gcb-host`. The image is stock `node:24-slim`;
the default sidecar fetches `gcb-host` with `npx` at start, while `--code` runs a staged commit with no
registry access at boot.
Docker only. Run `init` and `compose` from an installed `gcb-host`. The default sidecar uses the
released `gcb-host` image and runs its installed `gcb daemon`; `--code` runs a staged commit instead.

```sh
DEPLOY=/srv/git-cred-broker # the deployment directory
Expand Down Expand Up @@ -229,8 +226,7 @@ guess. The runtime route is deliberately a superset: a directory bind-mounted in
counts as shared, because any container that can rewrite the broker's code is as good a reason not to
stage there as the agent is.

The sidecar fetches the published `gcb-host` package with `npx` at start. To pin a reviewed commit
instead, run `gcb stage --to "$DEPLOY/app"`, install its dependencies in that directory with
The sidecar runs the installed `gcb` from the released host image. To pin a reviewed commit instead, run `gcb stage --to "$DEPLOY/app"`, install its dependencies in that directory with
`corepack yarn install`, and pass `--code "$DEPLOY/app"` to `compose`. Run `stage` from the repository
root you intend to export, or pass `--repo <path>`: it defaults to the current directory and exports
that repository's `HEAD`, never the working tree. `stage` is export-only: it does not install
Expand Down Expand Up @@ -268,7 +264,7 @@ gcb setup
install and a dev shim) and `credential.useHttpPath` (without the latter, git sends no repository
path and the broker can only authorize host-wide). The helper is resolved by the git process later,
not by `setup`: that process must have `gcb` on its PATH. Run setup from the installed client, not
a one-off `npx` process.
a one-off execution.

It also rewrites `git@github.com:` remotes to
https **inside the container only** so the host's SSH workflow is untouched, and writes a CA bundle
Expand Down Expand Up @@ -348,8 +344,7 @@ a sidecar it is inside the container:

```sh
DEPLOY=/srv/git-cred-broker
cd "$DEPLOY" && docker compose exec gcb \
npx --yes --package gcb-host gcb \
cd "$DEPLOY" && docker compose exec gcb gcb \
diagnose --config /etc/git-cred-broker/config/broker.config.yml
```

Expand Down Expand Up @@ -810,6 +805,36 @@ its own `corepack` and `npm`, and a whole-directory copy would replace them. Tha
local build; CI and production pass a published version instead, e.g.
`--build-arg GCB_CLIENT_IMAGE=ghcr.io/code-vaults/gcb-client:<version>`.

### Updating the sidecar

Pin a released `gcb-host` image by version or digest; do not use `:dev` or `pull_policy: never` for
updates. The generated service is named `gcb` by default (`gcb compose --name <name>` changes it).

The released image contains the `gcb` binary and starts `gcb daemon`. Keep the generated `sh -c`
wrapper: it applies `GCB_PROXY`, and its final `exec` already runs the installed binary. Do not replace
the whole `command` with a bare `gcb daemon` list.

```sh
docker compose pull gcb
docker compose up -d --no-deps --force-recreate gcb
```

Verify the running sidecar, not just the host CLI:

```sh
docker compose exec gcb gcb --version
docker compose exec gcb gcb doctor --config /etc/git-cred-broker/config/broker.config.yml
gcb --version # in the pushing environment; must be the same release line
```

`gcb doctor` checks configuration and the audit path; it is not a daemon-liveness probe. Check
liveness from the pushing environment with `gcb probe --repo <owner/name>`: exit `0` means allowed,
`1` denied, and `3` means the broker is unreachable. Alert on a non-zero doctor result; restart only
when `probe` returns `3` or the socket is gone; a configuration error needs an operator.

Use the same release line on both sides. Typed host replies and the active-audit ping need at least
`0.3.0`; `gcb authorize --broker-container` needs host `0.8.0`.

## App permissions by action

The action catalog is the source for these requirements; `gcb gh --help` prints the same
Expand Down
13 changes: 4 additions & 9 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,23 @@

services:
git-cred-broker:
# The usual NAS case. The image installs the package at start, so there is no checkout to copy
# The usual NAS case. The released image contains gcb-host, so there is no checkout to copy
# and nothing to build. Only this container mounts the private key; the socket directory is
# the only thing shared with the DSH container.
image: node:24-slim
image: ghcr.io/code-vaults/gcb-host:0.8.0
container_name: git-cred-broker
restart: unless-stopped
# Must match the uid/gid of the container that will use the socket, or it is unusable.
# `compose --user "<pusher uid>:<pusher gid>"` renders this from the deployment.
user: '1000:1000'
read_only: true
tmpfs:
# npx needs somewhere writable for its cache; /tmp is a tmpfs above.
- /tmp
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
environment:
# npx needs somewhere writable for its cache; /tmp is a tmpfs above.
- npm_config_cache=/tmp/npm-cache
# Egress: the socket needs no proxy, the broker's own calls to github.com do.
- http_proxy=${http_proxy:-${HTTP_PROXY:-}}
- https_proxy=${https_proxy:-${HTTPS_PROXY:-}}
Expand All @@ -41,7 +38,7 @@ services:
command:
- sh
- -c
- exec npx --yes --package 'gcb-host' gcb daemon --config /etc/git-cred-broker/config/broker.config.yml
- exec gcb daemon --config /etc/git-cred-broker/config/broker.config.yml
volumes:
# The configuration directory, not one file: an atomic replacement on the host must stay
# visible to the container's watcher. Put broker.config.yml in ./config; the key and refresh
Expand Down Expand Up @@ -72,9 +69,7 @@ services:
# The same host directory the broker binds, or the two are not sharing a socket at all.
- /srv/git-broker-socket:/run/git-broker

# Pin a released version (`npx --yes --package 'gcb-host@<version>'`) if you would rather not
# resolve latest on every start; `compose` pins the version it was generated from. The first
# functional release is 0.0.1; 0.0.0 is an empty placeholder.
# Pin the released image tag or digest; `compose` pins the version it was generated from.
#
# The host-process alternative, for a host that has Node and a service manager:
#
Expand Down
44 changes: 16 additions & 28 deletions packages/host/src/commands/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* The broker runs in its own container with the private key mounted read-only, no published ports,
* no capabilities and a read-only root filesystem; the only surface it shares with anything else is
* the socket directory. The container fetches the published package, so there is no checkout to
* copy and nothing to build on the host.
* the socket directory. The released image contains the package, so there is no checkout to copy and
* nothing to build on the host.
*
* The mount targets are constants from `deployment.ts`, shared with `init --mode sidecar`, so the
* paths recorded in `broker.config.yml` and the paths this file mounts cannot drift apart.
Expand Down Expand Up @@ -33,16 +33,14 @@ export interface ComposeInput {
readonly socketDir: string
/** `uid:gid` the sidecar runs as; must match the container that needs the socket. */
readonly user: string
/** Base image. */
/** Base image; the released host image contains the `gcb` binary. */
readonly image: string
/** Npm spec to run, e.g. `gcb@0.0.0`. */
readonly packageSpec: string
/** Compose service and container name. */
readonly name: string
/**
* Host directory holding the broker's code, as `stage` exports it. When given, the sidecar runs
* that code with the image's Node instead of fetching the package at start: no registry access at
* boot, and the commit that runs is the one you reviewed.
* that code with the image's Node instead of running the image's installed binary: no registry
* access at boot, and the commit that runs is the one you reviewed.
*/
readonly code?: string
}
Expand Down Expand Up @@ -96,14 +94,8 @@ export function renderCompose(input: ComposeInput): string {
? `# It runs the code mounted read-only from ${input.code}, which is whatever \`stage\` put there —
# see the STAGED.json beside it for the commit. stage does not install dependencies or build:
# run \`corepack yarn install\` in that directory first, then the source entry point runs here.`
: `# The image fetches the published package at start:
#
# npx --yes --package '${input.packageSpec}' gcb daemon
#
# To avoid depending on the registry at boot, either render this file with --code <directory> to
# run staged code from a mount, or point --image at an image of your own that already has the
# package installed, and change \`command\` to the binary in it:
# ["gcb", "daemon", "--config", "${mountedConfigPath}"]`
: `# The image contains gcb-host and the command below runs its installed \`gcb\` binary.
# To pin a reviewed commit instead, render this file with --code <directory>.`

// The egress lines belong to both renders: a --code deployment is a sidecar too, and without them it
// would carry no proxy variables at all, so the daemon would go direct and hang rather than refuse.
Expand All @@ -117,13 +109,8 @@ export function renderCompose(input: ComposeInput): string {
# Runtime override: a URL pins a proxy, an empty value goes direct, unset keeps the above.
- GCB_PROXY=\${GCB_PROXY-default}`

const environment = fromCode
? `
const environment = `
environment:${egress}`
: `
environment:
# npx needs somewhere writable for its cache; /tmp is a tmpfs above.
- npm_config_cache=/tmp/npm-cache${egress}`

// A bind mount for a path that does not exist becomes a directory, and the broker would then read a
// directory instead of a token — for every action, not only the personal ones. Emit it once `authorize`
Expand All @@ -134,7 +121,7 @@ export function renderCompose(input: ComposeInput): string {
'\n # for a path that does not exist would become a directory, and the broker would read that.'
const start = fromCode
? `exec node --conditions=development ${CODE_DIR}/packages/host/bin/gcb.js daemon --config ${mountedConfigArg}`
: `exec npx --yes --package '${input.packageSpec}' gcb daemon --config ${mountedConfigArg}`
: `exec gcb daemon --config ${mountedConfigArg}`
const command = ` - sh
- -c
- |
Expand Down Expand Up @@ -214,11 +201,10 @@ Print a Docker sidecar definition for the broker (to stdout). Pair it with a con
--config <path> The sidecar's config, checked before anything is printed
(default: $GIT_BROKER_CONFIG, else ./broker.config.yml)
--socket-dir <path> Host directory the pushing container already mounts
--code <path> Run code mounted from this host directory instead of fetching the package
at start (as \`stage\` exports it); nothing is fetched or built at boot
--code <path> Run code mounted from this host directory instead of the installed binary
(as \`stage\` exports it); nothing is fetched or built at boot
--user <uid:gid> UID the sidecar runs as (default: this user)
--image <name> Base image (default: node:24-slim)
--package <spec> npm spec to run (default: gcb-host@<version>)
--image <name> Base image (default: ghcr.io/code-vaults/gcb-host:<version>)
--name <name> Service and container name (default: gcb)
-h, --help Show this help
`
Expand All @@ -235,6 +221,9 @@ export function runCompose(argv: readonly string[]): number {
say(COMPOSE_USAGE)
return 0
}
if (argv.some(argument => argument === '--package' || argument.startsWith('--package='))) {
fail('--package is not supported; pin the released image with --image instead')
}
const explicitConfig = args.value('config')
const dirArg = args.value('dir')
const configPath = path.resolve(
Expand Down Expand Up @@ -281,8 +270,7 @@ export function runCompose(argv: readonly string[]): number {
configPath: configFile,
socketDir,
user,
image: args.value('image') ?? 'node:24-slim',
packageSpec: args.value('package') ?? `gcb-host@${PACKAGE_VERSION}`,
image: args.value('image') ?? `ghcr.io/code-vaults/gcb-host:${PACKAGE_VERSION}`,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
name: args.value('name') ?? 'gcb',
code: args.value('code'),
}),
Expand Down
Loading
Loading