@flit/cdk-pipeline 1.0.1 → 1.0.3
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/.jsii +5662 -0
- package/README.md +171 -5
- package/package.json +61 -18
- package/src/artifact.ts +24 -0
- package/{dist/index.d.ts → src/index.ts} +4 -3
- package/src/pipeline-segment.ts +68 -0
- package/src/pipeline.ts +94 -0
- package/src/publish-assets-action.ts +126 -0
- package/src/segment.ts +45 -0
- package/src/source-segment.ts +71 -0
- package/src/stack-segment.ts +195 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/artifact.d.ts +0 -8
- package/dist/artifact.js +0 -20
- package/dist/index.js +0 -23
- package/dist/pipeline-segment.d.ts +0 -18
- package/dist/pipeline-segment.js +0 -29
- package/dist/pipeline.d.ts +0 -10
- package/dist/pipeline.js +0 -43
- package/dist/publish-assets-action.d.ts +0 -16
- package/dist/publish-assets-action.js +0 -80
- package/dist/segment.d.ts +0 -21
- package/dist/segment.js +0 -28
- package/dist/source-segment.d.ts +0 -28
- package/dist/source-segment.js +0 -34
- package/dist/stack-segment.d.ts +0 -33
- package/dist/stack-segment.js +0 -114
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IAction } from "aws-cdk-lib/aws-codepipeline";
|
|
2
|
+
import {
|
|
3
|
+
GitHubSourceAction,
|
|
4
|
+
GitHubTrigger,
|
|
5
|
+
} from "aws-cdk-lib/aws-codepipeline-actions";
|
|
6
|
+
import { Pipeline } from "./pipeline";
|
|
7
|
+
import { SecretValue } from "aws-cdk-lib";
|
|
8
|
+
|
|
9
|
+
import { Artifact } from "./artifact";
|
|
10
|
+
import { Segment, SegmentConstructed } from "./segment";
|
|
11
|
+
|
|
12
|
+
export interface SourceSegmentProps {
|
|
13
|
+
readonly output: Artifact;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export abstract class SourceSegment extends Segment {
|
|
17
|
+
readonly isSource: boolean = true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GitHubSourceSegmentProps extends SourceSegmentProps {
|
|
21
|
+
readonly oauthToken: SecretValue;
|
|
22
|
+
readonly owner: string;
|
|
23
|
+
readonly repo: string;
|
|
24
|
+
readonly branch?: string;
|
|
25
|
+
readonly runOrder?: number;
|
|
26
|
+
readonly trigger?: GitHubTrigger;
|
|
27
|
+
readonly variablesNamespace?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @category Segments
|
|
32
|
+
*/
|
|
33
|
+
export class GitHubSourceSegment extends SourceSegment {
|
|
34
|
+
private props: GitHubSourceSegmentProps;
|
|
35
|
+
constructor(props: GitHubSourceSegmentProps) {
|
|
36
|
+
super(props);
|
|
37
|
+
this.props = props;
|
|
38
|
+
}
|
|
39
|
+
construct(scope: Pipeline): SegmentConstructed {
|
|
40
|
+
return new GitHubSourceSegmentConstructed(scope, this.props.repo, {
|
|
41
|
+
...this.props,
|
|
42
|
+
actionName: this.props.repo,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface GitHubSourceSegmentConstructedProps {
|
|
48
|
+
readonly output: Artifact;
|
|
49
|
+
readonly actionName: string;
|
|
50
|
+
readonly oauthToken: SecretValue;
|
|
51
|
+
readonly owner: string;
|
|
52
|
+
readonly repo: string;
|
|
53
|
+
readonly branch?: string;
|
|
54
|
+
readonly runOrder?: number;
|
|
55
|
+
readonly trigger?: GitHubTrigger;
|
|
56
|
+
readonly variablesNamespace?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class GitHubSourceSegmentConstructed extends SegmentConstructed {
|
|
60
|
+
readonly name: string;
|
|
61
|
+
readonly actions: IAction[];
|
|
62
|
+
constructor(
|
|
63
|
+
scope: Pipeline,
|
|
64
|
+
id: string,
|
|
65
|
+
props: GitHubSourceSegmentConstructedProps
|
|
66
|
+
) {
|
|
67
|
+
super(scope, id);
|
|
68
|
+
this.name = "Source";
|
|
69
|
+
this.actions = [new GitHubSourceAction(props)];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Stack } from "aws-cdk-lib";
|
|
2
|
+
import {
|
|
3
|
+
BuildEnvironmentVariable,
|
|
4
|
+
BuildSpec,
|
|
5
|
+
ComputeType,
|
|
6
|
+
LinuxBuildImage,
|
|
7
|
+
Project,
|
|
8
|
+
} from "aws-cdk-lib/aws-codebuild";
|
|
9
|
+
import { IAction } from "aws-cdk-lib/aws-codepipeline";
|
|
10
|
+
import {
|
|
11
|
+
CloudFormationCreateReplaceChangeSetAction,
|
|
12
|
+
CloudFormationExecuteChangeSetAction,
|
|
13
|
+
CodeBuildAction,
|
|
14
|
+
ManualApprovalAction,
|
|
15
|
+
} from "aws-cdk-lib/aws-codepipeline-actions";
|
|
16
|
+
import * as path from "path";
|
|
17
|
+
|
|
18
|
+
import { PublishAssetsAction } from "./publish-assets-action";
|
|
19
|
+
import { Artifact } from "./artifact";
|
|
20
|
+
import { Segment, SegmentConstructed } from "./segment";
|
|
21
|
+
import { Pipeline } from "./pipeline";
|
|
22
|
+
|
|
23
|
+
export interface StackSegmentProps {
|
|
24
|
+
/**
|
|
25
|
+
* The stack to be deployed in this segment.
|
|
26
|
+
*/
|
|
27
|
+
readonly stack: Stack;
|
|
28
|
+
/**
|
|
29
|
+
* The input arfifact for the build stage.
|
|
30
|
+
*/
|
|
31
|
+
readonly input: Artifact | Artifact[];
|
|
32
|
+
/**
|
|
33
|
+
* The command(s) to build the stack.
|
|
34
|
+
* @example "cdk synth StackName --strict --exclusively"
|
|
35
|
+
*/
|
|
36
|
+
readonly command: string | string[];
|
|
37
|
+
/**
|
|
38
|
+
* The environmental variables for the build stage.
|
|
39
|
+
*/
|
|
40
|
+
readonly environmentVariables?: { [key: string]: BuildEnvironmentVariable };
|
|
41
|
+
/**
|
|
42
|
+
* The name of the stack to deploy the changes to.
|
|
43
|
+
* @deafult The name of the given stack.
|
|
44
|
+
*/
|
|
45
|
+
readonly stackName?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The AWS account this Action is supposed to operate in.
|
|
48
|
+
*/
|
|
49
|
+
readonly account?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The AWS region the given Action resides in.
|
|
52
|
+
*/
|
|
53
|
+
readonly region?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The artifact to hold the stack deployment output file.
|
|
56
|
+
* @default no output artifact
|
|
57
|
+
*/
|
|
58
|
+
readonly output?: Artifact;
|
|
59
|
+
/**
|
|
60
|
+
* Does this stage require manual approval of the change set?
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
readonly manualApproval?: Boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @category Segments
|
|
68
|
+
*/
|
|
69
|
+
export class StackSegment extends Segment {
|
|
70
|
+
readonly props: StackSegmentProps;
|
|
71
|
+
|
|
72
|
+
constructor(props: StackSegmentProps) {
|
|
73
|
+
super(props);
|
|
74
|
+
this.props = props;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
construct(scope: Pipeline): SegmentConstructed {
|
|
78
|
+
return new StackSegmentConstructed(
|
|
79
|
+
scope,
|
|
80
|
+
`Deploy${this.props.stack.stackName}`,
|
|
81
|
+
{
|
|
82
|
+
...this.props,
|
|
83
|
+
input: this.inputs[0],
|
|
84
|
+
extraInputs: this.inputs.slice(1),
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface StackSegmentConstructedProps {
|
|
91
|
+
readonly stack: Stack;
|
|
92
|
+
readonly command: string | string[];
|
|
93
|
+
readonly environmentVariables?: { [key: string]: BuildEnvironmentVariable };
|
|
94
|
+
readonly stackName?: string;
|
|
95
|
+
readonly account?: string;
|
|
96
|
+
readonly region?: string;
|
|
97
|
+
readonly input: Artifact;
|
|
98
|
+
readonly extraInputs?: Artifact[];
|
|
99
|
+
readonly output?: Artifact;
|
|
100
|
+
readonly manualApproval?: Boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class StackSegmentConstructed extends SegmentConstructed {
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly actions: IAction[];
|
|
106
|
+
|
|
107
|
+
constructor(
|
|
108
|
+
scope: Pipeline,
|
|
109
|
+
id: string,
|
|
110
|
+
props: StackSegmentConstructedProps
|
|
111
|
+
) {
|
|
112
|
+
super(scope, id);
|
|
113
|
+
|
|
114
|
+
this.name = props.stack.stackName;
|
|
115
|
+
|
|
116
|
+
const buildArtifact = new Artifact();
|
|
117
|
+
|
|
118
|
+
this.actions = [
|
|
119
|
+
new CodeBuildAction({
|
|
120
|
+
actionName: "Build",
|
|
121
|
+
runOrder: 1,
|
|
122
|
+
input: props.input,
|
|
123
|
+
extraInputs: props.extraInputs,
|
|
124
|
+
outputs: [buildArtifact],
|
|
125
|
+
environmentVariables: props.environmentVariables,
|
|
126
|
+
project: new Project(this, "UpdateCodeBuild", {
|
|
127
|
+
environment: {
|
|
128
|
+
computeType: ComputeType.MEDIUM,
|
|
129
|
+
buildImage: LinuxBuildImage.AMAZON_LINUX_2_4,
|
|
130
|
+
privileged: true,
|
|
131
|
+
},
|
|
132
|
+
buildSpec: BuildSpec.fromObject({
|
|
133
|
+
version: "0.2",
|
|
134
|
+
phases: {
|
|
135
|
+
install: {
|
|
136
|
+
"runtime-versions": {
|
|
137
|
+
docker: 20,
|
|
138
|
+
nodejs: 18,
|
|
139
|
+
},
|
|
140
|
+
commands: ["npm ci"],
|
|
141
|
+
},
|
|
142
|
+
build: {
|
|
143
|
+
commands: props.command,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
artifacts: {
|
|
147
|
+
files: [path.join(scope.buildDir, "**/*")],
|
|
148
|
+
},
|
|
149
|
+
cache: {
|
|
150
|
+
paths: ["/root/.npm/**/*"],
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
}),
|
|
154
|
+
}),
|
|
155
|
+
new PublishAssetsAction(this, "PublishAssets", {
|
|
156
|
+
actionName: "PublishAssets",
|
|
157
|
+
runOrder: 2,
|
|
158
|
+
input: buildArtifact,
|
|
159
|
+
manifestPath: scope.buildDir,
|
|
160
|
+
}),
|
|
161
|
+
new CloudFormationCreateReplaceChangeSetAction({
|
|
162
|
+
actionName: "PrepareChanges",
|
|
163
|
+
runOrder: 3,
|
|
164
|
+
stackName: props.stackName ? props.stackName : props.stack.stackName,
|
|
165
|
+
account: props.account,
|
|
166
|
+
region: props.region,
|
|
167
|
+
changeSetName: `${props.stack.stackName}Changes`,
|
|
168
|
+
adminPermissions: true,
|
|
169
|
+
templatePath: buildArtifact.atPath(
|
|
170
|
+
path.join(scope.buildDir, props.stack.templateFile)
|
|
171
|
+
),
|
|
172
|
+
}),
|
|
173
|
+
...(props.manualApproval
|
|
174
|
+
? [
|
|
175
|
+
new ManualApprovalAction({
|
|
176
|
+
actionName: "ApproveChanges",
|
|
177
|
+
runOrder: 4,
|
|
178
|
+
}),
|
|
179
|
+
]
|
|
180
|
+
: []),
|
|
181
|
+
new CloudFormationExecuteChangeSetAction({
|
|
182
|
+
actionName: "ExecuteChanges",
|
|
183
|
+
runOrder: props.manualApproval ? 5 : 4,
|
|
184
|
+
stackName: props.stackName ? props.stackName : props.stack.stackName,
|
|
185
|
+
account: props.account,
|
|
186
|
+
region: props.region,
|
|
187
|
+
changeSetName: `${props.stack.stackName}Changes`,
|
|
188
|
+
output: props.output,
|
|
189
|
+
outputFileName: props.output
|
|
190
|
+
? `${props.stack.stackName}Output.json`
|
|
191
|
+
: undefined,
|
|
192
|
+
}),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
}
|