Skip to content

Commit

Permalink
feat: added possibility to define a single stackFactory (inMultiDeplo…
Browse files Browse the repository at this point in the history
…yCodePipelineProps) for all stages; A stackFactory at stage level always take precedence.
  • Loading branch information
wolfadr committed Jun 13, 2022
1 parent 3076164 commit cf9cd29
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
52 changes: 47 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

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*
[CodeArtifactFeature](#tts-cdk-build-pipelines-codeartifactfeature)|*No 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*
Expand Down Expand Up @@ -40,7 +41,7 @@ Name|Description

## class AdditionalTrigger <a id="tts-cdk-build-pipelines-additionaltrigger"></a>


Convenience class to create additional trigger {CodePipelineMixin}s for executing a CodePipeline if certain events occur other than a code change.


### Initializer
Expand All @@ -59,7 +60,7 @@ new AdditionalTrigger()

#### *static* schedule(schedule) <a id="tts-cdk-build-pipelines-additionaltrigger-schedule"></a>


Create an additional trigger {CodePipelineMixin} based on a schedule.

```ts
static schedule(schedule: Schedule): CodePipelineMixin
Expand All @@ -72,7 +73,7 @@ __Returns__:

#### *static* ssmParameterChange(...parameterNames) <a id="tts-cdk-build-pipelines-additionaltrigger-ssmparameterchange"></a>


Create an additional trigger {CodePipelineMixin} for a SSM parameter value change.

```ts
static ssmParameterChange(...parameterNames: string[]): CodePipelineMixin
Expand Down Expand Up @@ -346,6 +347,7 @@ new MultiDeployCodePipeline(scope: Construct, id: string, props: MultiDeployCode
* **synthCodeBuildDefaults** (<code>[pipelines.CodeBuildOptions](#aws-cdk-lib-pipelines-codebuildoptions)</code>) Additional customizations to apply to the synthesize CodeBuild projects. __*Default*__: Only `codeBuildDefaults` are applied
* **deploymentStages** (<code>Array<[DeploymentStage](#tts-cdk-build-pipelines-deploymentstage)></code>) *No description*
* **mixins** (<code>Array<[CodePipelineMixin](#tts-cdk-build-pipelines-codepipelinemixin)></code>) *No description* __*Optional*__
* **stackFactory** (<code>[IStackFactory](#tts-cdk-build-pipelines-istackfactory)</code>) *No description* __*Optional*__



Expand Down Expand Up @@ -374,6 +376,44 @@ protected doBuildPipeline(): void



## class NoopStackFactory <a id="tts-cdk-build-pipelines-noopstackfactory"></a>



__Implements__: [IStackFactory](#tts-cdk-build-pipelines-istackfactory)

### Initializer




```ts
new NoopStackFactory()
```



### Methods


#### create(scope, env) <a id="tts-cdk-build-pipelines-noopstackfactory-create"></a>



```ts
create(scope: Construct, env: Environment): Stack
```

* **scope** (<code>[Construct](#constructs-construct)</code>) *No description*
* **env** (<code>[Environment](#aws-cdk-lib-environment)</code>) *No description*
* **account** (<code>string</code>) The AWS account ID for this environment. __*Default*__: Aws.accountId which means that the stack will be account-agnostic.
* **region** (<code>string</code>) The AWS region for this environment. __*Default*__: Aws.region which means that the stack will be region-agnostic.

__Returns__:
* <code>[Stack](#aws-cdk-lib-stack)</code>



## class SSMParametersFeature <a id="tts-cdk-build-pipelines-ssmparametersfeature"></a>


Expand Down Expand Up @@ -531,9 +571,9 @@ Name | Type | Description
Name | Type | Description
-----|------|-------------
**name** | <code>string</code> | <span></span>
**stackFactory** | <code>[IStackFactory](#tts-cdk-build-pipelines-istackfactory)</code> | <span></span>
**targets** | <code>[IDeploymentTargetsProvider](#tts-cdk-build-pipelines-ideploymenttargetsprovider)</code> | <span></span>
**requireManualApproval**? | <code>boolean</code> | __*Optional*__
**stackFactory**? | <code>[IStackFactory](#tts-cdk-build-pipelines-istackfactory)</code> | __*Optional*__



Expand Down Expand Up @@ -576,6 +616,7 @@ __Returns__:

## interface IStackFactory <a id="tts-cdk-build-pipelines-istackfactory"></a>

__Implemented by__: [NoopStackFactory](#tts-cdk-build-pipelines-noopstackfactory)


### Methods
Expand Down Expand Up @@ -624,6 +665,7 @@ Name | Type | Description
**reuseCrossRegionSupportStacks**? | <code>boolean</code> | Reuse the same cross region support stack for all pipelines in the App.<br/>__*Default*__: true (Use the same support stack for all pipelines in App)
**selfMutation**? | <code>boolean</code> | Whether the pipeline will update itself.<br/>__*Default*__: true
**selfMutationCodeBuildDefaults**? | <code>[pipelines.CodeBuildOptions](#aws-cdk-lib-pipelines-codebuildoptions)</code> | Additional customizations to apply to the self mutation CodeBuild projects.<br/>__*Default*__: Only `codeBuildDefaults` are applied
**stackFactory**? | <code>[IStackFactory](#tts-cdk-build-pipelines-istackfactory)</code> | __*Optional*__
**synthCodeBuildDefaults**? | <code>[pipelines.CodeBuildOptions](#aws-cdk-lib-pipelines-codebuildoptions)</code> | Additional customizations to apply to the synthesize CodeBuild projects.<br/>__*Default*__: Only `codeBuildDefaults` are applied


Expand Down
8 changes: 6 additions & 2 deletions src/pipelines/multiDeploy/MultiDeployCodePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

Expand Down Expand Up @@ -53,14 +54,17 @@ 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}`, {
env: {
account: target.account,
region: target.region,
},
}, stage.stackFactory);
}, factory);

wave.addStage(appStage);
this.stacks.push(appStage.stack);
Expand Down
8 changes: 7 additions & 1 deletion src/pipelines/multiDeploy/deploymentTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit cf9cd29

Please sign in to comment.