From cf9cd2985c506f7671d1f1911a867f84f8c81a94 Mon Sep 17 00:00:00 2001 From: WolfAn Date: Mon, 13 Jun 2022 17:22:36 +0200 Subject: [PATCH] feat: added possibility to define a single stackFactory (inMultiDeployCodePipelineProps) for all stages; A stackFactory at stage level always take precedence. --- API.md | 52 +++++++++++++++++-- .../multiDeploy/MultiDeployCodePipeline.ts | 8 ++- .../multiDeploy/deploymentTargets.ts | 8 ++- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/API.md b/API.md index e3345b1..dfca07b 100644 --- a/API.md +++ b/API.md @@ -4,7 +4,7 @@ Name|Description ----|----------- -[AdditionalTrigger](#tts-cdk-build-pipelines-additionaltrigger)|*No description* +[AdditionalTrigger](#tts-cdk-build-pipelines-additionaltrigger)|Convenience class to create additional trigger {CodePipelineMixin}s for executing a CodePipeline if certain events occur other than a code change. [BuildProjectFeature](#tts-cdk-build-pipelines-buildprojectfeature)|*No description* [BuildSpecPipeline](#tts-cdk-build-pipelines-buildspecpipeline)|*No description* [CleanupStacksMixin](#tts-cdk-build-pipelines-cleanupstacksmixin)|*No description* @@ -12,6 +12,7 @@ Name|Description [CodePipelineMixin](#tts-cdk-build-pipelines-codepipelinemixin)|*No description* [DeploymentTargetsSource](#tts-cdk-build-pipelines-deploymenttargetssource)|*No description* [MultiDeployCodePipeline](#tts-cdk-build-pipelines-multideploycodepipeline)|*No description* +[NoopStackFactory](#tts-cdk-build-pipelines-noopstackfactory)|*No description* [SSMParametersFeature](#tts-cdk-build-pipelines-ssmparametersfeature)|*No description* [StackFactoryApplicationStage](#tts-cdk-build-pipelines-stackfactoryapplicationstage)|*No description* [SynthCommands](#tts-cdk-build-pipelines-synthcommands)|*No description* @@ -40,7 +41,7 @@ Name|Description ## class AdditionalTrigger - +Convenience class to create additional trigger {CodePipelineMixin}s for executing a CodePipeline if certain events occur other than a code change. ### Initializer @@ -59,7 +60,7 @@ new AdditionalTrigger() #### *static* schedule(schedule) - +Create an additional trigger {CodePipelineMixin} based on a schedule. ```ts static schedule(schedule: Schedule): CodePipelineMixin @@ -72,7 +73,7 @@ __Returns__: #### *static* ssmParameterChange(...parameterNames) - +Create an additional trigger {CodePipelineMixin} for a SSM parameter value change. ```ts static ssmParameterChange(...parameterNames: string[]): CodePipelineMixin @@ -346,6 +347,7 @@ new MultiDeployCodePipeline(scope: Construct, id: string, props: MultiDeployCode * **synthCodeBuildDefaults** ([pipelines.CodeBuildOptions](#aws-cdk-lib-pipelines-codebuildoptions)) Additional customizations to apply to the synthesize CodeBuild projects. __*Default*__: Only `codeBuildDefaults` are applied * **deploymentStages** (Array<[DeploymentStage](#tts-cdk-build-pipelines-deploymentstage)>) *No description* * **mixins** (Array<[CodePipelineMixin](#tts-cdk-build-pipelines-codepipelinemixin)>) *No description* __*Optional*__ + * **stackFactory** ([IStackFactory](#tts-cdk-build-pipelines-istackfactory)) *No description* __*Optional*__ @@ -374,6 +376,44 @@ protected doBuildPipeline(): void +## class NoopStackFactory + + + +__Implements__: [IStackFactory](#tts-cdk-build-pipelines-istackfactory) + +### Initializer + + + + +```ts +new NoopStackFactory() +``` + + + +### Methods + + +#### create(scope, env) + + + +```ts +create(scope: Construct, env: Environment): Stack +``` + +* **scope** ([Construct](#constructs-construct)) *No description* +* **env** ([Environment](#aws-cdk-lib-environment)) *No description* + * **account** (string) The AWS account ID for this environment. __*Default*__: Aws.accountId which means that the stack will be account-agnostic. + * **region** (string) The AWS region for this environment. __*Default*__: Aws.region which means that the stack will be region-agnostic. + +__Returns__: +* [Stack](#aws-cdk-lib-stack) + + + ## class SSMParametersFeature @@ -531,9 +571,9 @@ Name | Type | Description Name | Type | Description -----|------|------------- **name** | string | -**stackFactory** | [IStackFactory](#tts-cdk-build-pipelines-istackfactory) | **targets** | [IDeploymentTargetsProvider](#tts-cdk-build-pipelines-ideploymenttargetsprovider) | **requireManualApproval**? | boolean | __*Optional*__ +**stackFactory**? | [IStackFactory](#tts-cdk-build-pipelines-istackfactory) | __*Optional*__ @@ -576,6 +616,7 @@ __Returns__: ## interface IStackFactory +__Implemented by__: [NoopStackFactory](#tts-cdk-build-pipelines-noopstackfactory) ### Methods @@ -624,6 +665,7 @@ Name | Type | Description **reuseCrossRegionSupportStacks**? | boolean | Reuse the same cross region support stack for all pipelines in the App.
__*Default*__: true (Use the same support stack for all pipelines in App) **selfMutation**? | boolean | Whether the pipeline will update itself.
__*Default*__: true **selfMutationCodeBuildDefaults**? | [pipelines.CodeBuildOptions](#aws-cdk-lib-pipelines-codebuildoptions) | Additional customizations to apply to the self mutation CodeBuild projects.
__*Default*__: Only `codeBuildDefaults` are applied +**stackFactory**? | [IStackFactory](#tts-cdk-build-pipelines-istackfactory) | __*Optional*__ **synthCodeBuildDefaults**? | [pipelines.CodeBuildOptions](#aws-cdk-lib-pipelines-codebuildoptions) | Additional customizations to apply to the synthesize CodeBuild projects.
__*Default*__: Only `codeBuildDefaults` are applied diff --git a/src/pipelines/multiDeploy/MultiDeployCodePipeline.ts b/src/pipelines/multiDeploy/MultiDeployCodePipeline.ts index 4dd01c6..79f2123 100755 --- a/src/pipelines/multiDeploy/MultiDeployCodePipeline.ts +++ b/src/pipelines/multiDeploy/MultiDeployCodePipeline.ts @@ -2,10 +2,11 @@ import { Stack, Stage, StageProps } from 'aws-cdk-lib'; import { CodePipeline, CodePipelineProps, ManualApprovalStep } from 'aws-cdk-lib/pipelines'; import { Construct } from 'constructs'; import { CodePipelineMixin } from '../../mixins'; -import { DeploymentStage, IStackFactory } from './deploymentTargets'; +import { DeploymentStage, IStackFactory, NoopStackFactory } from './deploymentTargets'; export interface MultiDeployCodePipelineProps extends CodePipelineProps { readonly deploymentStages: DeploymentStage[]; + readonly stackFactory?: IStackFactory; readonly mixins?: CodePipelineMixin[]; } @@ -53,6 +54,9 @@ export class MultiDeployCodePipeline extends CodePipeline { pre: stage.requireManualApproval ? [new ManualApprovalStep('Approve')] : [], }); + const factory = stage.stackFactory ? stage.stackFactory : + (this.mdcProps.stackFactory ? this.mdcProps.stackFactory : new NoopStackFactory()); + targets.forEach(target => { const appStage = new StackFactoryApplicationStage(this, `a${target.account}-${target.region}`, { @@ -60,7 +64,7 @@ export class MultiDeployCodePipeline extends CodePipeline { account: target.account, region: target.region, }, - }, stage.stackFactory); + }, factory); wave.addStage(appStage); this.stacks.push(appStage.stack); diff --git a/src/pipelines/multiDeploy/deploymentTargets.ts b/src/pipelines/multiDeploy/deploymentTargets.ts index 27cab50..1fdefba 100755 --- a/src/pipelines/multiDeploy/deploymentTargets.ts +++ b/src/pipelines/multiDeploy/deploymentTargets.ts @@ -15,10 +15,16 @@ export interface IStackFactory { create(scope: Construct, env: Environment): Stack; } +export class NoopStackFactory implements IStackFactory { + create(scope: Construct, env: Environment): Stack { + return new Stack(scope, 'noop-stack', { env }); + } +} + export interface DeploymentStage { readonly name: string; readonly targets: IDeploymentTargetsProvider; - readonly stackFactory: IStackFactory; + readonly stackFactory?: IStackFactory; readonly requireManualApproval?: boolean; }