Skip to content

Commit 847944f

Browse files
committed
fix(setup): fall back to the installed app when the context isn't OrbStack
Context detection only fell back to the app bundle when `docker context show` failed outright, so an OrbStack-only Mac sitting on the `default` context still resolved to Docker Desktop — the same 90s hang this fix exists to remove. Treat an explicit OrbStack selection as the only positive context signal and otherwise pick whichever app is installed. Read `DOCKER_HOST` first: it overrides the active context, so the context name is not authoritative while it is set.
1 parent 02180df commit 847944f

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

scripts/setup/docker.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,34 @@ function installed(): boolean {
2424
return Bun.which('docker') !== null
2525
}
2626

27-
function currentDockerContext(): string | null {
27+
/**
28+
* Whether the docker CLI is currently pointed at OrbStack. `DOCKER_HOST` wins
29+
* over the active context when set, so it is the only signal worth reading in
30+
* that case; otherwise the active context is authoritative, since OrbStack
31+
* registers and selects a context named `orbstack`.
32+
*/
33+
function orbstackSelected(): boolean {
34+
const host = process.env.DOCKER_HOST
35+
if (host) return host.includes('.orbstack/')
2836
const result = spawnSync('docker', ['context', 'show'], { encoding: 'utf8' })
29-
return result.status === 0 ? result.stdout.trim() : null
37+
return result.status === 0 && result.stdout.trim() === 'orbstack'
3038
}
3139

3240
/**
33-
* Which GUI app owns the `docker` CLI on this Mac. Docker Desktop and OrbStack
34-
* both install a `docker` binary, so presence of the CLI alone doesn't tell us
35-
* which app to relaunch. Prefer the docker CLI's own active context — it's
36-
* accurate regardless of where the app bundle lives, and authoritative when
37-
* both apps are installed but only one is the active context. Only fall back
38-
* to checking the well-known `.app` install path when the context command
39-
* gives no answer at all.
41+
* Which GUI app owns the `docker` CLI on this Mac. Both apps install a `docker`
42+
* binary, so CLI presence alone doesn't say which one to launch. An explicit
43+
* OrbStack selection wins; otherwise prefer whichever app is actually
44+
* installed, which also covers CLIs too old for `docker context show`.
4045
*/
4146
function macDockerApp(): typeof ORBSTACK_APP | typeof DOCKER_DESKTOP_APP {
42-
const context = currentDockerContext()
43-
if (context !== null) return context === 'orbstack' ? ORBSTACK_APP : DOCKER_DESKTOP_APP
47+
if (orbstackSelected()) return ORBSTACK_APP
48+
if (existsSync(DOCKER_DESKTOP_APP.path)) return DOCKER_DESKTOP_APP
4449
return existsSync(ORBSTACK_APP.path) ? ORBSTACK_APP : DOCKER_DESKTOP_APP
4550
}
4651

4752
/**
48-
* Returns whether the Docker daemon is available, offering to launch Docker
49-
* Desktop (macOS) when it's installed but stopped. Never installs anything.
53+
* Returns whether the Docker daemon is available, offering to launch the
54+
* installed docker app (macOS) when it's stopped. Never installs anything.
5055
* With required=true, unavailability is a SetupError instead of false.
5156
*/
5257
export async function ensureDocker(required: boolean): Promise<boolean> {

0 commit comments

Comments
 (0)