@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.
package/src/segment.ts CHANGED
@@ -6,32 +6,32 @@ import { Artifact } from "./artifact";
6
6
  import { Pipeline } from "./pipeline";
7
7
 
8
8
  export interface SegmentProps {
9
- readonly input?: Artifact | Artifact[];
10
- readonly output?: Artifact | Artifact[];
9
+ readonly input?: Artifact | Artifact[];
10
+ readonly output?: Artifact | Artifact[];
11
11
  }
12
12
 
13
13
  export abstract class Segment {
14
- readonly isSource: boolean = false;
15
- readonly isPipeline: boolean = false;
16
- readonly dependencies?: Stack[];
17
- readonly inputs: Artifact[] = [];
18
- readonly outputs: Artifact[] = [];
19
- constructor(props: SegmentProps) {
20
- if (props.input) {
21
- this.inputs = Array.isArray(props.input) ? props.input : [props.input];
22
- this.inputs.forEach((artifact) => artifact.consume(this), this);
23
- }
24
- if (props.output) {
25
- this.outputs = Array.isArray(props.output)
26
- ? props.output
27
- : [props.output];
28
- this.outputs.forEach((artifact) => artifact.produce(this), this);
29
- }
30
- }
31
- abstract construct(scope: Pipeline): SegmentConstructed;
14
+ readonly isSource: boolean = false;
15
+ readonly isPipeline: boolean = false;
16
+ readonly dependencies?: Stack[];
17
+ readonly inputs: Artifact[] = [];
18
+ readonly outputs: Artifact[] = [];
19
+ constructor(props: SegmentProps) {
20
+ if (props.input) {
21
+ this.inputs = Array.isArray(props.input) ? props.input : [props.input];
22
+ this.inputs.forEach((artifact) => artifact.consume(this), this);
23
+ }
24
+ if (props.output) {
25
+ this.outputs = Array.isArray(props.output)
26
+ ? props.output
27
+ : [props.output];
28
+ this.outputs.forEach((artifact) => artifact.produce(this), this);
29
+ }
30
+ }
31
+ abstract construct(scope: Pipeline): SegmentConstructed;
32
32
  }
33
33
 
34
34
  export abstract class SegmentConstructed extends Construct {
35
- readonly name: string = "";
36
- readonly actions: IAction[] = [];
35
+ readonly name: string = "";
36
+ readonly actions: IAction[] = [];
37
37
  }
@@ -2,13 +2,13 @@ import { Artifact } from "./artifact";
2
2
  import { Segment } from "./segment";
3
3
 
4
4
  export interface SourceSegmentProps {
5
- readonly output: Artifact;
5
+ readonly output: Artifact;
6
6
  }
7
7
 
8
8
  export abstract class SourceSegment extends Segment {
9
- readonly isSource = true;
9
+ readonly isSource = true;
10
10
  }
11
11
 
12
12
  export function isSource(item: Segment): item is SourceSegment {
13
- return item.isSource;
13
+ return item.isSource;
14
14
  }
@@ -86,7 +86,7 @@ export class StackSegment extends Segment {
86
86
  construct(scope: Pipeline): SegmentConstructed {
87
87
  return new StackSegmentConstructed(
88
88
  scope,
89
- `Deploy${this.props.stack.stackName}`,
89
+ `Deploy${this.props.stack.node.id}`,
90
90
  {
91
91
  ...this.props,
92
92
  input: this.inputs[0],
@@ -120,7 +120,7 @@ export class StackSegmentConstructed extends SegmentConstructed {
120
120
  ) {
121
121
  super(scope, id);
122
122
 
123
- this.name = props.stack.stackName;
123
+ this.name = props.stack.node.id;
124
124
 
125
125
  const buildArtifact = props.project
126
126
  ? props.buildOutput || new Artifact()
@@ -130,67 +130,77 @@ export class StackSegmentConstructed extends SegmentConstructed {
130
130
  ...props.project,
131
131
  buildSpec: props.project?.buildSpec
132
132
  ? mergeBuildSpecs(
133
- props.project.buildSpec,
134
- BuildSpec.fromObject({
133
+ props.project.buildSpec,
134
+ BuildSpec.fromObject({
135
+ artifacts: {
136
+ files: [path.join(scope.buildDir, "**/*")],
137
+ },
138
+ }),
139
+ )
140
+ : BuildSpec.fromObject({
135
141
  artifacts: {
136
142
  files: [path.join(scope.buildDir, "**/*")],
137
143
  },
138
- }),
139
- )
140
- : BuildSpec.fromObject({
141
- artifacts: {
142
- files: [path.join(scope.buildDir, "**/*")],
143
- },
144
- }),
145
- })
144
+ }),
145
+ });
146
146
 
147
- Object.entries(props.project?.environment?.environmentVariables || []).forEach(([, v]) => {
147
+ Object.entries(
148
+ props.project?.environment?.environmentVariables || [],
149
+ ).forEach(([, v]) => {
148
150
  switch (v.type) {
149
151
  case BuildEnvironmentVariableType.PARAMETER_STORE:
150
- codeBuildProject.addToRolePolicy(new PolicyStatement({
151
- actions: [
152
- "ssm:GetParameter",
153
- "ssm:GetParameters",
154
- "ssm:GetParametersByPath",
155
- ],
156
- resources: [
157
- `arn:aws:ssm:*:${Stack.of(this).account}:parameter/${v.value}`
158
- ],
159
- }));
152
+ codeBuildProject.addToRolePolicy(
153
+ new PolicyStatement({
154
+ actions: [
155
+ "ssm:GetParameter",
156
+ "ssm:GetParameters",
157
+ "ssm:GetParametersByPath",
158
+ ],
159
+ resources: [
160
+ `arn:aws:ssm:*:${Stack.of(this).account}:parameter/${v.value}`,
161
+ ],
162
+ }),
163
+ );
160
164
  break;
161
165
  case BuildEnvironmentVariableType.SECRETS_MANAGER:
162
- codeBuildProject.addToRolePolicy(new PolicyStatement({
163
- actions: [
164
- "secretsmanager:GetSecretValue",
165
- "secretsmanager:DescribeSecret",
166
- ],
167
- resources: [(v.value as string).startsWith("arn:") ?
168
- v.value.split(":").slice(0, 7).join(":") :
169
- `arn:aws:secretsmanager:*:${Stack.of(this).account}:secret:${v.value}-*`],
170
- }));
166
+ codeBuildProject.addToRolePolicy(
167
+ new PolicyStatement({
168
+ actions: [
169
+ "secretsmanager:GetSecretValue",
170
+ "secretsmanager:DescribeSecret",
171
+ ],
172
+ resources: [
173
+ (v.value as string).startsWith("arn:")
174
+ ? v.value.split(":").slice(0, 7).join(":")
175
+ : `arn:aws:secretsmanager:*:${
176
+ Stack.of(this).account
177
+ }:secret:${v.value}-*`,
178
+ ],
179
+ }),
180
+ );
171
181
  break;
172
182
  }
173
- })
183
+ });
174
184
 
175
185
  this.actions = [
176
186
  ...(buildArtifact
177
187
  ? [
178
- new CodeBuildAction({
179
- actionName: `${this.name}Build`,
180
- runOrder: 1,
181
- input: props.input,
182
- extraInputs: props.extraInputs,
183
- outputs: [buildArtifact],
184
- environmentVariables: props.environmentVariables,
185
- project: codeBuildProject,
186
- }),
187
- new PublishAssetsAction(this, "PublishAssets", {
188
- actionName: `${this.name}PublishAssets`,
189
- runOrder: 2,
190
- input: buildArtifact,
191
- manifestPath: scope.buildDir,
192
- }),
193
- ]
188
+ new CodeBuildAction({
189
+ actionName: `${this.name}Build`,
190
+ runOrder: 1,
191
+ input: props.input,
192
+ extraInputs: props.extraInputs,
193
+ outputs: [buildArtifact],
194
+ environmentVariables: props.environmentVariables,
195
+ project: codeBuildProject,
196
+ }),
197
+ new PublishAssetsAction(this, "PublishAssets", {
198
+ actionName: `${this.name}PublishAssets`,
199
+ runOrder: 2,
200
+ input: buildArtifact,
201
+ manifestPath: scope.buildDir,
202
+ }),
203
+ ]
194
204
  : []),
195
205
  new CloudFormationCreateReplaceChangeSetAction({
196
206
  actionName: `${this.name}PrepareChanges`,
@@ -198,7 +208,7 @@ export class StackSegmentConstructed extends SegmentConstructed {
198
208
  stackName: props.stackName ? props.stackName : props.stack.stackName,
199
209
  account: props.stack.account,
200
210
  region: props.stack.region,
201
- changeSetName: `${props.stack.stackName}Changes`,
211
+ changeSetName: `${this.name}Changes`,
202
212
  adminPermissions: true,
203
213
  templatePath: (buildArtifact ? buildArtifact : props.input).atPath(
204
214
  path.join(scope.buildDir, props.stack.templateFile),
@@ -206,11 +216,11 @@ export class StackSegmentConstructed extends SegmentConstructed {
206
216
  }),
207
217
  ...(props.manualApproval
208
218
  ? [
209
- new ManualApprovalAction({
210
- actionName: `${this.name}ApproveChanges`,
211
- runOrder: buildArtifact ? 4 : 2,
212
- }),
213
- ]
219
+ new ManualApprovalAction({
220
+ actionName: `${this.name}ApproveChanges`,
221
+ runOrder: buildArtifact ? 4 : 2,
222
+ }),
223
+ ]
214
224
  : []),
215
225
  new CloudFormationExecuteChangeSetAction({
216
226
  actionName: `${this.name}ExecuteChanges`,
@@ -219,18 +229,18 @@ export class StackSegmentConstructed extends SegmentConstructed {
219
229
  ? 5
220
230
  : 3
221
231
  : buildArtifact
222
- ? 4
223
- : 2,
232
+ ? 4
233
+ : 2,
224
234
  stackName: props.stackName ? props.stackName : props.stack.stackName,
225
235
  account: props.stack.account,
226
236
  region: props.stack.region,
227
- changeSetName: `${props.stack.stackName}Changes`,
237
+ changeSetName: `${this.name}Changes`,
228
238
  output: props.stackOutput,
229
239
  outputFileName: props.outputFileName
230
240
  ? props.outputFileName
231
241
  : props.stackOutput
232
- ? "artifact.json"
233
- : undefined,
242
+ ? "artifact.json"
243
+ : undefined,
234
244
  }),
235
245
  ];
236
246
  }