Skip to content

Commit 200e43c

Browse files
committed
buildx(history): detach dial-stdio process
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 2cb2c55 commit 200e43c

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/buildx/history.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {ChildProcessByStdio, spawn} from 'child_process';
17+
import {spawn} from 'child_process';
1818
import fs from 'fs';
19-
import {Readable, Writable} from 'node:stream';
2019
import os from 'os';
2120
import path from 'path';
2221
import * as core from '@actions/core';
@@ -93,9 +92,17 @@ export class History {
9392
await Exec.exec('mkfifo', [buildxOutFifoPath]);
9493

9594
const buildxCmd = await this.buildx.getCommand(['--builder', builderName, 'dial-stdio']);
96-
const buildxDialStdioProc = History.spawn(buildxCmd.command, buildxCmd.args);
95+
96+
core.info(`[command]${buildxCmd.command} ${buildxCmd.args.join(' ')}`);
97+
const buildxDialStdioProc = spawn(buildxCmd.command, buildxCmd.args, {
98+
stdio: ['pipe', 'pipe', 'inherit'],
99+
detached: true
100+
});
97101
fs.createReadStream(buildxInFifoPath).pipe(buildxDialStdioProc.stdin);
98102
buildxDialStdioProc.stdout.pipe(fs.createWriteStream(buildxOutFifoPath));
103+
buildxDialStdioProc.on('exit', code => {
104+
core.info(`Process "buildx dial-stdio" exited with code ${code}`);
105+
});
99106

100107
const tmpDockerbuildFilename = path.join(outDir, 'rec.dockerbuild');
101108
const summaryFilename = path.join(outDir, 'summary.json');
@@ -112,13 +119,17 @@ export class History {
112119
ebargs.push(`--gid=${process.getgid()}`);
113120
}
114121
// prettier-ignore
115-
const dockerRunProc = History.spawn('docker', [
122+
const dockerRunArgs = [
116123
'run', '--rm', '-i',
117124
'-v', `${Buildx.refsDir}:/buildx-refs`,
118125
'-v', `${outDir}:/out`,
119126
opts.image || History.EXPORT_TOOL_IMAGE,
120127
...ebargs
121-
]);
128+
]
129+
core.info(`[command]docker ${dockerRunArgs.join(' ')}`);
130+
const dockerRunProc = spawn('docker', dockerRunArgs, {
131+
stdio: ['pipe', 'pipe', 'inherit']
132+
});
122133
fs.createReadStream(buildxOutFifoPath).pipe(dockerRunProc.stdin);
123134
dockerRunProc.stdout.pipe(fs.createWriteStream(buildxInFifoPath));
124135
dockerRunProc.on('close', code => {
@@ -133,9 +144,12 @@ export class History {
133144
}
134145
});
135146
dockerRunProc.on('error', err => {
136-
core.error(`Error executing buildx dial-stdio: ${err}`);
147+
core.error(`Error executing "docker run": ${err}`);
137148
reject(err);
138149
});
150+
dockerRunProc.on('exit', code => {
151+
core.info(`Process "docker run" exited with code ${code}`);
152+
});
139153
}).catch(err => {
140154
throw err;
141155
});
@@ -162,11 +176,4 @@ export class History {
162176
refs: refs
163177
};
164178
}
165-
166-
private static spawn(command: string, args?: ReadonlyArray<string>): ChildProcessByStdio<Writable, Readable, null> {
167-
core.info(`[command]${command}${args ? ` ${args.join(' ')}` : ''}`);
168-
return spawn(command, args || [], {
169-
stdio: ['pipe', 'pipe', 'inherit']
170-
});
171-
}
172179
}

0 commit comments

Comments
 (0)