Moves the warning not to copy .gitignore patterns into .dockerignore next to the .dockerignore rule, splits the two long paragraphs into lists, and cuts the history "since consuming repos receive the file and not the tracker"; every pattern rule stays. Model: opus-5-5
This commit is contained in:
1 parent
64b8139d44
commit
2bc68d1f1e
1 file changed
+37
-32
+37
-32
@@ -645,6 +645,8 @@ style conventions are in separate documents:
|
||||
`if: github.ref_name == 'main'`, so the run from the feature branch
|
||||
publishes nothing.
|
||||
|
||||
# `.gitignore` and `.dockerignore`
|
||||
|
||||
- `.gitignore` should be comprehensive from the start:
|
||||
- OS files (`.DS_Store`)
|
||||
- editor files (`.swp`, `*~`)
|
||||
@@ -657,47 +659,50 @@ style conventions are in separate documents:
|
||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.gitignore` when setting
|
||||
up a new repo. A repo's `.gitignore` is the standard file followed by the
|
||||
repo's own entries, such as its binaries. A re-vendor replaces the standard
|
||||
part and keeps those entries. These patterns are written to `.gitignore`'s
|
||||
own semantics, in which an unanchored pattern already matches at every
|
||||
depth. They are not a `.dockerignore` and must not be transplanted into one
|
||||
unmodified.
|
||||
part and keeps those entries.
|
||||
|
||||
- **`.dockerignore` does not use `.gitignore` semantics, and copying patterns
|
||||
across unmodified leaves secrets in the build context.** Docker matches with
|
||||
across unmodified leaves secrets in the build context.** The standard
|
||||
`.gitignore` patterns are written to `.gitignore`'s own semantics, in which an
|
||||
unanchored pattern already matches at every depth. They must not be
|
||||
transplanted into a `.dockerignore` unmodified. Docker matches with
|
||||
`moby/patternmatcher`: `filepath.Match` semantics plus a `**` extension. So
|
||||
`*` does not cross `/`, and a pattern without a leading `**/` is anchored at
|
||||
the build-context root. A `.dockerignore` listing `.env`, `*.pem` and `*.key`
|
||||
therefore excludes only the copies at the repository root. `config/.env` and
|
||||
`certs/server.key` still reach the context and can land in an image layer.
|
||||
Such a `.dockerignore` is more dangerous than a short file with no secret
|
||||
patterns at all, because it reads as solved and stops anyone looking. Give
|
||||
every depth-independent pattern the `**/` prefix, and leave only genuinely
|
||||
root-anchored entries unprefixed. Those are `.claude`, `.yarn/*`,
|
||||
`!.yarn/releases`, and the repo's own host-built binary. The binary is written
|
||||
`/myapp` and never `**/myapp`, which would also match `cmd/myapp/` and delete
|
||||
the package directory from the context. Matching is case-sensitive, and an
|
||||
all-caps copy of each pattern still misses `Server.Key`. So secret names use
|
||||
character ranges: `**/*.[kK][eE][yY]`, `**/*.[pP][eE][mM]`, and likewise for
|
||||
`.envrc` and the extensionless SSH keys. Where such a pattern also catches
|
||||
something the build needs, re-include it with a negation
|
||||
(`!docs/example.env`). Deleting the pattern reopens the exposure for every
|
||||
other file it covers. Fetch the standard `.dockerignore` from
|
||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.dockerignore` and extend
|
||||
it with the repo's own artifacts.
|
||||
the build-context root.
|
||||
- A `.dockerignore` listing `.env`, `*.pem` and `*.key` therefore excludes
|
||||
only the copies at the repository root. `config/.env` and
|
||||
`certs/server.key` still reach the context and can land in an image layer.
|
||||
Such a `.dockerignore` is more dangerous than a short file with no secret
|
||||
patterns at all, because it reads as solved and stops anyone looking.
|
||||
- Give every depth-independent pattern the `**/` prefix, and leave only
|
||||
genuinely root-anchored entries unprefixed. Those are `.claude`,
|
||||
`.yarn/*`, `!.yarn/releases`, and the repo's own host-built binary. The
|
||||
binary is written `/myapp` and never `**/myapp`, which would also match
|
||||
`cmd/myapp/` and delete the package directory from the context.
|
||||
- Matching is case-sensitive, and an all-caps copy of each pattern still
|
||||
misses `Server.Key`. So secret names use character ranges:
|
||||
`**/*.[kK][eE][yY]`, `**/*.[pP][eE][mM]`, and likewise for `.envrc` and
|
||||
the extensionless SSH keys.
|
||||
- Where such a pattern also catches something the build needs, re-include it
|
||||
with a negation (`!docs/example.env`). Deleting the pattern reopens the
|
||||
exposure for every other file it covers.
|
||||
- Fetch the standard `.dockerignore` from
|
||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.dockerignore` and
|
||||
extend it with the repo's own artifacts.
|
||||
|
||||
- **In-repo agent scratch belongs in both files, written to each file's own
|
||||
semantics.** `.claude/` holds one worktree per in-flight agent, an entire
|
||||
additional checkout of the repo. Under `COPY . .` the build context therefore
|
||||
inflates by a multiple of the repo, and another session's unreviewed work can
|
||||
be copied into an image layer. In `.gitignore` the entry is `.claude/`,
|
||||
unanchored. In `.dockerignore` it is `.claude`, anchored and with **no** `**/`
|
||||
prefix, because the prefixed form would also delete any nested directory of
|
||||
that name from the build. Anchoring carries a known gap. The canonical
|
||||
`.dockerignore` states the gap in its own comment, since consuming repos
|
||||
receive the file and not the tracker. The gap is that the directory is created
|
||||
in the agent's working directory. A repo running agents in subdirectories
|
||||
therefore still ships `services/api/.claude/` and must add its own anchored
|
||||
entry there.
|
||||
be copied into an image layer.
|
||||
- In `.gitignore` the entry is `.claude/`, unanchored.
|
||||
- In `.dockerignore` it is `.claude`, anchored and with **no** `**/` prefix,
|
||||
because the prefixed form would also delete any nested directory of that
|
||||
name from the build.
|
||||
- Anchoring carries a known gap, which the canonical `.dockerignore` states
|
||||
in its own comment. The directory is created in the agent's working
|
||||
directory. A repo running agents in subdirectories therefore still ships
|
||||
`services/api/.claude/` and must add its own anchored entry there.
|
||||
|
||||
- **Verify `.dockerignore` by enumerating the image, not by reading the
|
||||
patterns.** Plant files at the root _and_ at least two directories deep. Build
|
||||
|
||||
Reference in new issue
Block a user