Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 0716633

Browse files
authored
fix(cli-integ): proxy test is being throttled by ecr (#80)
We are seeing sporadic throttling errors: ```console πŸ’» docker run --net=bridge --rm -v /tmp:/tmp -v /home/runner:/home/runner -v /tmp/cdk-integ-0ffcgkzpab:/tmp/cdk-integ-0ffcgkzpab -e HOME -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -w /tmp/cdk-integ-0ffcgkzpab --cap-add=NET_ADMIN public.ecr.aws/ubuntu/ubuntu:24.04_stable /tmp/cdk-integ-0ffcgkzpab/script.sh Unable to find image 'public.ecr.aws/ubuntu/ubuntu:24.04_stable' locally 24.04_stable: Pulling from ubuntu/ubuntu docker: toomanyrequests: Rate exceeded. See 'docker run --help'. 'docker run --net=bridge --rm -v /tmp:/tmp -v /home/runner:/home/runner -v /tmp/cdk-integ-0ffcgkzpab:/tmp/cdk-integ-0ffcgkzpab -e HOME -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -w /tmp/cdk-integ-0ffcgkzpab --cap-add=NET_ADMIN public.ecr.aws/ubuntu/ubuntu:24.04_stable /tmp/cdk-integ-0ffcgkzpab/script.sh' exited with error code 125.Error: 'docker run --net=bridge --rm -v /tmp:/tmp -v /home/runner:/home/runner -v /tmp/cdk-integ-0ffcgkzpab:/tmp/cdk-integ-0ffcgkzpab -e HOME -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -w /tmp/cdk-integ-0ffcgkzpab --cap-add=NET_ADMIN public.ecr.aws/ubuntu/ubuntu:24.04_stable /tmp/cdk-integ-0ffcgkzpab/script.sh' exited with error code 125. at ChildProcess.<anonymous> (/home/runner/work/aws-cdk-cli/aws-cdk-cli/lib/shell.ts:109:22) at ChildProcess.emit (node:events:524:28) at maybeClose (node:internal/child_process:1104:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) ::endgroup:: ``` Login to ECR to increase our throttling limits.
1 parent 3371cf1 commit 0716633

File tree

7 files changed

+88
-0
lines changed

7 files changed

+88
-0
lines changed

β€Ž.projenrc.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const cliInteg = configureProject(
172172
'@aws-sdk/client-codeartifact@^3',
173173
'@aws-sdk/client-cloudformation@^3',
174174
'@aws-sdk/client-ecr@^3',
175+
'@aws-sdk/client-ecr-public@^3',
175176
'@aws-sdk/client-ecs@^3',
176177
'@aws-sdk/client-iam@^3',
177178
'@aws-sdk/client-lambda@^3',

β€Žpackages/@aws-cdk-testing/cli-integ/.projen/deps.jsonβ€Ž

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackages/@aws-cdk-testing/cli-integ/lib/aws.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type Stack,
77
} from '@aws-sdk/client-cloudformation';
88
import { DeleteRepositoryCommand, ECRClient } from '@aws-sdk/client-ecr';
9+
import { ECRPUBLICClient } from '@aws-sdk/client-ecr-public';
910
import { ECSClient } from '@aws-sdk/client-ecs';
1011
import { IAMClient } from '@aws-sdk/client-iam';
1112
import { LambdaClient } from '@aws-sdk/client-lambda';
@@ -42,6 +43,7 @@ export class AwsClients {
4243
public readonly cloudFormation: CloudFormationClient;
4344
public readonly s3: S3Client;
4445
public readonly ecr: ECRClient;
46+
public readonly ecrPublic: ECRPUBLICClient;
4547
public readonly ecs: ECSClient;
4648
public readonly sso: SSOClient;
4749
public readonly sns: SNSClient;
@@ -61,6 +63,7 @@ export class AwsClients {
6163
this.cloudFormation = new CloudFormationClient(this.config);
6264
this.s3 = new S3Client(this.config);
6365
this.ecr = new ECRClient(this.config);
66+
this.ecrPublic = new ECRPUBLICClient({ ...this.config, region: 'us-east-1' /* public gallery is only available in us-east-1 */ });
6467
this.ecs = new ECSClient(this.config);
6568
this.sso = new SSOClient(this.config);
6669
this.sns = new SNSClient(this.config);

β€Žpackages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.tsβ€Ž

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from 'fs';
44
import * as os from 'os';
55
import * as path from 'path';
66
import { DescribeStacksCommand, Stack } from '@aws-sdk/client-cloudformation';
7+
import { GetAuthorizationTokenCommand } from '@aws-sdk/client-ecr-public';
78
import { outputFromStack, AwsClients, sleep } from './aws';
89
import { TestContext } from './integ-test';
910
import { findYarnPackages } from './package-sources/repo-source';
@@ -345,6 +346,36 @@ export class TestFixture extends ShellHelper {
345346
this.output.write(`${s}\n`);
346347
}
347348

349+
/**
350+
* Login to the public ECR gallery using the current AWS credentials.
351+
* Use this if your test needs to directly pull images outside of a `cdk` or `cdk-assets` command.
352+
*/
353+
public async ecrPublicLogin() {
354+
355+
const tokenResponse = await this.aws.ecrPublic.send(new GetAuthorizationTokenCommand({}));
356+
const authData = tokenResponse.authorizationData?.authorizationToken;
357+
358+
const docker = process.env.CDK_DOCKER ?? 'docker';
359+
360+
if (!authData) {
361+
throw new Error("Could not retrieve ECR public auth token.");
362+
}
363+
364+
const decoded = Buffer.from(authData, "base64").toString("utf-8");
365+
const [username, password] = decoded.split(":");
366+
367+
await this.shell([docker, 'login',
368+
'--username', username,
369+
'--password', "${ECR_PASSWORD}",
370+
'public.ecr.aws'], {
371+
shell: true,
372+
modEnv: {
373+
ECR_PASSWORD: password,
374+
},
375+
});
376+
377+
}
378+
348379
public async cdkDeploy(stackNames: string | string[], options: CdkCliOptions = {}, skipStackRename?: boolean) {
349380
return this.cdk(this.cdkDeployCommandLine(stackNames, options, skipStackRename), options);
350381
}

β€Žpackages/@aws-cdk-testing/cli-integ/package.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/proxy.integtest.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ async function runInIsolatedContainer(fixture: TestFixture, pathsToMount: string
5555

5656
await fs.chmod(scriptName, 0o755);
5757

58+
await fixture.ecrPublicLogin();
59+
5860
// Run commands in a Docker shell
5961
await fixture.shell([
6062
docker, 'run', '--net=bridge', '--rm',

β€Žyarn.lockβ€Ž

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)