Skip to content

Commit

Permalink
Move from exec to spawn to avoid stdout buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pazdera committed Dec 14, 2017
1 parent 57853ae commit e98574e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions lib/deploy-methods/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ function _doReleaseBySync(build, target, data) {
rs.pipe(write);

write.on('finish', () => {
let env = Object.assign({}, process.env);
let env = Object.assign({}, process.env),
proc,
errBuffer = "";

if (config.local.awsKey) {
env.AWS_ACCESS_KEY_ID = config.local.awsKey;
Expand All @@ -102,16 +104,25 @@ function _doReleaseBySync(build, target, data) {
env.AWS_SECRET_ACCESS_KEY = config.local.awsSecret;
}

childProcess.exec(`aws s3 sync ${path} s3://${target}`, {env}, (err, stdout, stderr) => {
if (err) {
proc = childProcess.spawn('aws', ['s3', 'sync', path, `s3://${target}`], {
env: env,
stdio: ['pipe', 'ignore', 'pipe'],
shell: true
});
proc.stderr.on('data', function (data) {
errBuffer += data + "\n";
});

proc.on('close', function (code) {
if (code !== 0) {
cleanupCb();

if (err.toString().indexOf('aws: command not found')) {
if (errBuffer.toString().indexOf('aws: command not found') >= 0) {
console.log('It looks like you don\'t have the `aws` command on your system that is required to deploy this build.');
console.log('See https://aws.amazon.com/cli/ for instructions how to inststall the AWS CLI.');
}

return reject('Sync failed: ' + err);
return reject('Sync failed: ' + errBuffer.trim());
}

cleanupCb();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kart",
"version": "0.4.4",
"version": "0.4.5",
"description": "Kano Archive and Release Tool. Managing releases mainly of static websites.",
"main": "lib/index.js",
"bin": {
Expand Down

0 comments on commit e98574e

Please sign in to comment.