Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(assets): run executable command of container assets in cloud assembly root directory #16094

Merged
merged 3 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an assertion that verifies that the default is to run next to assets.json, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why I extended the mock of "sometool" so that it also checks that cwd is set to "/external/cdk.out".

{ 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