Commit 6fa264af authored by Johan Helsing's avatar Johan Helsing

Use spawn instead of exec

parent 3db6d473
......@@ -278,8 +278,7 @@
"lodash": {
"version": "4.17.5",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",
"dev": true
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
},
"minimatch": {
"version": "3.0.4",
......
"use strict";
const GerritEventEmitter = require('gerrit-event-emitter').GerritEventEmitter;
const emitter = new GerritEventEmitter('codereview.qt-project.org');
const { exec } = require("child_process");
const { spawn } = require('child_process');
const { reduce } = require('lodash');
const fs = require('fs');
function startDockerTest(options, callback) {
const { qtWaylandRev, qt5Rev, containerName } = options;
const environment = {
QT_DOCKERTEST_QTWAYLAND_REV: qtWaylandRev,
QT_DOCKERTEST_QT5_REV: qt5Rev
};
const envArgs = reduce(environment, (args, value, key) => args.concat(['-e', `${key}=${value}`]), []);
const command = `docker run ${envArgs} --name ${containerName} qtbuilder-stretch`;
const args = [].concat(['run', '--name', containerName], envArgs, ['qtbuilder-stretch']);
console.log('docker ' + args.join(' '));
return spawn('docker', args);
}
emitter.on('patchsetCreated', data => {
const { change, patchSet } = data;
......@@ -18,11 +34,10 @@ emitter.on('patchsetCreated', data => {
const qtWaylandRev = patchSet.ref;
const qt5Rev = branch;
const command = `docker run -e QT_DOCKERTEST_QTWAYLAND_REV=${qtWaylandRev} -e QT_DOCKERTEST_QT5_REV=${qt5Rev} --name gerrit-watcher-${change.number}-${patchSet.number} qtbuilder-stretch`;
console.log(prefix, command);
exec(command, (err, stdout, stderr) => {
if (err) {
console.log(prefix, 'FAILED');
const containerName = `gerrit-watcher-${change.number}-${patchSet.number}`;
startDockerTest({qtWaylandRev, qt5Rev, containerName}, (error, stdout, stderr) => {
if (error) {
console.log(prefix, "FAILED: error", error);
console.log(stderr);
} else {
console.log(prefix, 'PASSED');
......@@ -34,3 +49,18 @@ emitter.on('gerritStreamEnd', () => emitter.start());
console.log("Starting gerrit-watcher");
emitter.start();
const initContainerName = 'gerrit-watcher-init-test-'+Math.floor(new Date() / 1000);
const initTest = startDockerTest({qtWaylandRev: '5.11', qt5Rev: '5.11', containerName: initContainerName});
const logFile = fs.createWriteStream(`logs/${initContainerName}`);
initTest.stdout.pipe(logFile);
initTest.stderr.pipe(logFile);
initTest.on('close', code => {
if (code != 0) {
console.log(initContainerName, "FAILED: with code", code);
} else {
console.log(initContainerName, 'PASSED');
}
logFile.close();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment