Updated faceai container
All checks were successful
Publish FaceAI Container / publish (push) Successful in 2m23s
All checks were successful
Publish FaceAI Container / publish (push) Successful in 2m23s
This commit is contained in:
parent
85d6dff580
commit
07db048310
3 changed files with 136 additions and 18 deletions
53
faceai/docker/run-with-log-file.mjs
Normal file
53
faceai/docker/run-with-log-file.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import fs from 'node:fs';
|
||||
import fsp from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { spawn } from 'node:child_process';
|
||||
|
||||
const [, , logPath, ...commandArgs] = process.argv;
|
||||
|
||||
if (!logPath || commandArgs.length === 0) {
|
||||
process.stderr.write('Usage: node docker/run-with-log-file.mjs <log-path> <command> [args...]\n');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await fsp.mkdir(path.dirname(logPath), { recursive: true });
|
||||
|
||||
const logStream = fs.createWriteStream(logPath, { flags: 'a' });
|
||||
const child = spawn(commandArgs[0], commandArgs.slice(1), {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
stdio: ['inherit', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
function writeChunk(target, chunk) {
|
||||
target.write(chunk);
|
||||
logStream.write(chunk);
|
||||
}
|
||||
|
||||
child.stdout.on('data', (chunk) => {
|
||||
writeChunk(process.stdout, chunk);
|
||||
});
|
||||
|
||||
child.stderr.on('data', (chunk) => {
|
||||
writeChunk(process.stderr, chunk);
|
||||
});
|
||||
|
||||
child.on('error', (error) => {
|
||||
const message = `${error.stack || error.message}\n`;
|
||||
writeChunk(process.stderr, message);
|
||||
logStream.end(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
|
||||
child.on('close', (code, signal) => {
|
||||
logStream.end(() => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
}
|
||||
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue