Skip to content

Commit

Permalink
fix(assets): run executable command of container assets in cloud asse…
Browse files Browse the repository at this point in the history
…mbly root directory (#16094)

Runs the executable command of container assets in the cloud assembly root directory and not the current directory.

Could be a breaking change.

fixes #15721
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
pgarbe authored Sep 7, 2021
1 parent f19896b commit c2852c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/cdk-assets/lib/private/handlers/container-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ export class ContainerImageAssetHandler implements IAssetHandler {
* External command is responsible for deduplicating the build if possible,
* and is expected to return the generated image identifier on stdout.
*/
private async buildExternalAsset(executable: string[]): Promise<string | undefined> {
private async buildExternalAsset(executable: string[], cwd?: string): Promise<string | undefined> {

const assetPath = cwd ?? this.workDir;

this.host.emitMessage(EventType.BUILD, `Building Docker image using command '${executable}'`);
if (this.host.aborted) { return undefined; }

return (await shell(executable, { quiet: true })).trim();
return (await shell(executable, { cwd: assetPath, quiet: true })).trim();
}


/**
* Check whether the image already exists in the ECR repo
*
Expand Down
2 changes: 1 addition & 1 deletion packages/cdk-assets/test/docker-images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('external assets', () => {

const expectAllSpawns = mockSpawn(
{ commandLine: ['docker', 'login', '--username', 'user', '--password-stdin', 'https://proxy.com/'] },
{ commandLine: ['sometool'], stdout: externalTag },
{ commandLine: ['sometool'], stdout: externalTag, cwd: '/external/cdk.out' },
{ commandLine: ['docker', 'tag', externalTag, '12345.amazonaws.com/repo:ghijkl'] },
{ commandLine: ['docker', 'push', '12345.amazonaws.com/repo:ghijkl'] },
);
Expand Down

0 comments on commit c2852c9

Please # to comment.