Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const cliInteg = configureProject(
'@aws-sdk/client-codeartifact@^3',
'@aws-sdk/client-cloudformation@^3',
'@aws-sdk/client-ecr@^3',
'@aws-sdk/client-ecr-public@^3',
'@aws-sdk/client-ecs@^3',
'@aws-sdk/client-iam@^3',
'@aws-sdk/client-lambda@^3',
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type Stack,
} from '@aws-sdk/client-cloudformation';
import { DeleteRepositoryCommand, ECRClient } from '@aws-sdk/client-ecr';
import { ECRPUBLICClient } from '@aws-sdk/client-ecr-public';
import { ECSClient } from '@aws-sdk/client-ecs';
import { IAMClient } from '@aws-sdk/client-iam';
import { LambdaClient } from '@aws-sdk/client-lambda';
Expand Down Expand Up @@ -42,6 +43,7 @@ export class AwsClients {
public readonly cloudFormation: CloudFormationClient;
public readonly s3: S3Client;
public readonly ecr: ECRClient;
public readonly ecrPublic: ECRPUBLICClient;
public readonly ecs: ECSClient;
public readonly sso: SSOClient;
public readonly sns: SNSClient;
Expand All @@ -61,6 +63,7 @@ export class AwsClients {
this.cloudFormation = new CloudFormationClient(this.config);
this.s3 = new S3Client(this.config);
this.ecr = new ECRClient(this.config);
this.ecrPublic = new ECRPUBLICClient({ ...this.config, region: 'us-east-1' /* public gallery is only available in us-east-1 */ });
this.ecs = new ECSClient(this.config);
this.sso = new SSOClient(this.config);
this.sns = new SNSClient(this.config);
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { DescribeStacksCommand, Stack } from '@aws-sdk/client-cloudformation';
import { GetAuthorizationTokenCommand } from '@aws-sdk/client-ecr-public';
import { outputFromStack, AwsClients, sleep } from './aws';
import { TestContext } from './integ-test';
import { findYarnPackages } from './package-sources/repo-source';
Expand Down Expand Up @@ -345,6 +346,36 @@ export class TestFixture extends ShellHelper {
this.output.write(`${s}\n`);
}

/**
* Login to the public ECR gallery using the current AWS credentials.
* Use this if your test needs to directly pull images outside of a `cdk` or `cdk-assets` command.
*/
public async ecrPublicLogin() {

const tokenResponse = await this.aws.ecrPublic.send(new GetAuthorizationTokenCommand({}));
const authData = tokenResponse.authorizationData?.authorizationToken;

const docker = process.env.CDK_DOCKER ?? 'docker';

if (!authData) {
throw new Error("Could not retrieve ECR public auth token.");
}

const decoded = Buffer.from(authData, "base64").toString("utf-8");
const [username, password] = decoded.split(":");

await this.shell([docker, 'login',
'--username', username,
'--password', "${ECR_PASSWORD}",
'public.ecr.aws'], {
shell: true,
modEnv: {
ECR_PASSWORD: password,
},
});

}

public async cdkDeploy(stackNames: string | string[], options: CdkCliOptions = {}, skipStackRename?: boolean) {
return this.cdk(this.cdkDeployCommandLine(stackNames, options, skipStackRename), options);
}
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk-testing/cli-integ/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async function runInIsolatedContainer(fixture: TestFixture, pathsToMount: string

await fs.chmod(scriptName, 0o755);

await fixture.ecrPublicLogin();

// Run commands in a Docker shell
await fixture.shell([
docker, 'run', '--net=bridge', '--rm',
Expand Down
45 changes: 45 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.