Skip to content

Commit 9ce0f3b

Browse files
committed
Merge remote-tracking branch 'origin/next' into mn-wf-g2-native-compose-feature-refusals-b21
# Conflicts: # src/commands/doctor.ts
2 parents 9ee2bec + ec223cd commit 9ce0f3b

30 files changed

Lines changed: 2830 additions & 134 deletions

‎docs/architecture.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ Projects can declare shareable env overlays and safely inject secrets into compo
113113
At runtime, hack resolves the selected overlay and injects the effective env directly into compose and
114114
host-side command flows. For service-scoped values, hack still generates
115115
`.hack/.internal/compose.env.override.yml` so compose services get the right per-service environment
116-
without requiring `.hack/.env` to exist. That file holds resolved plaintext, so it is written like
117-
`.hack/.env`: atomically, mode `0600`, and never through a symlink.
116+
without requiring `.hack/.env` to exist. That file holds only `${HACK_ENV_...}` references; the values
117+
reach `docker compose` through its process environment, so no decrypted value rests on disk.
118118

119119
See `docs/env.md` for the current env model and migration notes.
120120

‎docs/env.md‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ Hack reads the canonical YAML files and injects the resolved env directly into:
196196

197197
That means `.hack/.env` is no longer the primary runtime source of truth.
198198

199+
On the Compose backend, Hack still generates `.hack/.internal/compose.env.override.yml`
200+
so each service gets its own environment. The file holds no values: each entry is a
201+
`${HACK_ENV_<digest>_<KEY>}` reference, and Hack passes the resolved values to
202+
`docker compose` through its process environment. Nothing Hack writes there contains a
203+
decrypted value, whether `up` succeeds, fails or is interrupted. The file is written
204+
with mode 0600, and Hack refuses to write through a symlink at that path. A value
205+
reaches the container literally, `$` included.
206+
207+
Only the `docker compose` invocations that read the override (`up`, `run`, `exec`,
208+
`ps` and the dependency cache initialization) receive the `HACK_ENV_*` values. The other
209+
`docker` commands Hack runs around Compose, such as `docker inspect`, `docker logs` and
210+
`docker events` for dependency cache progress and reuse, get the same environment
211+
without them.
212+
213+
Because the file holds only references, a `docker compose -f
214+
.hack/.internal/compose.env.override.yml ...` command run outside Hack (a script, an IDE
215+
integration or a test harness) gets a blank value for every managed variable, with only a
216+
per-variable warning from Compose. Use `hack run` or `hack exec`, or supply the same
217+
`HACK_ENV_*` variables to that command.
218+
219+
Every service gets its own `HACK_ENV_*` copy of each value, including values that come
220+
from the global scope, so the Compose client environment grows with services times keys.
221+
The platform limits apply to it: about 1 MiB of arguments and environment in total on
222+
macOS, and on Linux also 128 KiB (`MAX_ARG_STRLEN`) for a single `NAME=value` string. A
223+
larger single value, such as a big JSON credential, makes the Compose start fail with
224+
`E2BIG`.
225+
226+
When you upgrade from an earlier version, read the two subsections at the end of this
227+
section: managed values that contain `$` now reach containers differently, and an
228+
override written by the earlier version can still hold values.
229+
199230
`hack env materialize` is manual by design. Use it only when you need a compatibility file for an external tool that expects `.env` on disk.
200231

201232
Hack writes `.hack/.env` and `.hack/.env.<overlay>` (from `materialize`, legacy
@@ -216,6 +247,53 @@ That means Hack prefers host-usable values when it can:
216247

217248
Use `--target compose` if you explicitly want the container-oriented compose view instead.
218249

250+
### Upgrading: managed values that contain `$`
251+
252+
Earlier versions wrote each value into the override literally, so Compose interpolated
253+
a `$` inside a managed value: `$VAR` and `${VAR}` became the host or Compose value of
254+
`VAR` (blank when unset), and `$$` became `$`. Now Compose substitutes each reference
255+
once and does not interpolate the value, so the container receives the value exactly as
256+
stored, `$` included. If a managed value contains `$`:
257+
258+
- the container sees a different value after the upgrade, and the next `hack up`
259+
recreates that service's containers because their configuration changed;
260+
- a value that relied on interpolation (for example `${HOME}/data`) now reaches the
261+
container unexpanded; store the expanded value instead;
262+
- a value that escaped `$` as `$$` now reaches the container as `$$`; store a single `$`.
263+
264+
Values without `$` reach containers unchanged, and their containers are not recreated.
265+
266+
### Overrides from earlier versions
267+
268+
An override written by an earlier Hack version can still hold literal values. The next
269+
`hack up`, `hack restart`, `hack run` or `hack exec` replaces it or, when it renders no
270+
override, removes it. `hack down` removes it before its lifecycle hooks, the remote target
271+
or `docker compose down` run, so a failed hook, a remote target or a failed Compose down
272+
does not keep it. `hack doctor` reports such a file in its "compose env at rest" check
273+
(counts only, never values), and `hack doctor --fix` removes it.
274+
275+
A legacy adoption (`hack config adopt`) pins the override's exact bytes and file
276+
identity for as long as the adoption exists, and adopted commands never rewrite it. So:
277+
278+
- `hack config adopt` and `hack config adopt --dry-run` refuse a literal override. Run
279+
`hack up` once so Hack rewrites it with references, then adopt.
280+
- An adoption made by an earlier version over a literal override keeps that file. Hack
281+
never removes it while a prepared, active or pending adoption exists, because removal
282+
would make the adoption refuse to load. `hack doctor` reports it with this next step.
283+
To drop the values, stop the adopted containers (`hack down`), run
284+
`hack config adopt --rollback`, run `hack up` so Hack rewrites the file with references,
285+
then adopt again with `hack config adopt --stop`.
286+
287+
A removal first moves the file aside, then checks what it moved. If a concurrent Hack
288+
command had just replaced it with a value-free file, that file is put back rather than
289+
deleted. Between the move and the put-back the path is briefly absent, so a Compose
290+
command started by that concurrent Hack command at that moment can fail to find it; run
291+
the command again. If Hack is killed between the move and the delete, the moved file
292+
(`.hack/.internal/.compose.env.override.yml.<id>.remove`) can hold values. `hack doctor`
293+
reports such files by count, and the next removal, `hack doctor --fix`, or `hack up`,
294+
`hack restart`, `hack run` or `hack exec` deletes each one once it is more than a minute
295+
old. A newer one may belong to a removal that is still running, so it is left alone.
296+
219297
## Choosing the right execution surface
220298

221299
- `hack host exec` / `hack host shell`: run on your host machine with Hack-resolved env injected.

0 commit comments

Comments
 (0)