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
+35
-30
+35
-30
@@ -645,6 +645,8 @@ style conventions are in separate documents:
|
|||||||
`if: github.ref_name == 'main'`, so the run from the feature branch
|
`if: github.ref_name == 'main'`, so the run from the feature branch
|
||||||
publishes nothing.
|
publishes nothing.
|
||||||
|
|
||||||
|
# `.gitignore` and `.dockerignore`
|
||||||
|
|
||||||
- `.gitignore` should be comprehensive from the start:
|
- `.gitignore` should be comprehensive from the start:
|
||||||
- OS files (`.DS_Store`)
|
- OS files (`.DS_Store`)
|
||||||
- editor files (`.swp`, `*~`)
|
- 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
|
`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
|
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
|
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
|
part and keeps those entries.
|
||||||
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.
|
|
||||||
|
|
||||||
- **`.dockerignore` does not use `.gitignore` semantics, and copying patterns
|
- **`.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
|
`moby/patternmatcher`: `filepath.Match` semantics plus a `**` extension. So
|
||||||
`*` does not cross `/`, and a pattern without a leading `**/` is anchored at
|
`*` does not cross `/`, and a pattern without a leading `**/` is anchored at
|
||||||
the build-context root. A `.dockerignore` listing `.env`, `*.pem` and `*.key`
|
the build-context root.
|
||||||
therefore excludes only the copies at the repository root. `config/.env` and
|
- 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.
|
`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
|
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
|
patterns at all, because it reads as solved and stops anyone looking.
|
||||||
every depth-independent pattern the `**/` prefix, and leave only genuinely
|
- Give every depth-independent pattern the `**/` prefix, and leave only
|
||||||
root-anchored entries unprefixed. Those are `.claude`, `.yarn/*`,
|
genuinely root-anchored entries unprefixed. Those are `.claude`,
|
||||||
`!.yarn/releases`, and the repo's own host-built binary. The binary is written
|
`.yarn/*`, `!.yarn/releases`, and the repo's own host-built binary. The
|
||||||
`/myapp` and never `**/myapp`, which would also match `cmd/myapp/` and delete
|
binary is written `/myapp` and never `**/myapp`, which would also match
|
||||||
the package directory from the context. Matching is case-sensitive, and an
|
`cmd/myapp/` and delete the package directory from the context.
|
||||||
all-caps copy of each pattern still misses `Server.Key`. So secret names use
|
- Matching is case-sensitive, and an all-caps copy of each pattern still
|
||||||
character ranges: `**/*.[kK][eE][yY]`, `**/*.[pP][eE][mM]`, and likewise for
|
misses `Server.Key`. So secret names use character ranges:
|
||||||
`.envrc` and the extensionless SSH keys. Where such a pattern also catches
|
`**/*.[kK][eE][yY]`, `**/*.[pP][eE][mM]`, and likewise for `.envrc` and
|
||||||
something the build needs, re-include it with a negation
|
the extensionless SSH keys.
|
||||||
(`!docs/example.env`). Deleting the pattern reopens the exposure for every
|
- Where such a pattern also catches something the build needs, re-include it
|
||||||
other file it covers. Fetch the standard `.dockerignore` from
|
with a negation (`!docs/example.env`). Deleting the pattern reopens the
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.dockerignore` and extend
|
exposure for every other file it covers.
|
||||||
it with the repo's own artifacts.
|
- 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
|
- **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
|
semantics.** `.claude/` holds one worktree per in-flight agent, an entire
|
||||||
additional checkout of the repo. Under `COPY . .` the build context therefore
|
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
|
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/`,
|
be copied into an image layer.
|
||||||
unanchored. In `.dockerignore` it is `.claude`, anchored and with **no** `**/`
|
- In `.gitignore` the entry is `.claude/`, unanchored.
|
||||||
prefix, because the prefixed form would also delete any nested directory of
|
- In `.dockerignore` it is `.claude`, anchored and with **no** `**/` prefix,
|
||||||
that name from the build. Anchoring carries a known gap. The canonical
|
because the prefixed form would also delete any nested directory of that
|
||||||
`.dockerignore` states the gap in its own comment, since consuming repos
|
name from the build.
|
||||||
receive the file and not the tracker. The gap is that the directory is created
|
- Anchoring carries a known gap, which the canonical `.dockerignore` states
|
||||||
in the agent's working directory. A repo running agents in subdirectories
|
in its own comment. The directory is created in the agent's working
|
||||||
therefore still ships `services/api/.claude/` and must add its own anchored
|
directory. A repo running agents in subdirectories therefore still ships
|
||||||
entry there.
|
`services/api/.claude/` and must add its own anchored entry there.
|
||||||
|
|
||||||
- **Verify `.dockerignore` by enumerating the image, not by reading the
|
- **Verify `.dockerignore` by enumerating the image, not by reading the
|
||||||
patterns.** Plant files at the root _and_ at least two directories deep. Build
|
patterns.** Plant files at the root _and_ at least two directories deep. Build
|
||||||
|
|||||||
Reference in new issue
Block a user