sdk: fix piping stdio of Daemons, support onStdOut/onStderr (#2762)

This commit is contained in:
Remco Ros
2024-10-25 00:29:12 +02:00
committed by GitHub
parent 7694b68e06
commit 42cfd69463
5 changed files with 26 additions and 15 deletions

View File

@@ -35,8 +35,8 @@ export interface ExecSpawnable {
): Promise<ExecResults>
spawn(
command: string[],
options?: CommandOptions,
): Promise<cp.ChildProcessWithoutNullStreams>
options?: CommandOptions & StdioOptions,
): Promise<cp.ChildProcess>
}
/**
* Want to limit what we can do in a container, so we want to launch a container with a specific image and the mounts.
@@ -332,8 +332,8 @@ export class SubContainer implements ExecSpawnable {
async spawn(
command: string[],
options?: CommandOptions,
): Promise<cp.ChildProcessWithoutNullStreams> {
options: CommandOptions & StdioOptions = { stdio: "inherit" },
): Promise<cp.ChildProcess> {
await this.waitProc()
const imageMeta: any = await fs
.readFile(`/media/startos/images/${this.imageId}.json`, {
@@ -342,12 +342,12 @@ export class SubContainer implements ExecSpawnable {
.catch(() => "{}")
.then(JSON.parse)
let extra: string[] = []
if (options?.user) {
if (options.user) {
extra.push(`--user=${options.user}`)
delete options.user
}
let workdir = imageMeta.workdir || "/"
if (options?.cwd) {
if (options.cwd) {
workdir = options.cwd
delete options.cwd
}
@@ -387,8 +387,8 @@ export class SubContainerHandle implements ExecSpawnable {
}
spawn(
command: string[],
options?: CommandOptions,
): Promise<cp.ChildProcessWithoutNullStreams> {
options: CommandOptions & StdioOptions = { stdio: "inherit" },
): Promise<cp.ChildProcess> {
return this.subContainer.spawn(command, options)
}
}
@@ -399,6 +399,10 @@ export type CommandOptions = {
user?: string
}
export type StdioOptions = {
stdio?: cp.IOType
}
export type MountOptions =
| MountOptionsVolume
| MountOptionsAssets