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(codepipeline-actions): use IBaseService instead of BaseService in EcsDeployActionProps #6412

Merged
merged 18 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface EcsDeployActionProps extends codepipeline.CommonAwsActionProps
/**
* The ECS Service to deploy.
*/
readonly service: ecs.BaseService;
readonly service: ecs.IService;
}

/**
Expand Down Expand Up @@ -94,7 +94,7 @@ export class EcsDeployAction extends Action {

return {
configuration: {
ClusterName: this.props.service.cluster.clusterName,
ClusterName: this.props.service.clusterName,
ServiceName: this.props.service.serviceName,
FileName: this.props.imageFile && this.props.imageFile.fileName,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ export = {

test.done();
},

'can be created just by serviceArn'(test: Test) {
const service = anyIService();
const artifact = new codepipeline.Artifact('Artifact');

test.doesNotThrow(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the test.doesNotThrow(), it's redundant.

new cpactions.EcsDeployAction({
actionName: 'ECS',
service,
imageFile: artifact.atPath('imageFile.json'),
});
});
skinny85 marked this conversation as resolved.
Show resolved Hide resolved

test.done();
},
},
};

Expand All @@ -98,3 +113,11 @@ function anyEcsService(): ecs.FargateService {
taskDefinition,
});
}

function anyIService(): ecs.IService {
const stack = new cdk.Stack();
return ecs.FargateService.fromFargateServiceAttributes(stack, 'FargateService', {
serviceName: 'serviceName',
clusterName: 'clusterName',
});
}
15 changes: 13 additions & 2 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import { ScalableTaskCount } from './scalable-task-count';
*/
export interface IService extends IResource {
/**
* The Amazon Resource Name (ARN) of the service.
* The name of the cluster that hosts the service.
*/
readonly clusterName: string;
/**
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
* The name of the service.
*
* @attribute
*/
readonly serviceArn: string;
readonly serviceName: string;
}

/**
Expand Down Expand Up @@ -258,6 +262,8 @@ export abstract class BaseService extends Resource

/**
* The Amazon Resource Name (ARN) of the service.
*
* @attribute
*/
public readonly serviceArn: string;

Expand All @@ -277,6 +283,10 @@ export abstract class BaseService extends Resource
* The cluster that hosts the service.
*/
public readonly cluster: ICluster;
/**
* The cluster name that hosts the service.
*/
public readonly clusterName: string;

/**
* The details of the AWS Cloud Map service.
Expand Down Expand Up @@ -345,6 +355,7 @@ export abstract class BaseService extends Resource
this.serviceName = this.getResourceNameAttribute(this.resource.attrName);

this.cluster = props.cluster;
this.clusterName = props.cluster.clusterName;

if (props.cloudMapOptions) {
this.enableCloudMap(props.cloudMapOptions);
Expand Down
21 changes: 18 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ export interface IEc2Service extends IService {

}

/**
* The properties to import from the service using the EC2 launch type.
*/
export interface Ec2ServiceAttributes {
/**
* The name of the cluster that hosts the service.
*/
readonly clusterName: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be ICluster. Not clusterName.

/**
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
* The name of the service.
*/
readonly serviceName: string;
}

/**
* This creates a service using the EC2 launch type on an ECS cluster.
*
Expand All @@ -95,11 +109,12 @@ export interface IEc2Service extends IService {
export class Ec2Service extends BaseService implements IEc2Service {

/**
* Imports from the specified service ARN.
* Imports from the specified service attrributes.
*/
public static fromEc2ServiceArn(scope: Construct, id: string, ec2ServiceArn: string): IEc2Service {
public static fromEc2ServiceAttributes(scope: Construct, id: string, attrs: Ec2ServiceAttributes): IEc2Service {
class Import extends Resource implements IEc2Service {
public readonly serviceArn = ec2ServiceArn;
public readonly serviceName = attrs.serviceName;
public readonly clusterName = attrs.clusterName;
}
return new Import(scope, id);
}
Expand Down
21 changes: 18 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ export interface IFargateService extends IService {

}

/**
* The properties to import from the service using the Fargate launch type.
*/
export interface FargateServiceAttributes {
/**
* The name of the cluster that hosts the service.
*/
readonly clusterName: string;
/**
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
* The name of the service.
*/
readonly serviceName: string;
}

/**
* This creates a service using the Fargate launch type on an ECS cluster.
*
Expand All @@ -73,11 +87,12 @@ export interface IFargateService extends IService {
export class FargateService extends BaseService implements IFargateService {

/**
* Import a task definition from the specified task definition ARN.
* Imports from the specified service attrributes.
*/
public static fromFargateServiceArn(scope: cdk.Construct, id: string, fargateServiceArn: string): IFargateService {
public static fromFargateServiceAttributes(scope: cdk.Construct, id: string, attrs: FargateServiceAttributes): IFargateService {
class Import extends cdk.Resource implements IFargateService {
public readonly serviceArn = fargateServiceArn;
public readonly serviceName = attrs.serviceName;
public readonly clusterName = attrs.clusterName;
}
return new Import(scope, id);
}
Expand Down