@flit/cdk-pipeline 1.5.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
1
  import {
2
- BuildEnvironmentVariable,
3
- BuildSpec,
4
- mergeBuildSpecs,
5
- Project,
6
- ProjectProps,
2
+ BuildEnvironmentVariable,
3
+ BuildSpec,
4
+ mergeBuildSpecs,
5
+ Project,
6
+ ProjectProps,
7
7
  } from "aws-cdk-lib/aws-codebuild";
8
8
  import { Stack } from "aws-cdk-lib";
9
9
  import { IAction } from "aws-cdk-lib/aws-codepipeline";
10
10
  import {
11
- CloudFormationCreateReplaceChangeSetAction,
12
- CloudFormationExecuteChangeSetAction,
13
- CodeBuildAction,
14
- ManualApprovalAction,
11
+ CloudFormationCreateReplaceChangeSetAction,
12
+ CloudFormationExecuteChangeSetAction,
13
+ CodeBuildAction,
14
+ ManualApprovalAction,
15
15
  } from "aws-cdk-lib/aws-codepipeline-actions";
16
16
  import * as path from "path";
17
17
 
@@ -21,154 +21,154 @@ import { Pipeline } from "./pipeline";
21
21
  import { PublishAssetsAction } from "./publish-assets-action";
22
22
 
23
23
  export interface PipelineSegmentProps {
24
- /**
25
- * The input arfifact for the build stage.
26
- */
27
- readonly input: Artifact | Artifact[];
28
- /**
29
- * The command(s) to build the stack.
30
- * @example "cdk synth StackName --strict --exclusively"
31
- */
32
- readonly project: ProjectProps;
33
- /**
34
- * The environmental variables for the build stage.
35
- */
36
- readonly environmentVariables?: { [key: string]: BuildEnvironmentVariable };
37
- /**
38
- * The name of the stack to apply this action to.
39
- * @default The name of the given stack.
40
- */
41
- readonly stackName?: string;
42
- /**
43
- * The artifact to hold the stack deployment output file.
44
- * @default no output artifact
45
- */
46
- readonly output?: Artifact;
47
- /**
48
- * The filename for the file in the output artifact
49
- * @default artifact.json
50
- */
51
- readonly outputFileName?: string;
52
- /**
53
- * Does this stage require manual approval of the change set?
54
- * @default false
55
- */
56
- readonly manualApproval?: Boolean;
24
+ /**
25
+ * The input arfifact for the build stage.
26
+ */
27
+ readonly input: Artifact | Artifact[];
28
+ /**
29
+ * The command(s) to build the stack.
30
+ * @example "cdk synth StackName --strict --exclusively"
31
+ */
32
+ readonly project: ProjectProps;
33
+ /**
34
+ * The environmental variables for the build stage.
35
+ */
36
+ readonly environmentVariables?: { [key: string]: BuildEnvironmentVariable };
37
+ /**
38
+ * The name of the stack to apply this action to.
39
+ * @default The name of the given stack.
40
+ */
41
+ readonly stackName?: string;
42
+ /**
43
+ * The artifact to hold the stack deployment output file.
44
+ * @default no output artifact
45
+ */
46
+ readonly output?: Artifact;
47
+ /**
48
+ * The filename for the file in the output artifact
49
+ * @default artifact.json
50
+ */
51
+ readonly outputFileName?: string;
52
+ /**
53
+ * Does this stage require manual approval of the change set?
54
+ * @default false
55
+ */
56
+ readonly manualApproval?: Boolean;
57
57
  }
58
58
 
59
59
  /**
60
60
  * @category Segments
61
61
  */
62
62
  export class PipelineSegment extends Segment {
63
- readonly isPipeline = true;
64
- readonly props: PipelineSegmentProps;
63
+ readonly isPipeline = true;
64
+ readonly props: PipelineSegmentProps;
65
65
 
66
- constructor(props: PipelineSegmentProps) {
67
- super(props);
68
- this.props = props;
69
- }
66
+ constructor(props: PipelineSegmentProps) {
67
+ super(props);
68
+ this.props = props;
69
+ }
70
70
 
71
- construct(scope: Pipeline): SegmentConstructed {
72
- return new PipelineSegmentConstructed(scope, `Deploy${scope.stackName}`, {
73
- ...this.props,
74
- stack: scope,
75
- input: this.inputs[0],
76
- extraInputs: this.inputs.slice(1),
77
- });
78
- }
71
+ construct(scope: Pipeline): SegmentConstructed {
72
+ return new PipelineSegmentConstructed(scope, `Deploy${scope.node.id}`, {
73
+ ...this.props,
74
+ stack: scope,
75
+ input: this.inputs[0],
76
+ extraInputs: this.inputs.slice(1),
77
+ });
78
+ }
79
79
  }
80
80
 
81
81
  export interface PipelineSegmentConstructedProps {
82
- readonly stack: Stack;
83
- readonly project: ProjectProps;
84
- readonly environmentVariables?: { [key: string]: BuildEnvironmentVariable };
85
- readonly stackName?: string;
86
- readonly input: Artifact;
87
- readonly extraInputs?: Artifact[];
88
- readonly output?: Artifact;
89
- readonly outputFileName?: string;
90
- readonly manualApproval?: Boolean;
82
+ readonly stack: Stack;
83
+ readonly project: ProjectProps;
84
+ readonly environmentVariables?: { [key: string]: BuildEnvironmentVariable };
85
+ readonly stackName?: string;
86
+ readonly input: Artifact;
87
+ readonly extraInputs?: Artifact[];
88
+ readonly output?: Artifact;
89
+ readonly outputFileName?: string;
90
+ readonly manualApproval?: Boolean;
91
91
  }
92
92
 
93
93
  export class PipelineSegmentConstructed extends SegmentConstructed {
94
- readonly name: string;
95
- readonly actions: IAction[];
94
+ readonly name: string;
95
+ readonly actions: IAction[];
96
96
 
97
- constructor(
98
- scope: Pipeline,
99
- id: string,
100
- props: PipelineSegmentConstructedProps,
101
- ) {
102
- super(scope, id);
97
+ constructor(
98
+ scope: Pipeline,
99
+ id: string,
100
+ props: PipelineSegmentConstructedProps,
101
+ ) {
102
+ super(scope, id);
103
103
 
104
- this.name = props.stack.stackName;
104
+ this.name = props.stack.stackName;
105
105
 
106
- const buildArtifact = props.output || new Artifact();
106
+ const buildArtifact = props.output || new Artifact();
107
107
 
108
- this.actions = [
109
- new CodeBuildAction({
110
- actionName: "Build",
111
- runOrder: 1,
112
- input: props.input,
113
- extraInputs: props.extraInputs,
114
- outputs: [buildArtifact],
115
- environmentVariables: props.environmentVariables,
116
- project: new Project(this, "UpdateCodeBuild", {
117
- ...props.project,
118
- buildSpec: props.project.buildSpec
119
- ? mergeBuildSpecs(
120
- props.project.buildSpec,
121
- BuildSpec.fromObject({
122
- artifacts: {
123
- files: [path.join(scope.buildDir, "**/*")],
124
- },
125
- }),
126
- )
127
- : BuildSpec.fromObject({
128
- artifacts: {
129
- files: [path.join(scope.buildDir, "**/*")],
130
- },
131
- }),
132
- }),
133
- }),
134
- new PublishAssetsAction(this, "PublishAssets", {
135
- actionName: "PublishAssets",
136
- runOrder: 2,
137
- input: buildArtifact,
138
- manifestPath: scope.buildDir,
139
- }),
140
- new CloudFormationCreateReplaceChangeSetAction({
141
- actionName: "PrepareChanges",
142
- runOrder: 3,
143
- stackName: props.stackName ? props.stackName : props.stack.stackName,
144
- account: props.stack.account,
145
- region: props.stack.region,
146
- changeSetName: `${props.stack.stackName}Changes`,
147
- adminPermissions: true,
148
- templatePath: buildArtifact.atPath(
149
- path.join(scope.buildDir, props.stack.templateFile),
150
- ),
151
- }),
152
- ...(props.manualApproval
153
- ? [
154
- new ManualApprovalAction({
155
- actionName: "ApproveChanges",
156
- runOrder: 4,
157
- }),
158
- ]
159
- : []),
160
- new CloudFormationExecuteChangeSetAction({
161
- actionName: "ExecuteChanges",
162
- runOrder: props.manualApproval ? 5 : 4,
163
- stackName: props.stackName ? props.stackName : props.stack.stackName,
164
- account: props.stack.account,
165
- region: props.stack.region,
166
- changeSetName: `${props.stack.stackName}Changes`,
167
- }),
168
- ];
169
- }
108
+ this.actions = [
109
+ new CodeBuildAction({
110
+ actionName: "Build",
111
+ runOrder: 1,
112
+ input: props.input,
113
+ extraInputs: props.extraInputs,
114
+ outputs: [buildArtifact],
115
+ environmentVariables: props.environmentVariables,
116
+ project: new Project(this, "UpdateCodeBuild", {
117
+ ...props.project,
118
+ buildSpec: props.project.buildSpec
119
+ ? mergeBuildSpecs(
120
+ props.project.buildSpec,
121
+ BuildSpec.fromObject({
122
+ artifacts: {
123
+ files: [path.join(scope.buildDir, "**/*")],
124
+ },
125
+ }),
126
+ )
127
+ : BuildSpec.fromObject({
128
+ artifacts: {
129
+ files: [path.join(scope.buildDir, "**/*")],
130
+ },
131
+ }),
132
+ }),
133
+ }),
134
+ new PublishAssetsAction(this, "PublishAssets", {
135
+ actionName: "PublishAssets",
136
+ runOrder: 2,
137
+ input: buildArtifact,
138
+ manifestPath: scope.buildDir,
139
+ }),
140
+ new CloudFormationCreateReplaceChangeSetAction({
141
+ actionName: "PrepareChanges",
142
+ runOrder: 3,
143
+ stackName: props.stackName ? props.stackName : props.stack.stackName,
144
+ account: props.stack.account,
145
+ region: props.stack.region,
146
+ changeSetName: `${this.name}Changes`,
147
+ adminPermissions: true,
148
+ templatePath: buildArtifact.atPath(
149
+ path.join(scope.buildDir, props.stack.templateFile),
150
+ ),
151
+ }),
152
+ ...(props.manualApproval
153
+ ? [
154
+ new ManualApprovalAction({
155
+ actionName: "ApproveChanges",
156
+ runOrder: 4,
157
+ }),
158
+ ]
159
+ : []),
160
+ new CloudFormationExecuteChangeSetAction({
161
+ actionName: "ExecuteChanges",
162
+ runOrder: props.manualApproval ? 5 : 4,
163
+ stackName: props.stackName ? props.stackName : props.stack.stackName,
164
+ account: props.stack.account,
165
+ region: props.stack.region,
166
+ changeSetName: `${this.name}Changes`,
167
+ }),
168
+ ];
169
+ }
170
170
  }
171
171
 
172
172
  export function isPipeline(item: Segment): item is PipelineSegment {
173
- return item.isPipeline;
173
+ return item.isPipeline;
174
174
  }
package/src/pipeline.ts CHANGED
@@ -73,7 +73,7 @@ export class Pipeline extends Stack {
73
73
  }
74
74
 
75
75
  if (
76
- segments[1].length === 1 &&
76
+ segments[1].length !== 1 ||
77
77
  segments[1].filter(isPipeline).length !== segments[1].length
78
78
  ) {
79
79
  throw new Error("Second segment must be the pipeline segment");
@@ -1,123 +1,123 @@
1
1
  import { Stack } from "aws-cdk-lib";
2
2
  import { Construct } from "constructs";
3
3
  import {
4
- ActionBindOptions,
5
- ActionConfig,
6
- ActionProperties,
7
- Artifact,
8
- IAction,
9
- IStage,
4
+ ActionBindOptions,
5
+ ActionConfig,
6
+ ActionProperties,
7
+ Artifact,
8
+ IAction,
9
+ IStage,
10
10
  } from "aws-cdk-lib/aws-codepipeline";
11
11
  import { BuildSpec, LinuxBuildImage, Project } from "aws-cdk-lib/aws-codebuild";
12
12
  import { CodeBuildAction } from "aws-cdk-lib/aws-codepipeline-actions";
13
13
  import {
14
- AccountPrincipal,
15
- CompositePrincipal,
16
- PolicyDocument,
17
- PolicyStatement,
18
- Role,
19
- ServicePrincipal,
14
+ AccountPrincipal,
15
+ CompositePrincipal,
16
+ PolicyDocument,
17
+ PolicyStatement,
18
+ Role,
19
+ ServicePrincipal,
20
20
  } from "aws-cdk-lib/aws-iam";
21
21
  import { IRuleTarget, RuleProps, Rule } from "aws-cdk-lib/aws-events";
22
22
  import * as path from "path";
23
23
 
24
24
  export interface PublishAssetsActionProps {
25
- readonly actionName: string;
26
- readonly input: Artifact;
27
- readonly manifestPath: string;
28
- readonly runOrder?: number;
25
+ readonly actionName: string;
26
+ readonly input: Artifact;
27
+ readonly manifestPath: string;
28
+ readonly runOrder?: number;
29
29
  }
30
30
 
31
31
  export class PublishAssetsAction extends Construct implements IAction {
32
- public readonly actionProperties: ActionProperties;
32
+ public readonly actionProperties: ActionProperties;
33
33
 
34
- bound(
35
- scope: Construct,
36
- stage: IStage,
37
- options: ActionBindOptions,
38
- ): ActionConfig {
39
- throw new Error(`Method not implemented.${!scope && !stage! && options}`);
40
- }
34
+ bound(
35
+ scope: Construct,
36
+ stage: IStage,
37
+ options: ActionBindOptions,
38
+ ): ActionConfig {
39
+ throw new Error(`Method not implemented.${!scope && !stage! && options}`);
40
+ }
41
41
 
42
- bind(
43
- scope: Construct,
44
- stage: IStage,
45
- options: ActionBindOptions,
46
- ): ActionConfig {
47
- throw new Error(`Method not implemented.${!scope && !stage! && options}`);
48
- }
42
+ bind(
43
+ scope: Construct,
44
+ stage: IStage,
45
+ options: ActionBindOptions,
46
+ ): ActionConfig {
47
+ throw new Error(`Method not implemented.${!scope && !stage! && options}`);
48
+ }
49
49
 
50
- onStateChange(
51
- name: string,
52
- target?: IRuleTarget | undefined,
53
- options?: RuleProps | undefined,
54
- ): Rule {
55
- throw new Error(`Method not implemented.${!name && !target! && options}`);
56
- }
50
+ onStateChange(
51
+ name: string,
52
+ target?: IRuleTarget | undefined,
53
+ options?: RuleProps | undefined,
54
+ ): Rule {
55
+ throw new Error(`Method not implemented.${!name && !target! && options}`);
56
+ }
57
57
 
58
- constructor(scope: Construct, id: string, props: PublishAssetsActionProps) {
59
- super(scope, id);
60
- const codeBuild = new CodeBuildAction({
61
- ...props,
62
- input: props.input,
63
- project: new Project(this, id, {
64
- environment: {
65
- buildImage: LinuxBuildImage.AMAZON_LINUX_2_5,
66
- },
67
- role: new Role(this, "UpdatePipelineCodeCuildRole", {
68
- assumedBy: new CompositePrincipal(
69
- new ServicePrincipal("codebuild.amazonaws.com"),
70
- new AccountPrincipal(Stack.of(this).account),
71
- ),
72
- inlinePolicies: {
73
- selfMutation: new PolicyDocument({
74
- statements: [
75
- new PolicyStatement({
76
- actions: ["sts:AssumeRole"],
77
- resources: [`arn:*:iam::${Stack.of(this).account}:role/*`],
78
- conditions: {
79
- "ForAnyValue:StringEquals": {
80
- "iam:ResourceTag/aws-cdk:bootstrap-role": [
81
- "image-publishing",
82
- "file-publishing",
83
- "deploy",
84
- ],
85
- },
86
- },
87
- }),
88
- ],
89
- }),
90
- },
91
- }),
92
- buildSpec: BuildSpec.fromObject({
93
- version: "0.2",
94
- phases: {
95
- install: {
96
- "runtime-versions": {
97
- nodejs: "latest",
98
- },
99
- commands: ["npm i -g @flit/publish-cdk-assets@latest"],
100
- },
101
- build: {
102
- commands: `pca ${
103
- props.manifestPath ? path.normalize(props.manifestPath) : "."
104
- }`,
105
- },
106
- },
107
- }),
108
- }),
109
- });
58
+ constructor(scope: Construct, id: string, props: PublishAssetsActionProps) {
59
+ super(scope, id);
60
+ const codeBuild = new CodeBuildAction({
61
+ ...props,
62
+ input: props.input,
63
+ project: new Project(this, id, {
64
+ environment: {
65
+ buildImage: LinuxBuildImage.AMAZON_LINUX_2_5,
66
+ },
67
+ role: new Role(this, "UpdatePipelineCodeCuildRole", {
68
+ assumedBy: new CompositePrincipal(
69
+ new ServicePrincipal("codebuild.amazonaws.com"),
70
+ new AccountPrincipal(Stack.of(this).account),
71
+ ),
72
+ inlinePolicies: {
73
+ selfMutation: new PolicyDocument({
74
+ statements: [
75
+ new PolicyStatement({
76
+ actions: ["sts:AssumeRole"],
77
+ resources: [`arn:*:iam::${Stack.of(this).account}:role/*`],
78
+ conditions: {
79
+ "ForAnyValue:StringEquals": {
80
+ "iam:ResourceTag/aws-cdk:bootstrap-role": [
81
+ "image-publishing",
82
+ "file-publishing",
83
+ "deploy",
84
+ ],
85
+ },
86
+ },
87
+ }),
88
+ ],
89
+ }),
90
+ },
91
+ }),
92
+ buildSpec: BuildSpec.fromObject({
93
+ version: "0.2",
94
+ phases: {
95
+ install: {
96
+ "runtime-versions": {
97
+ nodejs: "latest",
98
+ },
99
+ commands: ["npm i -g @flit/publish-cdk-assets@latest"],
100
+ },
101
+ build: {
102
+ commands: `pca ${
103
+ props.manifestPath ? path.normalize(props.manifestPath) : "."
104
+ }`,
105
+ },
106
+ },
107
+ }),
108
+ }),
109
+ });
110
110
 
111
- this.actionProperties = codeBuild.actionProperties;
112
- this.bind = (
113
- scope: Construct,
114
- stage: IStage,
115
- options: ActionBindOptions,
116
- ): ActionConfig => codeBuild.bind(scope, stage, options);
117
- this.onStateChange = (
118
- name: string,
119
- target?: IRuleTarget,
120
- options?: RuleProps,
121
- ): Rule => codeBuild.onStateChange(name, target, options);
122
- }
111
+ this.actionProperties = codeBuild.actionProperties;
112
+ this.bind = (
113
+ scope: Construct,
114
+ stage: IStage,
115
+ options: ActionBindOptions,
116
+ ): ActionConfig => codeBuild.bind(scope, stage, options);
117
+ this.onStateChange = (
118
+ name: string,
119
+ target?: IRuleTarget,
120
+ options?: RuleProps,
121
+ ): Rule => codeBuild.onStateChange(name, target, options);
122
+ }
123
123
  }
@@ -1,7 +1,7 @@
1
1
  import { IAction } from "aws-cdk-lib/aws-codepipeline";
2
2
  import {
3
- S3SourceAction,
4
- S3Trigger,
3
+ S3SourceAction,
4
+ S3Trigger,
5
5
  } from "aws-cdk-lib/aws-codepipeline-actions";
6
6
  import { SecretValue } from "aws-cdk-lib";
7
7
  import { IBucket } from "aws-cdk-lib/aws-s3";
@@ -12,51 +12,51 @@ import { SegmentConstructed } from "./segment";
12
12
  import { SourceSegment, SourceSegmentProps } from "./source-segment";
13
13
 
14
14
  export interface S3SourceSegmentProps extends SourceSegmentProps {
15
- readonly oauthToken: SecretValue;
16
- readonly bucket: IBucket;
17
- readonly bucketKey: string;
18
- readonly trigger?: S3Trigger;
19
- readonly variablesNamespace?: string;
15
+ readonly oauthToken: SecretValue;
16
+ readonly bucket: IBucket;
17
+ readonly bucketKey: string;
18
+ readonly trigger?: S3Trigger;
19
+ readonly variablesNamespace?: string;
20
20
  }
21
21
 
22
22
  /**
23
23
  * @category Segments
24
24
  */
25
25
  export class S3SourceSegment extends SourceSegment {
26
- private props: S3SourceSegmentProps;
27
- constructor(props: S3SourceSegmentProps) {
28
- super(props);
29
- this.props = props;
30
- }
31
- construct(scope: Pipeline): SegmentConstructed {
32
- const name = `${this.props.bucket}-${this.props.bucketKey}`;
26
+ private props: S3SourceSegmentProps;
27
+ constructor(props: S3SourceSegmentProps) {
28
+ super(props);
29
+ this.props = props;
30
+ }
31
+ construct(scope: Pipeline): SegmentConstructed {
32
+ const name = `${this.props.bucket}-${this.props.bucketKey}`;
33
33
 
34
- return new S3SourceSegmentConstructed(scope, name, {
35
- ...this.props,
36
- actionName: name,
37
- });
38
- }
34
+ return new S3SourceSegmentConstructed(scope, name, {
35
+ ...this.props,
36
+ actionName: name,
37
+ });
38
+ }
39
39
  }
40
40
 
41
41
  export interface S3SourceSegmentConstructedProps {
42
- readonly output: Artifact;
43
- readonly actionName: string;
44
- readonly bucket: IBucket;
45
- readonly bucketKey: string;
46
- readonly trigger?: S3Trigger;
47
- readonly variablesNamespace?: string;
42
+ readonly output: Artifact;
43
+ readonly actionName: string;
44
+ readonly bucket: IBucket;
45
+ readonly bucketKey: string;
46
+ readonly trigger?: S3Trigger;
47
+ readonly variablesNamespace?: string;
48
48
  }
49
49
 
50
50
  export class S3SourceSegmentConstructed extends SegmentConstructed {
51
- readonly name: string;
52
- readonly actions: IAction[];
53
- constructor(
54
- scope: Pipeline,
55
- id: string,
56
- props: S3SourceSegmentConstructedProps,
57
- ) {
58
- super(scope, id);
59
- this.name = "Source";
60
- this.actions = [new S3SourceAction(props)];
61
- }
51
+ readonly name: string;
52
+ readonly actions: IAction[];
53
+ constructor(
54
+ scope: Pipeline,
55
+ id: string,
56
+ props: S3SourceSegmentConstructedProps,
57
+ ) {
58
+ super(scope, id);
59
+ this.name = "Source";
60
+ this.actions = [new S3SourceAction(props)];
61
+ }
62
62
  }