Skip to content

Commit

Permalink
fix(core): asset bundling fails with BuildKit (#8911)
Browse files Browse the repository at this point in the history
Docker buildkit has different output from the legacy builder unless you pass the -q flag in which case the output is always just the image tag. This PR works for both build versions.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
elthrasher committed Jul 6, 2020
1 parent 755648a commit c1d4e0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/core/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export class BundlingDockerImage {
const buildArgs = options.buildArgs || {};

const dockerArgs: string[] = [
'build',
'build', '-q',
...flatten(Object.entries(buildArgs).map(([k, v]) => ['--build-arg', `${k}=${v}`])),
path,
];

const docker = dockerExec(dockerArgs);

const match = docker.stdout.toString().match(/Successfully built ([a-z0-9]+)/);
const match = docker.stdout.toString().match(/sha256:([a-z0-9]+)/);

if (!match) {
throw new Error('Failed to extract image ID from Docker build output');
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/core/test/test.bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export = {
const spawnSyncStub = sinon.stub(child_process, 'spawnSync').returns({
status: 0,
stderr: Buffer.from('stderr'),
stdout: Buffer.from(`Successfully built ${imageId}`),
stdout: Buffer.from(`sha256:${imageId}`),
pid: 123,
output: ['stdout', 'stderr'],
signal: null,
Expand All @@ -63,7 +63,7 @@ export = {
image._run();

test.ok(spawnSyncStub.firstCall.calledWith('docker', [
'build',
'build', '-q',
'--build-arg', 'TEST_ARG=cdk-test',
'docker-path',
]));
Expand Down

0 comments on commit c1d4e0f

Please sign in to comment.