Skip to content

Commit

Permalink
feat(core): show output during asset bundling
Browse files Browse the repository at this point in the history
Show Docker outpout during asset bundling.

Closes aws#8956
  • Loading branch information
jogold committed Jul 9, 2020
1 parent d80efae commit 2e0146f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class AssetStaging extends Construct {
];

try {
console.error(`Bundling asset ${this.node.path}...`); // tslint:disable-line no-console
options.image._run({
command: options.command,
user,
Expand Down
13 changes: 8 additions & 5 deletions packages/@aws-cdk/core/lib/bundling.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawnSync } from 'child_process';
import { spawnSync, SpawnSyncOptions } from 'child_process';

/**
* Bundling options
Expand Down Expand Up @@ -121,7 +121,7 @@ export class BundlingDockerImage {
...command,
];

dockerExec(dockerArgs);
dockerExec(dockerArgs, { stdio: 'inherit' }); // show Docker output in console
}
}

Expand Down Expand Up @@ -222,16 +222,19 @@ function flatten(x: string[][]) {
return Array.prototype.concat([], ...x);
}

function dockerExec(args: string[]) {
function dockerExec(args: string[], options?: SpawnSyncOptions) {
const prog = process.env.CDK_DOCKER ?? 'docker';
const proc = spawnSync(prog, args);
const proc = spawnSync(prog, args, options);

if (proc.error) {
throw proc.error;
}

if (proc.status !== 0) {
throw new Error(`[Status ${proc.status}] stdout: ${proc.stdout?.toString().trim()}\n\n\nstderr: ${proc.stderr?.toString().trim()}`);
if (proc.stdout || proc.stderr) {
throw new Error(`[Status ${proc.status}] stdout: ${proc.stdout?.toString().trim()}\n\n\nstderr: ${proc.stderr?.toString().trim()}`);
}
throw new Error(`${prog} exited with status ${proc.status}`);
}

return proc;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/core/test/test.bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export = {
'-w', '/working-directory',
'alpine',
'cool', 'command',
]));
], { stdio: 'inherit' }));
test.done();
},

Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/core/test/test.staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export = {
const ensureDirSyncSpy = sinon.spy(fs, 'ensureDirSync');
const mkdtempSyncSpy = sinon.spy(fs, 'mkdtempSync');
const chmodSyncSpy = sinon.spy(fs, 'chmodSync');
const consoleErrorSpy = sinon.spy(console, 'error');

// WHEN
new AssetStaging(stack, 'Asset', {
Expand Down Expand Up @@ -138,6 +139,9 @@ export = {
test.ok(mkdtempSyncSpy.calledWith(sinon.match(path.join(stagingTmp, 'asset-bundle-'))));
test.ok(chmodSyncSpy.calledWith(sinon.match(path.join(stagingTmp, 'asset-bundle-')), 0o777));

// shows a message before bundling
test.ok(consoleErrorSpy.calledWith('Bundling asset stack/Asset...'));

test.done();
},

Expand Down

0 comments on commit 2e0146f

Please sign in to comment.