The resolveService helper implements a strategy to prefer native binaries but fall back to Docker if necessary. This is used by stack.start() and prefetch().
Resolution Logic
resolveService attempts to resolve a binary via BinaryResolver. The result is a ServiceResolution object:
- Success: If a binary is found and extracted, it returns
{ type: "binary", path: string }. - Fallback to Docker: If
BinaryNotFoundError or DownloadError occurs, it returns { type: "docker", image: string } using the appropriate Docker image for that service and version. - Hard Failure: If a
ChecksumMismatchError occurs, the error is propagated and not replaced by Docker, as a corrupted download is treated as a security/integrity issue.
type ServiceResolution =
| { readonly type: "binary"; readonly path: string }
| { readonly type: "docker"; readonly image: string };
export const resolveService = (
resolver: BinaryResolver["Service"],
service: ServiceName,
version: string,
): Effect.Effect<ServiceResolution, ChecksumMismatchError> =>
resolver.resolve({ service, version }).pipe(
Effect.map((path): ServiceResolution => ({ type: "binary", path })),
Effect.catchTag("BinaryNotFoundError", () =>
Effect.succeed<ServiceResolution>({
type: "docker",
image: dockerImageForService(service, version),
}),
),
Effect.catchTag("DownloadError", () =>
Effect.succeed<ServiceResolution>({
type: "docker",
image: dockerImageForService(service, version),
}),
),
);