diff --git a/packages/cdk-blue-green-container-deployment/package.json b/packages/cdk-blue-green-container-deployment/package.json index 6a68588f0..f8f83ff8f 100644 --- a/packages/cdk-blue-green-container-deployment/package.json +++ b/packages/cdk-blue-green-container-deployment/package.json @@ -1,6 +1,6 @@ { "name": "@cloudcomponents/cdk-blue-green-container-deployment", - "version": "1.48.0", + "version": "2.0.0", "description": "Blue green container deployment with CodeDeploy", "license": "MIT", "author": { @@ -60,36 +60,21 @@ } } }, - "peerDependencies": { - "@aws-cdk/aws-codebuild": "^1.134.0", - "@aws-cdk/aws-codedeploy": "^1.134.0", - "@aws-cdk/aws-ec2": "^1.134.0", - "@aws-cdk/aws-ecr": "^1.134.0", - "@aws-cdk/aws-ecs": "^1.134.0", - "@aws-cdk/aws-elasticloadbalancingv2": "^1.134.0", - "@aws-cdk/aws-iam": "^1.134.0", - "@aws-cdk/aws-lambda": "^1.134.0", - "@aws-cdk/core": "^1.134.0", - "@aws-cdk/custom-resources": "^1.134.0", - "constructs": "^3.2.0" - }, "dependencies": { - "@aws-cdk/aws-codebuild": "^1.134.0", - "@aws-cdk/aws-codedeploy": "^1.134.0", - "@aws-cdk/aws-ec2": "^1.134.0", - "@aws-cdk/aws-ecr": "^1.134.0", - "@aws-cdk/aws-ecs": "^1.134.0", - "@aws-cdk/aws-elasticloadbalancingv2": "^1.134.0", - "@aws-cdk/aws-iam": "^1.134.0", - "@aws-cdk/aws-lambda": "^1.134.0", - "@aws-cdk/core": "^1.134.0", - "@aws-cdk/custom-resources": "^1.134.0" + "aws-cdk-lib": "2.4.0", + "aws-lambda": "^1.0.7", + "constructs": "^10.0.0", + "custom-resource-helper": "^1.0.15", + "source-map-support": "^0.5.16" }, "devDependencies": { "@aws-cdk/assert": "^1.134.0", - "aws-sdk": "^2.1035.0", - "custom-resource-helper": "^1.0.15", + "aws-cdk": "2.4.0", + "jest": "^26.4.2", "jest-cdk-snapshot": "^1.4.2", + "ts-jest": "^26.2.0", + "ts-node": "^9.0.0", + "typescript": "~3.9.7", "winston": "^3.3.3" }, "externals": [ diff --git a/packages/cdk-blue-green-container-deployment/src/dummy-task-definition.ts b/packages/cdk-blue-green-container-deployment/src/dummy-task-definition.ts index a62d7c990..5dbffe7f5 100644 --- a/packages/cdk-blue-green-container-deployment/src/dummy-task-definition.ts +++ b/packages/cdk-blue-green-container-deployment/src/dummy-task-definition.ts @@ -1,8 +1,21 @@ -import { NetworkMode } from '@aws-cdk/aws-ecs'; -import { Role, ServicePrincipal, ManagedPolicy, PolicyStatement, Effect, IRole } from '@aws-cdk/aws-iam'; -import { Construct, ITaggable, TagManager, TagType, Lazy } from '@aws-cdk/core'; -import { AwsCustomResource, AwsCustomResourcePolicy, AwsSdkCall, PhysicalResourceId, PhysicalResourceIdReference } from '@aws-cdk/custom-resources'; - +import { NetworkMode } from "aws-cdk-lib/aws-ecs"; +import { + Role, + ServicePrincipal, + ManagedPolicy, + PolicyStatement, + Effect, + IRole, +} from "aws-cdk-lib/aws-iam"; +import { ITaggable, TagManager, TagType, Lazy } from "aws-cdk-lib/core"; +import { + AwsCustomResource, + AwsCustomResourcePolicy, + AwsSdkCall, + PhysicalResourceId, + PhysicalResourceIdReference, +} from "aws-cdk-lib/custom-resources"; +import { Construct } from "constructs"; export interface IDummyTaskDefinition { readonly executionRole: IRole; @@ -40,7 +53,10 @@ export interface DummyTaskDefinitionProps { readonly containerPort?: number; } -export class DummyTaskDefinition extends Construct implements IDummyTaskDefinition, ITaggable { +export class DummyTaskDefinition + extends Construct + implements IDummyTaskDefinition, ITaggable +{ public readonly executionRole: IRole; public readonly family: string; @@ -56,27 +72,31 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti constructor(scope: Construct, id: string, props: DummyTaskDefinitionProps) { super(scope, id); - this.tags = new TagManager(TagType.STANDARD, 'TagManager'); + this.tags = new TagManager(TagType.STANDARD, "TagManager"); - this.executionRole = new Role(this, 'ExecutionRole', { - assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'), - managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonECSTaskExecutionRolePolicy')], + this.executionRole = new Role(this, "ExecutionRole", { + assumedBy: new ServicePrincipal("ecs-tasks.amazonaws.com"), + managedPolicies: [ + ManagedPolicy.fromAwsManagedPolicyName( + "service-role/AmazonECSTaskExecutionRolePolicy" + ), + ], }); this.family = props.family ?? this.node.addr; - this.containerName = props.containerName ?? 'sample-website'; + this.containerName = props.containerName ?? "sample-website"; this.containerPort = props.containerPort ?? 80; const registerTaskDefinition: AwsSdkCall = { - service: 'ECS', - action: 'registerTaskDefinition', + service: "ECS", + action: "registerTaskDefinition", parameters: { - requiresCompatibilities: ['FARGATE'], + requiresCompatibilities: ["FARGATE"], family: this.family, executionRoleArn: this.executionRole.roleArn, networkMode: NetworkMode.AWS_VPC, - cpu: '256', - memory: '512', + cpu: "256", + memory: "512", containerDefinitions: [ { name: this.containerName, @@ -84,7 +104,7 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti portMappings: [ { hostPort: this.containerPort, - protocol: 'tcp', + protocol: "tcp", containerPort: this.containerPort, }, ], @@ -92,37 +112,44 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti ], tags: Lazy.any({ produce: () => this.tags.renderTags() }), }, - physicalResourceId: PhysicalResourceId.fromResponse('taskDefinition.taskDefinitionArn'), + physicalResourceId: PhysicalResourceId.fromResponse( + "taskDefinition.taskDefinitionArn" + ), }; const deregisterTaskDefinition: AwsSdkCall = { - service: 'ECS', - action: 'deregisterTaskDefinition', + service: "ECS", + action: "deregisterTaskDefinition", parameters: { taskDefinition: new PhysicalResourceIdReference(), }, }; - const taskDefinition = new AwsCustomResource(this, 'DummyTaskDefinition', { - resourceType: 'Custom::DummyTaskDefinition', + const taskDefinition = new AwsCustomResource(this, "DummyTaskDefinition", { + resourceType: "Custom::DummyTaskDefinition", onCreate: registerTaskDefinition, onUpdate: registerTaskDefinition, onDelete: deregisterTaskDefinition, policy: AwsCustomResourcePolicy.fromStatements([ new PolicyStatement({ effect: Effect.ALLOW, - actions: ['ecs:RegisterTaskDefinition', 'ecs:DeregisterTaskDefinition'], - resources: ['*'], + actions: [ + "ecs:RegisterTaskDefinition", + "ecs:DeregisterTaskDefinition", + ], + resources: ["*"], }), new PolicyStatement({ effect: Effect.ALLOW, - actions: ['iam:PassRole'], + actions: ["iam:PassRole"], resources: [this.executionRole.roleArn], }), ]), }); - this.taskDefinitionArn = taskDefinition.getResponseField('taskDefinition.taskDefinitionArn'); + this.taskDefinitionArn = taskDefinition.getResponseField( + "taskDefinition.taskDefinitionArn" + ); } /** diff --git a/packages/cdk-blue-green-container-deployment/src/ecs-deployment-config.ts b/packages/cdk-blue-green-container-deployment/src/ecs-deployment-config.ts index d3fc0e926..ac47f7133 100644 --- a/packages/cdk-blue-green-container-deployment/src/ecs-deployment-config.ts +++ b/packages/cdk-blue-green-container-deployment/src/ecs-deployment-config.ts @@ -1,5 +1,6 @@ -import { CfnDeploymentConfig } from '@aws-cdk/aws-codedeploy'; -import { Aws, Construct, IResolvable, Resource } from '@aws-cdk/core'; +import { CfnDeploymentConfig } from "aws-cdk-lib/aws-codedeploy"; +import { Aws, IResolvable, Resource } from "aws-cdk-lib/core"; +import { Construct } from "constructs"; export interface IEcsDeploymentConfig { readonly deploymentConfigName: string; @@ -20,22 +21,39 @@ export interface EcsDeploymentConfigurationProps { * @external * @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentconfig.html#cfn-codedeploy-deploymentconfig-minimumhealthyhosts */ - readonly minimumHealthyHosts?: CfnDeploymentConfig.MinimumHealthyHostsProperty | IResolvable; + readonly minimumHealthyHosts?: + | CfnDeploymentConfig.MinimumHealthyHostsProperty + | IResolvable; /** * `AWS::CodeDeploy::DeploymentConfig.TrafficRoutingConfig`. * * @external * @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentconfig.html#cfn-codedeploy-deploymentconfig-trafficroutingconfig */ - readonly trafficRoutingConfig?: CfnDeploymentConfig.TrafficRoutingConfigProperty | IResolvable; + readonly trafficRoutingConfig?: + | CfnDeploymentConfig.TrafficRoutingConfigProperty + | IResolvable; } -export class EcsDeploymentConfig extends Resource implements IEcsDeploymentConfig { - public static readonly LINEAR_10PERCENT_EVERY_1MINUTE = deploymentConfig('CodeDeployDefault.ECSLinear10PercentEvery1Minutes'); - public static readonly LINEAR_10PERCENT_EVERY_3MINUTES = deploymentConfig('CodeDeployDefault.ECSLinear10PercentEvery3Minutes'); - public static readonly CANARY_10PERCENT_5MINUTES = deploymentConfig('CodeDeployDefault.ECSCanary10Percent5Minutes'); - public static readonly CANARY_10PERCENT_15MINUTES = deploymentConfig('CodeDeployDefault.ECSCanary10Percent15Minutes'); - public static readonly ALL_AT_ONCE = deploymentConfig('CodeDeployDefault.ECSAllAtOnce'); +export class EcsDeploymentConfig + extends Resource + implements IEcsDeploymentConfig +{ + public static readonly LINEAR_10PERCENT_EVERY_1MINUTE = deploymentConfig( + "CodeDeployDefault.ECSLinear10PercentEvery1Minutes" + ); + public static readonly LINEAR_10PERCENT_EVERY_3MINUTES = deploymentConfig( + "CodeDeployDefault.ECSLinear10PercentEvery3Minutes" + ); + public static readonly CANARY_10PERCENT_5MINUTES = deploymentConfig( + "CodeDeployDefault.ECSCanary10Percent5Minutes" + ); + public static readonly CANARY_10PERCENT_15MINUTES = deploymentConfig( + "CodeDeployDefault.ECSCanary10Percent15Minutes" + ); + public static readonly ALL_AT_ONCE = deploymentConfig( + "CodeDeployDefault.ECSAllAtOnce" + ); /** * Import a custom Deployment Configuration for an ECS Deployment Group defined outside the CDK. @@ -45,23 +63,37 @@ export class EcsDeploymentConfig extends Resource implements IEcsDeploymentConfi * @param ecsDeploymentConfigName the name of the referenced custom Deployment Configuration * @returns a Construct representing a reference to an existing custom Deployment Configuration */ - public static fromEcsDeploymentConfigName(_scope: Construct, _id: string, ecsDeploymentConfigName: string): IEcsDeploymentConfig { + public static fromEcsDeploymentConfigName( + _scope: Construct, + _id: string, + ecsDeploymentConfigName: string + ): IEcsDeploymentConfig { return deploymentConfig(ecsDeploymentConfigName); } public readonly deploymentConfigName: string; public readonly deploymentConfigArn: string; - constructor(scope: Construct, id: string, props: EcsDeploymentConfigurationProps) { + constructor( + scope: Construct, + id: string, + props: EcsDeploymentConfigurationProps + ) { super(scope, id); - const cfnDeploymentConfig = new CfnDeploymentConfig(this, 'EcsDeploymentConfiguration', { - computePlatform: 'ECS', - ...props, - }); + const cfnDeploymentConfig = new CfnDeploymentConfig( + this, + "EcsDeploymentConfiguration", + { + computePlatform: "ECS", + ...props, + } + ); this.deploymentConfigName = cfnDeploymentConfig.ref; - this.deploymentConfigArn = arnForDeploymentConfig(this.deploymentConfigName); + this.deploymentConfigArn = arnForDeploymentConfig( + this.deploymentConfigName + ); } } diff --git a/packages/cdk-blue-green-container-deployment/src/ecs-deployment-group.ts b/packages/cdk-blue-green-container-deployment/src/ecs-deployment-group.ts index a79aa67eb..d728c9425 100644 --- a/packages/cdk-blue-green-container-deployment/src/ecs-deployment-group.ts +++ b/packages/cdk-blue-green-container-deployment/src/ecs-deployment-group.ts @@ -1,9 +1,25 @@ import * as path from 'path'; -import { EcsApplication, IEcsApplication } from '@aws-cdk/aws-codedeploy'; -import { ApplicationTargetGroup } from '@aws-cdk/aws-elasticloadbalancingv2'; -import { Role, ServicePrincipal, ManagedPolicy, Effect, PolicyStatement } from '@aws-cdk/aws-iam'; -import { Function, Runtime, Code } from '@aws-cdk/aws-lambda'; -import { Construct, Resource, IResource, CustomResource, Duration, ITaggable, TagType, TagManager, Lazy } from '@aws-cdk/core'; +import { EcsApplication, IEcsApplication } from "aws-cdk-lib/aws-codedeploy"; +import { ApplicationTargetGroup } from "aws-cdk-lib/aws-elasticloadbalancingv2"; +import { + Role, + ServicePrincipal, + ManagedPolicy, + Effect, + PolicyStatement, +} from "aws-cdk-lib/aws-iam"; +import { Function, Runtime, Code } from "aws-cdk-lib/aws-lambda"; +import { + Resource, + IResource, + CustomResource, + Duration, + ITaggable, + TagType, + TagManager, + Lazy, +} from "aws-cdk-lib/core"; +import { Construct } from "constructs"; import { EcsDeploymentConfig, IEcsDeploymentConfig } from './ecs-deployment-config'; import { IEcsService } from './ecs-service'; diff --git a/packages/cdk-blue-green-container-deployment/src/ecs-service.ts b/packages/cdk-blue-green-container-deployment/src/ecs-service.ts index a8f9a8469..d03949989 100644 --- a/packages/cdk-blue-green-container-deployment/src/ecs-service.ts +++ b/packages/cdk-blue-green-container-deployment/src/ecs-service.ts @@ -1,10 +1,27 @@ import * as path from 'path'; -import { IConnectable, Connections, SecurityGroup, Port } from '@aws-cdk/aws-ec2'; -import { ICluster, LaunchType, DeploymentCircuitBreaker } from '@aws-cdk/aws-ecs'; -import { ITargetGroup } from '@aws-cdk/aws-elasticloadbalancingv2'; -import { Effect, PolicyStatement } from '@aws-cdk/aws-iam'; -import { Function, Runtime, Code } from '@aws-cdk/aws-lambda'; -import { Duration, Construct, CustomResource, ITaggable, TagManager, TagType, Lazy } from '@aws-cdk/core'; +import { + IConnectable, + Connections, + SecurityGroup, + Port, +} from "aws-cdk-lib/aws-ec2"; +import { + ICluster, + LaunchType, + DeploymentCircuitBreaker, +} from "aws-cdk-lib/aws-ecs"; +import { ITargetGroup } from "aws-cdk-lib/aws-elasticloadbalancingv2"; +import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam"; +import { Function, Runtime, Code } from "aws-cdk-lib/aws-lambda"; +import { + Duration, + CustomResource, + ITaggable, + TagManager, + TagType, + Lazy, +} from "aws-cdk-lib/core"; +import { Construct } from "constructs"; import { DummyTaskDefinition } from './dummy-task-definition'; diff --git a/packages/cdk-blue-green-container-deployment/src/push-image-project.ts b/packages/cdk-blue-green-container-deployment/src/push-image-project.ts index a50893eb9..ba1225fe2 100644 --- a/packages/cdk-blue-green-container-deployment/src/push-image-project.ts +++ b/packages/cdk-blue-green-container-deployment/src/push-image-project.ts @@ -7,10 +7,11 @@ import { ComputeType, BuildEnvironmentVariable, BuildEnvironmentVariableType, -} from '@aws-cdk/aws-codebuild'; -import { IRepository } from '@aws-cdk/aws-ecr'; -import { PolicyStatement } from '@aws-cdk/aws-iam'; -import { Construct, Stack } from '@aws-cdk/core'; +} from "aws-cdk-lib/aws-codebuild"; +import { IRepository } from "aws-cdk-lib/aws-ecr"; +import { PolicyStatement } from "aws-cdk-lib/aws-iam"; +import { Stack } from "aws-cdk-lib/core"; +import { Construct } from "constructs"; import { BuildSpecGenerator } from './build-spec-generator'; import { IDummyTaskDefinition } from './dummy-task-definition';