Skip to content

Commit

Permalink
feat(pipelines): revised version of the API (#12326)
Browse files Browse the repository at this point in the history
Add a new, modernized API to the `pipelines` library.

Advantages of the new API are:

- Removes the need to interact with the underlying AWS CodePipeline library for `Artifacts` and `Sources`
- A streamlined API for sources (more sensible defaults allowing you to specify less)
- `Synth` classes hide less from you, allowing you more control and remove the need to decide whether or not to "eject" from the convenience classes of the original API
- Supports parallel deployments (speeding up large pipelines)
- Supports stages of >25 stacks
- Supports multiple sources powering the build
- Gives more control over the CodeBuild projects that get generated

In addition, by clearly separating out generic parts of the library from CodePipeline/CodeBuild-specific parts, allows easier development of construct libraries that target alternative deployment systems while reusing large parts of the logic of this library.

This does not remove or deprecate the old API, though starting today its use is discouraged in favor of the new API, which will see more development in the future.

Closes #10872.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Jul 15, 2021
1 parent 718d143 commit 165ee3a
Show file tree
Hide file tree
Showing 89 changed files with 12,363 additions and 3,156 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export class Pipeline extends PipelineBase {
}

/** @internal */
public _attachActionToPipeline(stage: Stage, action: IAction, actionScope: CoreConstruct): FullActionDescriptor {
public _attachActionToPipeline(stage: Stage, action: IAction, actionScope: Construct): FullActionDescriptor {
const richAction = new RichAction(action, this);

// handle cross-region actions here
Expand All @@ -491,8 +491,8 @@ export class Pipeline extends PipelineBase {
// // CodePipeline Variables
validateNamespaceName(richAction.actionProperties.variablesNamespace);

// bind the Action
const actionConfig = richAction.bind(actionScope, stage, {
// bind the Action (type h4x)
const actionConfig = richAction.bind(actionScope as CoreConstruct, stage, {
role: actionRole ? actionRole : this.role,
bucket: crossRegionInfo.artifactBucket,
});
Expand Down
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/lib/private/stage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as events from '@aws-cdk/aws-events';
import * as cdk from '@aws-cdk/core';
import { Construct, Node } from 'constructs';
import { IAction, IPipeline, IStage } from '../action';
import { Artifact } from '../artifact';
import { CfnPipeline } from '../codepipeline.generated';
Expand Down Expand Up @@ -137,7 +138,15 @@ export class Stage implements IStage {

private attachActionToPipeline(action: IAction): FullActionDescriptor {
// notify the Pipeline of the new Action
const actionScope = new cdk.Construct(this.scope, action.actionProperties.actionName);
//
// It may be that a construct already exists with the given action name (CDK Pipelines
// may do this to maintain construct tree compatibility between versions).
//
// If so, we simply reuse it.
let actionScope = Node.of(this.scope).tryFindChild(action.actionProperties.actionName) as Construct | undefined;
if (!actionScope) {
actionScope = new cdk.Construct(this.scope, action.actionProperties.actionName);
}
return this._pipeline._attachActionToPipeline(this, action, actionScope);
}

Expand Down
Loading

0 comments on commit 165ee3a

Please sign in to comment.