Compare commits
1 Commits
61448b0c4e
...
3a218497b8
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a218497b8 |
@@ -10,7 +10,10 @@
|
||||
# context root. A host-built binary is the usual case, and it must be
|
||||
# written anchored: `/myapp`, never `**/myapp`. The prefixed form also
|
||||
# matches `cmd/myapp/`, which deletes the package directory from the
|
||||
# context. In-repo agent scratch is the other case, for the same reason.
|
||||
# context. In-repo agent scratch is the other case, for the same reason
|
||||
# — with the caveat recorded at that entry: anchoring is exact only
|
||||
# where agents run at the repo root, and a repo where they do not must
|
||||
# add its own entries.
|
||||
#
|
||||
# Matching is case-sensitive, so `**/*.key` does not match
|
||||
# `certs/SERVER.KEY`, which is reachable on the case-insensitive
|
||||
@@ -38,12 +41,24 @@
|
||||
# `--build-arg VERSION=...`; see the version rule in REPO_POLICIES.md.
|
||||
.git
|
||||
|
||||
# In-repo agent scratch: one directory at the context root, holding a
|
||||
# full additional checkout of the repo for each in-flight agent. Written
|
||||
# anchored because it occurs exactly once — the `**/` form would also
|
||||
# match a nested directory of that name. Not case-folded, unlike the
|
||||
# secret patterns below: tooling creates this in exactly one spelling,
|
||||
# and a miss costs build-context bloat rather than exposure.
|
||||
# In-repo agent scratch: a directory holding a full additional checkout
|
||||
# of the repo for each in-flight agent. Anchored because it occurs
|
||||
# exactly once *where agents run at the repo root*, which is the
|
||||
# convention this file assumes; the `**/` form would also match any
|
||||
# nested directory of that name and delete it from the build.
|
||||
#
|
||||
# KNOWN GAP, and it is not hypothetical: the directory is created in the
|
||||
# agent's working directory. If agents in this repo run in
|
||||
# subdirectories — a monorepo with a per-service agent, say — then
|
||||
# `services/api/.claude/` is NOT excluded by the line below and still
|
||||
# reaches the build context and the image, which is the exposure this
|
||||
# entry exists to close. A repo in that shape adds its own anchored
|
||||
# entries (`/services/api/.claude`), or `**/.claude` after confirming no
|
||||
# legitimately named nested directory would be caught.
|
||||
#
|
||||
# Not case-folded, unlike the secret patterns below: tooling creates
|
||||
# this directory in exactly one spelling, so a folded pattern would add
|
||||
# no coverage.
|
||||
.claude
|
||||
|
||||
# Environment files. `*.env` covers both the bare `.env` name (`*` matches
|
||||
|
||||
35
TODO.md
35
TODO.md
@@ -27,21 +27,26 @@ fmt-check, and commit.
|
||||
reaching the image: another session's unreviewed, sometimes uncommitted work,
|
||||
inflating the context by a multiple of the repo and invalidating `COPY` for
|
||||
reasons unrelated to the repo's own content. The `.dockerignore` entry is
|
||||
root-anchored, because the directory occurs exactly once and the `**/` form
|
||||
additionally deletes any nested directory of that name; the `.gitignore` entry
|
||||
is unanchored, because `.gitignore` patterns already match at every depth, and
|
||||
each file is written to its own semantics rather than derived from the other.
|
||||
Also closed the consequence that ships broken silently: excluding `.git` means
|
||||
`git describe` cannot run in any build stage and yields an empty version
|
||||
without erroring, so `script/docker` and `script/cibuild` now compute the
|
||||
version on the host and pass `--build-arg VERSION`, and `REPO_POLICIES.md`
|
||||
states where `VERSION` comes from instead of leaving the reader to fill the
|
||||
gap with `git describe` inside the build. The two Go documents that carry the
|
||||
`GOLDFLAGS` pattern were corrected in the same pass, from `:=` to `?=`, since
|
||||
a `$(shell git describe)` evaluated inside a build stage is exactly the empty
|
||||
version this closes. Verified by enumerating a probe image before, after, and
|
||||
against the `**/`-prefixed form, with a positive control and the `CHECK_EPOCH`
|
||||
cache verification re-run under the changed build context.
|
||||
root-anchored, because the directory occurs exactly once where agents run at
|
||||
the repo root and the `**/` form additionally deletes any nested directory of
|
||||
that name — with the residual gap that follows from anchoring (a monorepo
|
||||
running agents in subdirectories still ships `services/api/.claude/`) stated
|
||||
in the canonical `.dockerignore`, the policy and the existing-repo checklist,
|
||||
since consuming repos receive the files rather than the tracker; the
|
||||
`.gitignore` entry is unanchored, because `.gitignore` patterns already match
|
||||
at every depth, and each file is written to its own semantics rather than
|
||||
derived from the other. Also closed the consequence that ships broken
|
||||
silently: excluding `.git` means `git describe` cannot run in any build stage
|
||||
and yields an empty version without erroring, so `script/docker` and
|
||||
`script/cibuild` now compute the version on the host and pass
|
||||
`--build-arg VERSION`, and `REPO_POLICIES.md` states where `VERSION` comes
|
||||
from instead of leaving the reader to fill the gap with `git describe` inside
|
||||
the build. The two Go documents that carry the `GOLDFLAGS` pattern were
|
||||
corrected in the same pass, from `:=` to `?=`, since a `$(shell git describe)`
|
||||
evaluated inside a build stage is exactly the empty version this closes.
|
||||
Verified by enumerating a probe image before, after, and against the
|
||||
`**/`-prefixed form, with a positive control and the `CHECK_EPOCH` cache
|
||||
verification re-run under the changed build context.
|
||||
- 2026-08-09: Closed the secret exposure in the canonical `.dockerignore`: a
|
||||
developer's local `.env`, `*.pem` or `*.key` was reaching the Docker build
|
||||
context under `COPY . .`, invisible to every git-based check because
|
||||
|
||||
@@ -49,13 +49,19 @@ last_modified: 2026-08-09
|
||||
```
|
||||
|
||||
```make
|
||||
# ?= so a Docker build can supply the value. `.dockerignore` excludes
|
||||
# `.git`, so inside a build stage `$(shell git describe ...)` expands to
|
||||
# the empty string without failing and the binary reports no version at
|
||||
# all. The Dockerfile declares `ARG VERSION` in the stage that compiles,
|
||||
# which puts it in the environment where this `?=` defers to it, and
|
||||
# `script/docker` / `script/cibuild` compute it on the host. See the
|
||||
# git-describe rule in REPO_POLICIES.md.
|
||||
# ?= rather than := because this `$(shell git describe ...)` is only
|
||||
# correct on the host. `.dockerignore` excludes `.git`, so evaluated
|
||||
# inside a build stage it expands to the empty string without failing
|
||||
# and the binary reports no version at all. The version is computed on
|
||||
# the host by `script/docker` / `script/cibuild` and passed with
|
||||
# `--build-arg VERSION=...`. If this repo's Dockerfile compiles by
|
||||
# invoking make (`RUN make build`), `ARG VERSION` in that stage puts the
|
||||
# value in the environment and `?=` defers to it. The canonical Go
|
||||
# template in REPO_POLICIES.md instead runs `go build` directly with
|
||||
# `-ldflags "... -X main.Version=${VERSION}"`, so there this Makefile is
|
||||
# a host-only path — but it is still `?=`, because a repo that later
|
||||
# moves the build behind make must not silently start shipping an empty
|
||||
# version. See the git-describe rule in REPO_POLICIES.md.
|
||||
VERSION ?= $(shell git describe --always --dirty)
|
||||
BUILDARCH := $(shell uname -m)
|
||||
|
||||
|
||||
@@ -52,6 +52,15 @@ with your task.
|
||||
the context by a multiple of it and can copy another session's unreviewed
|
||||
work into an image layer. Confirm by enumerating the image, not by reading
|
||||
the file — `.gitignore` hides these from `git status` too.
|
||||
- [ ] **Do agents in this repo run anywhere other than the repo root?** The
|
||||
scratch directory is created in the agent's working directory, so the
|
||||
canonical anchored entry misses `services/api/.claude/` in a monorepo with
|
||||
a per-service agent — it still reaches the build context and the image. An
|
||||
existing repo is where such a layout already exists, so check it here
|
||||
rather than assuming the canonical entry covers you: add anchored entries
|
||||
for the subdirectories that have one (`/services/api/.claude`), or
|
||||
`**/.claude` once you have confirmed no legitimately named nested
|
||||
directory would be caught.
|
||||
- [ ] If the repo embeds a version in a binary, that version is computed on the
|
||||
host and passed with `--build-arg VERSION=...` by `script/docker` and
|
||||
`script/cibuild`. No stage calls `git describe`: `.dockerignore` excludes
|
||||
|
||||
@@ -991,11 +991,13 @@ func main() {
|
||||
Use ldflags to inject version information at build time:
|
||||
|
||||
```makefile
|
||||
# ?= so a Docker build can supply the value. `.dockerignore` excludes `.git`,
|
||||
# so inside a build stage `$(shell git describe ...)` expands to the empty
|
||||
# string without failing and the binary reports no version. The Dockerfile
|
||||
# declares `ARG VERSION` in the stage that compiles, and `script/docker` /
|
||||
# `script/cibuild` compute it on the host — see REPO_POLICIES.md.
|
||||
# ?= rather than := because this `$(shell git describe ...)` is only correct
|
||||
# on the host: `.dockerignore` excludes `.git`, so evaluated inside a build
|
||||
# stage it expands to the empty string without failing and the binary reports
|
||||
# no version. The version is computed on the host by `script/docker` /
|
||||
# `script/cibuild` and passed with `--build-arg VERSION=...`; where the build
|
||||
# stage invokes make, `ARG VERSION` puts it in the environment and `?=` defers
|
||||
# to it. See the git-describe rule in REPO_POLICIES.md.
|
||||
VERSION ?= $(shell git describe --tags --always)
|
||||
BUILDARCH := $(shell go env GOARCH)
|
||||
|
||||
|
||||
@@ -64,7 +64,10 @@ Template files can be fetched from:
|
||||
the context root, so the copied form leaves `config/.env` in the build
|
||||
context while reading as solved. See the `.dockerignore` rule in
|
||||
`REPO_POLICIES.md`. The canonical file's `.claude` entry is anchored for
|
||||
the same reason as a repo-root binary; leave it that way.
|
||||
the same reason as a repo-root binary; leave it that way, but note it only
|
||||
covers agents running at the repo root — if this repo will run them in
|
||||
subdirectories, `services/api/.claude/` is not excluded and needs its own
|
||||
anchored entry.
|
||||
- If the image embeds a version in a binary, the version is computed on the
|
||||
host and passed with `--build-arg VERSION=...`. `ARG VERSION=dev` is
|
||||
declared in the stage that compiles, and **no stage calls `git describe`**
|
||||
@@ -113,20 +116,30 @@ are thin shims calling them. Model scripts:
|
||||
- [ ] `script/projectname` — outputs the project name (used by `script/docker`
|
||||
for the image tag)
|
||||
- [ ] `script/docker` / `make docker` — builds Docker image, tagged via
|
||||
`script/projectname` (byte-identical across repos); assigns
|
||||
`epoch="$(date +%s%N)$$"` and the `git describe` version on their own
|
||||
lines, and passes `--build-arg CHECK_EPOCH="$epoch"` and
|
||||
`--build-arg VERSION="$version"`
|
||||
- [ ] `script/cibuild` — cd to repo root, assign `epoch="$(date +%s%N)$$"` and
|
||||
`version="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"`
|
||||
on their own lines, then run
|
||||
`docker build --build-arg CHECK_EPOCH="$epoch" --build-arg VERSION="$version" .`
|
||||
(what CI runs). Both build args are mandatory, and both assignments must
|
||||
be on their own line: a failing command substitution inside an argument
|
||||
does not trip `set -e`, so the inline form degrades silently to an empty
|
||||
constant. See the `CHECK_EPOCH` and git-describe rules in
|
||||
`REPO_POLICIES.md` for why each element is load-bearing. A bare
|
||||
`docker build .` fails closed by design.
|
||||
`script/projectname` (byte-identical across repos); carries the same three
|
||||
version lines as `script/cibuild` below, and passes
|
||||
`--build-arg CHECK_EPOCH="$epoch"` and `--build-arg VERSION="$version"`
|
||||
- [ ] `script/cibuild` — cd to repo root, then, each on its own line:
|
||||
|
||||
```sh
|
||||
epoch="$(date +%s%N)$$"
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||
[ -n "$version" ] || version="unknown"
|
||||
docker build \
|
||||
--build-arg CHECK_EPOCH="$epoch" \
|
||||
--build-arg VERSION="$version" \
|
||||
.
|
||||
```
|
||||
|
||||
(what CI runs). Both build args are mandatory, and both assignments must be
|
||||
on their own line: a failing command substitution inside an argument does
|
||||
not trip `set -e`, so the inline form degrades silently to an empty
|
||||
constant. The `[ -n "$version" ]` line is a live check that fires on an
|
||||
export with no `.git` and on a repo with no commits — keep it, and do not
|
||||
collapse it into `|| echo unknown`, which makes it unreachable. See the
|
||||
`CHECK_EPOCH` and git-describe rules in `REPO_POLICIES.md` for why each
|
||||
element is load-bearing. A bare `docker build .` fails closed by design.
|
||||
|
||||
- [ ] `script/precommit` — called by the pre-commit hook; runs `script/check`
|
||||
- [ ] `script/install-precommit` — installs the pre-commit hook that runs
|
||||
`script/precommit`
|
||||
|
||||
@@ -124,7 +124,7 @@ style conventions are in separate documents:
|
||||
|
||||
```sh
|
||||
epoch="$(date +%s%N)$$"
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||
[ -n "$version" ] || version="unknown"
|
||||
docker build \
|
||||
--build-arg CHECK_EPOCH="$epoch" \
|
||||
@@ -391,10 +391,23 @@ style conventions are in separate documents:
|
||||
reasons that have nothing to do with the repo's own content. In `.gitignore`
|
||||
the entry is `.claude/`, unanchored, which already matches at every depth. In
|
||||
`.dockerignore` it is `.claude`, anchored and with **no** `**/` prefix: the
|
||||
directory occurs exactly once, at the context root, and the prefixed form
|
||||
would also match any nested directory of that name. It is not case-folded the
|
||||
way the secret patterns are, because tooling creates it in exactly one
|
||||
spelling and a miss costs context bloat rather than exposure.
|
||||
directory occurs exactly once **where agents run at the repo root**, and the
|
||||
prefixed form would also match any nested directory of that name and delete it
|
||||
from the build. It is not case-folded the way the secret patterns are, because
|
||||
tooling creates it in exactly one spelling, so a folded pattern would add no
|
||||
coverage.
|
||||
|
||||
**Known gap that comes with the anchored form.** The directory is created in
|
||||
the agent's working directory, so the "exactly once, at the root" premise is
|
||||
a property of how agents are run and not of the tooling. Where agents run in
|
||||
subdirectories — a monorepo with a per-service agent is the ordinary case —
|
||||
`services/api/.claude/` is **not** excluded by the canonical entry and still
|
||||
reaches the build context and the image, which is the exposure the entry
|
||||
exists to close. A repo in that shape adds its own anchored entries
|
||||
(`/services/api/.claude`), or `**/.claude` once it has confirmed no
|
||||
legitimately named nested directory would be caught. This is stated in the
|
||||
canonical `.dockerignore` itself, since that file is what consuming repos
|
||||
receive.
|
||||
|
||||
- **`.dockerignore` matching is case-sensitive, so cover capitalisation with
|
||||
character classes rather than by doubling patterns.** `**/*.key` does not
|
||||
@@ -438,7 +451,7 @@ style conventions are in separate documents:
|
||||
# Assign on its own line: a failing command substitution inside an
|
||||
# argument does not trip `set -e`, so the inline form degrades to an
|
||||
# empty constant — the same silent-empty failure this rule is about.
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||
[ -n "$version" ] || version="unknown"
|
||||
docker build \
|
||||
--build-arg CHECK_EPOCH="$epoch" \
|
||||
@@ -447,14 +460,21 @@ style conventions are in separate documents:
|
||||
```
|
||||
|
||||
`--always` makes an untagged repo yield the abbreviated commit hash instead
|
||||
of failing, and the `unknown` fallback covers a build from an export with no
|
||||
`.git` at all. Both are non-empty by construction: an empty version reads as
|
||||
a successful one, which is precisely the failure being closed. The
|
||||
Dockerfile's side is `ARG VERSION=dev` in the stage that compiles, declared
|
||||
there and not inherited, because `ARG` is stage-scoped exactly as
|
||||
`CHECK_EPOCH` is. Passing `VERSION` to a repo whose Dockerfile declares no
|
||||
such `ARG` is silently ignored by BuildKit and costs nothing, which is why
|
||||
the scripts stay byte-identical rather than growing a per-repo variant.
|
||||
of failing. `|| true` keeps a failing `git describe` from tripping `set -e`
|
||||
and leaves the value empty, so the `[ -n "$version" ]` line is the single
|
||||
place the fallback is applied — and it is a **live** check, not defence in
|
||||
depth: it fires on a build from an export with no `.git`, and on a
|
||||
repository with no commits yet. Do not fold the fallback into the
|
||||
substitution as `|| echo unknown`; that makes the guard unreachable, and a
|
||||
guard that cannot fire is indistinguishable from one that works to everyone
|
||||
who copies it. The result is non-empty by construction either way, which is
|
||||
the point: an empty version reads as a successful one, while `unknown` is
|
||||
visibly wrong. The Dockerfile's side is `ARG VERSION=dev` in the stage that
|
||||
compiles, declared there and not inherited, because `ARG` is stage-scoped
|
||||
exactly as `CHECK_EPOCH` is. Passing `VERSION` to a repo whose Dockerfile
|
||||
declares no such `ARG` is silently ignored by BuildKit and costs nothing,
|
||||
which is why the scripts stay byte-identical rather than growing a per-repo
|
||||
variant.
|
||||
|
||||
One consequence for CI: the standard checkout action clones shallow and
|
||||
fetches no tags, so `git describe --tags` there falls back to a bare commit
|
||||
|
||||
@@ -17,10 +17,12 @@ main() {
|
||||
# VERSION must be computed here, on the host: .dockerignore excludes
|
||||
# .git, so `git describe` cannot run in any build stage and fails
|
||||
# quietly there rather than erroring. Same own-line discipline as the
|
||||
# epoch, plus a non-empty fallback, so a repo built from an export
|
||||
# with no .git reports `unknown` rather than an empty version that
|
||||
# reads as a successful one.
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"
|
||||
# epoch. `|| true` keeps a failing describe from tripping `set -e`
|
||||
# and leaves the value empty; the guard below is then the single
|
||||
# place the fallback is applied, and it does fire — on an export with
|
||||
# no .git, or a repo with no commits yet. `unknown` is visibly wrong
|
||||
# in a binary in a way that an empty version is not.
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||
[ -n "$version" ] || version="unknown"
|
||||
docker build \
|
||||
--build-arg CHECK_EPOCH="$epoch" \
|
||||
|
||||
@@ -19,10 +19,12 @@ main() {
|
||||
# VERSION must be computed here, on the host: .dockerignore excludes
|
||||
# .git, so `git describe` cannot run in any build stage and fails
|
||||
# quietly there rather than erroring. Same own-line discipline as the
|
||||
# epoch, plus a non-empty fallback, so a repo built from an export
|
||||
# with no .git reports `unknown` rather than an empty version that
|
||||
# reads as a successful one.
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || echo unknown)"
|
||||
# epoch. `|| true` keeps a failing describe from tripping `set -e`
|
||||
# and leaves the value empty; the guard below is then the single
|
||||
# place the fallback is applied, and it does fire — on an export with
|
||||
# no .git, or a repo with no commits yet. `unknown` is visibly wrong
|
||||
# in a binary in a way that an empty version is not.
|
||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||
[ -n "$version" ] || version="unknown"
|
||||
docker build \
|
||||
--build-arg CHECK_EPOCH="$epoch" \
|
||||
|
||||
Reference in New Issue
Block a user