diff --git a/packages/aws-cdk/lib/docker.ts b/packages/aws-cdk/lib/docker.ts index f554aa20422c7..a5b95303549df 100644 --- a/packages/aws-cdk/lib/docker.ts +++ b/packages/aws-cdk/lib/docker.ts @@ -57,9 +57,10 @@ export async function prepareContainerAsset(asset: ContainerImageAssetMetadataEn } } + const buildArgs = ([] as string[]).concat(...Object.entries(asset.buildArgs || {}).map(([k, v]) => ['--build-arg', `${k}=${v}`])); const baseCommand = [ 'docker', 'build', - ...Object.entries(asset.buildArgs || {}).map(([k, v]) => `--build-arg ${k}=${v}`), + ...buildArgs, '--tag', latest, asset.path ]; diff --git a/packages/aws-cdk/test/test.docker.ts b/packages/aws-cdk/test/test.docker.ts index 4b2c4c875373a..826c36ce63297 100644 --- a/packages/aws-cdk/test/test.docker.ts +++ b/packages/aws-cdk/test/test.docker.ts @@ -92,7 +92,7 @@ export = { } // THEN - const command = ['docker', 'build', '--build-arg a=b', '--build-arg c=d', '--tag', `uri:latest`, '/foo']; + const command = ['docker', 'build', '--build-arg', 'a=b', '--build-arg', 'c=d', '--tag', `uri:latest`, '/foo']; test.ok(shellStub.calledWith(command)); prepareEcrRepositoryStub.restore();