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

feat(ecs): expose image name in container definition #17793

Merged
merged 9 commits into from
Feb 1, 2022
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ export class ContainerDefinition extends CoreConstruct {
*/
public readonly referencesSecretJsonField?: boolean;

/**
* The name of the image referenced by this container.
*/
public readonly imageName: string;

/**
* The inference accelerators referenced by this container.
*/
Expand Down Expand Up @@ -441,6 +446,8 @@ export class ContainerDefinition extends CoreConstruct {
this.containerName = props.containerName ?? this.node.id;

this.imageConfig = props.image.bind(this, this);
this.imageName = this.imageConfig.imageName;

if (props.logging) {
this.logDriverConfig = props.logging.bind(this, this);
}
Expand Down
26 changes: 26 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/container-definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2033,4 +2033,30 @@ describe('container definition', () => {
});

});

test('exposes image name', () => {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef');

// WHEN
const container = taskDefinition.addContainer('cont', {
image: ecs.ContainerImage.fromAsset(path.join(__dirname, 'demo-image')),
});

// THEN
expect(stack.resolve(container.imageName)).toEqual({
Copy link
Contributor

Choose a reason for hiding this comment

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

The unit tests for this module have been migrated to Assertions since this PR was opened! Please merge the latest from master, and update this unit test. (Should be pretty minimal effort).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's nothing to update here, it's an expectation on stack.resolve().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'Fn::Join': [
'',
[
{ Ref: 'AWS::AccountId' },
'.dkr.ecr.',
{ Ref: 'AWS::Region' },
'.',
{ Ref: 'AWS::URLSuffix' },
'/aws-cdk/assets:baa2d6eb2a17c75424df631c8c70ff39f2d5f3bee8b9e1a109ee24ca17300540',
],
],
});
});
});