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(cli): cross account docker image assets upload no longer works #14816

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
4 changes: 2 additions & 2 deletions packages/cdk-assets/lib/private/handlers/container-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class ContainerImageAssetHandler implements IAssetHandler {
public async publish(): Promise<void> {
const destination = await replaceAwsPlaceholders(this.asset.destination, this.host.aws);
const ecr = await this.host.aws.ecrClient(destination);
const account = (await this.host.aws.discoverCurrentAccount()).accountId;
const account = async () => (await this.host.aws.discoverCurrentAccount())?.accountId;
const repoUri = await repositoryUri(ecr, destination.repositoryName);

if (!repoUri) {
throw new Error(`No ECR repository named '${destination.repositoryName}' in account ${account}. Is this account bootstrapped?`);
throw new Error(`No ECR repository named '${destination.repositoryName}' in account ${await account()}. Is this account bootstrapped?`);
}

const imageUri = `${repoUri}:${destination.imageTag}`;
Expand Down
12 changes: 12 additions & 0 deletions packages/cdk-assets/test/docker-images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe('with a complete manifest', () => {
}));
});

test('Displays an error if the ECR repository cannot be found', async () => {
aws.mockEcr.describeImages = mockedApiFailure('RepositoryNotFoundException', 'Repository not Found');

await expect(pub.publish()).rejects.toThrow('Error publishing: Repository not Found');
});

test('successful run does not need to query account ID', async () => {
aws.mockEcr.describeImages = mockedApiResult({ /* No error == image exists */ });
await pub.publish();
expect(aws.discoverCurrentAccount).not.toHaveBeenCalled();
});

test('upload docker image if not uploaded yet but exists locally', async () => {
aws.mockEcr.describeImages = mockedApiFailure('ImageNotFoundException', 'File does not exist');
aws.mockEcr.getAuthorizationToken = mockedApiResult({
Expand Down