Skip to content

Commit 4550411

Browse files
fix(setup): pin the compose project on every lifecycle op
composeInstalls records the real project name from 'compose ls' and status and the destructive confirms print it, but every op ran 'compose -f <file>' with only cwd set — so Compose re-derived the project from that directory. The derived name is frequently not the recorded one: a directory is lowercased and stripped of dots (Sim.Demo_Test derives simdemo_test), and an explicit -p or COMPOSE_PROJECT_NAME at creation diverges outright. stop/down/reset could therefore act on a different project than the one named in the confirm, and reset runs 'down -v'. Route every op through composeArgs(), which pins '-p <recorded project>'. cwd stays, since the file's own relative paths still resolve against it. Verified with a stack started as -p pinned-name from a directory deriving simdemo_test: the old form found 0 of its containers, the pinned form finds them.
1 parent 02e93d8 commit 4550411

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

scripts/setup/lifecycle.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ function composeInstalls(): ComposeInstall[] {
155155
return installs
156156
}
157157

158+
/**
159+
* Compose args for an op on a detected install. `-p` is not optional: without it
160+
* Compose re-derives the project from the working directory, and that name is
161+
* frequently NOT the one `compose ls` reported — a directory is lowercased and
162+
* stripped of dots (`Sim.Demo` becomes `simdemo`), and an explicit `-p` or
163+
* COMPOSE_PROJECT_NAME at creation time diverges outright. Acting on a
164+
* re-derived name means `stop`/`down`/`reset` can target a different project
165+
* than the one named in the confirm — and `reset` runs `down -v`. Pinning the
166+
* recorded name makes the op hit exactly what was detected; cwd stays because
167+
* the file's own relative paths (build contexts, env_file) resolve against it.
168+
*/
169+
function composeArgs(install: ComposeInstall, ...verb: string[]): string[] {
170+
return ['compose', '-p', install.project, '-f', install.file, ...verb]
171+
}
172+
158173
/** Dev mode owns the split env files and, usually, the managed Postgres/Redis. */
159174
function devInstall(detection: Detection): DevInstall | null {
160175
const postgres = detection.dbContainer?.managed ?? false
@@ -240,7 +255,7 @@ function start(install: Install): void {
240255
if (install.kind === 'compose') {
241256
const spin = p.spinner()
242257
spin.start('Starting containers…')
243-
dockerRun(['compose', '-f', install.file, 'up', '-d'], 'docker compose up failed', install.dir)
258+
dockerRun(composeArgs(install, 'up', '-d'), 'docker compose up failed', install.dir)
244259
spin.stop('Containers up')
245260
p.note(
246261
[`open ${APP_URL}`, 'follow logs: sim logs', 'stop: sim stop'].join('\n'),
@@ -265,7 +280,7 @@ function stop(install: Install): void {
265280
if (install.kind === 'compose') {
266281
const spin = p.spinner()
267282
spin.start('Stopping containers…')
268-
dockerRun(['compose', '-f', install.file, 'stop'], 'docker compose stop failed', install.dir)
283+
dockerRun(composeArgs(install, 'stop'), 'docker compose stop failed', install.dir)
269284
spin.stop('Containers stopped (data kept)')
270285
p.note(['start again: sim start', 'remove: sim down'].join('\n'), 'Stopped')
271286
return
@@ -295,11 +310,7 @@ function restart(install: Install): void {
295310
if (install.kind === 'compose') {
296311
const spin = p.spinner()
297312
spin.start('Restarting containers…')
298-
dockerRun(
299-
['compose', '-f', install.file, 'restart'],
300-
'docker compose restart failed',
301-
install.dir
302-
)
313+
dockerRun(composeArgs(install, 'restart'), 'docker compose restart failed', install.dir)
303314
spin.stop('Containers restarted')
304315
p.note(`open ${APP_URL}`, 'Running')
305316
return
@@ -316,7 +327,7 @@ function restart(install: Install): void {
316327

317328
function showLogs(install: Install): void {
318329
if (install.kind === 'compose') {
319-
dockerInherit(['compose', '-f', install.file, 'logs', '-f', '--tail', '100'], install.dir)
330+
dockerInherit(composeArgs(install, 'logs', '-f', '--tail', '100'), install.dir)
320331
return
321332
}
322333
if (install.kind === 'dev') {
@@ -347,7 +358,7 @@ async function down(install: Install): Promise<void> {
347358
return
348359
}
349360
if (install.kind === 'compose') {
350-
dockerRun(['compose', '-f', install.file, 'down'], 'docker compose down failed', install.dir)
361+
dockerRun(composeArgs(install, 'down'), 'docker compose down failed', install.dir)
351362
p.log.step('Containers removed (volumes kept)')
352363
return
353364
}
@@ -390,11 +401,7 @@ async function reset(install: Install | null): Promise<void> {
390401
if (backup) p.log.step(`Archived ${backup}`)
391402
}
392403
if (install?.kind === 'compose') {
393-
dockerRun(
394-
['compose', '-f', install.file, 'down', '-v'],
395-
'docker compose down -v failed',
396-
install.dir
397-
)
404+
dockerRun(composeArgs(install, 'down', '-v'), 'docker compose down -v failed', install.dir)
398405
p.log.step('Containers and volumes removed')
399406
} else if (install?.kind === 'dev') {
400407
const names = managedNames(install)

0 commit comments

Comments
 (0)