@aws-blocks/core 0.1.2 → 0.1.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.
@@ -1,384 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type * as cdk from 'aws-cdk-lib';
5
- import type * as codebuild from 'aws-cdk-lib/aws-codebuild';
6
-
7
- /**
8
- * Configuration for the pipeline source (GitHub/CodeConnections).
9
- *
10
- * Uses AWS CodeConnections (formerly CodeStar Connections) for OAuth-based
11
- * access to GitHub repositories. No token management required — the
12
- * connection is created once via the AWS Console.
13
- */
14
- export interface PipelineSourceConfig {
15
- /**
16
- * Repository in `owner/repo` format.
17
- *
18
- * @example 'my-org/my-app'
19
- */
20
- readonly repo: string;
21
-
22
- /**
23
- * ARN of the AWS CodeConnections connection.
24
- *
25
- * **Important:** This connection requires a one-time OAuth handshake via the
26
- * AWS Console before it can be used. After creating the connection resource
27
- * (via CDK, CLI, or Console), you must complete the OAuth flow in the
28
- * Console under **Developer Tools → Connections** — the connection will be
29
- * in `PENDING` status until authorized.
30
- *
31
- * Steps:
32
- * 1. Create the connection (Console or CLI)
33
- * 2. Navigate to **Developer Tools → Connections** in the AWS Console
34
- * 3. Select the pending connection and click "Update pending connection"
35
- * 4. Authorize the GitHub app and select your repository/organization
36
- * 5. The status changes to `AVAILABLE` — the pipeline can now pull source
37
- *
38
- * @see https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create-github.html
39
- *
40
- * @example 'arn:aws:codeconnections:us-east-1:123456789:connection/abc-def'
41
- */
42
- readonly connectionArn: string;
43
-
44
- /**
45
- * Whether to trigger the pipeline on push to the branch.
46
- *
47
- * @default true
48
- */
49
- readonly triggerOnPush?: boolean;
50
-
51
- /**
52
- * Path-based trigger filters for monorepo support.
53
- *
54
- * When specified, the pipeline only triggers on pushes that modify files
55
- * matching these path patterns. Useful for monorepos where multiple
56
- * pipelines share a single repository.
57
- *
58
- * @example ['packages/backend/**', 'shared/**']
59
- */
60
- readonly triggerFilters?: string[];
61
- }
62
-
63
- /**
64
- * Configuration for the synth step (build + CDK synth).
65
- *
66
- * The synth step installs dependencies and runs `cdk synth` to produce
67
- * the CloudFormation template. The pipeline is self-mutating: if the
68
- * synth output changes the pipeline definition, it updates itself first.
69
- */
70
- export interface PipelineSynthConfig {
71
- /**
72
- * Shell commands to run during the synth step.
73
- *
74
- * @default ['npm ci', 'npx cdk synth'] — installs dependencies and synthesizes the CDK app.
75
- * Override if you need Node version upgrades, custom build steps, or a non-standard cdk.json app path.
76
- * If your app requires Node 22+, prepend `'n 22'` to commands or use {@link installCommands}.
77
- */
78
- readonly commands?: string[];
79
-
80
- /**
81
- * Commands to run in the CodeBuild install phase (before synth commands).
82
- *
83
- * @default [] — no install commands. The default build image (Amazon Linux 2023 standard:5.0)
84
- * includes Node 22. Set this if you need additional global tools or a different Node version.
85
- *
86
- * @example ['n 20'] — downgrade Node to version 20
87
- */
88
- readonly installCommands?: string[];
89
-
90
- /**
91
- * The CodeBuild build image to use for the synth step.
92
- *
93
- * The default image (Amazon Linux 2023 standard:5.0) includes Node 22 and
94
- * Amazon Linux 2023. Override this if you need a different OS or runtime set.
95
- *
96
- * @default codebuild.LinuxBuildImage.AMAZON_LINUX_2023_5
97
- */
98
- readonly buildImage?: codebuild.IBuildImage;
99
-
100
- /**
101
- * Environment variables available during synth.
102
- *
103
- * Note: `NODE_OPTIONS` is automatically prepended with `--conditions=cdk`
104
- * (required for ESM conditional exports). Your custom NODE_OPTIONS will be
105
- * appended after this flag.
106
- */
107
- readonly env?: Record<string, string>;
108
-
109
- /**
110
- * Primary output directory for the CDK cloud assembly.
111
- *
112
- * Override this for monorepos where `cdk synth` outputs to a
113
- * subdirectory (e.g., `packages/infra/cdk.out`).
114
- *
115
- * @default 'cdk.out'
116
- */
117
- readonly primaryOutputDirectory?: string;
118
-
119
- /**
120
- * Whether to enable Docker for the synth step.
121
- *
122
- * Required when your CDK app uses Docker image assets (e.g., Lambda
123
- * container images, ECS task definitions with Dockerfile builds).
124
- *
125
- * @default false
126
- */
127
- readonly dockerEnabled?: boolean;
128
-
129
- /**
130
- * CodeBuild compute type for the synth step.
131
- *
132
- * Controls the CPU/memory allocation for the build environment.
133
- * Increase this if you encounter OOM (exit code 137) during synth/bundling.
134
- *
135
- * - `SMALL`: 2 vCPU, 3 GB
136
- * - `MEDIUM`: 4 vCPU, 7 GB
137
- * - `LARGE`: 8 vCPU, 15 GB
138
- *
139
- * @default ComputeType.MEDIUM (7GB RAM, 4 vCPU) — sufficient for most apps with
140
- * Lambda bundling + frontend builds. Use SMALL for trivial apps or LARGE for monorepos.
141
- */
142
- readonly computeType?: codebuild.ComputeType;
143
- }
144
-
145
- /**
146
- * Configuration for a deployment stage.
147
- *
148
- * Each stage represents a deployment environment (e.g., beta, prod).
149
- * Stages are deployed in the order they appear in the `stages` array.
150
- */
151
- export interface PipelineStageConfig<TConfig = Record<string, unknown>> {
152
- /**
153
- * Logical name for this stage (e.g., 'beta', 'prod').
154
- * Used as the CDK Stage construct id.
155
- */
156
- readonly name: string;
157
-
158
- /**
159
- * Target AWS account and region for this stage.
160
- * When omitted, deploys to the pipeline's own account/region.
161
- */
162
- readonly env?: cdk.Environment;
163
-
164
- /**
165
- * Whether to require manual approval before deploying to this stage.
166
- *
167
- * @default false
168
- */
169
- readonly requireApproval?: boolean;
170
-
171
- /**
172
- * Optional comment shown in the approval notification.
173
- * Only relevant when `requireApproval` is true.
174
- */
175
- readonly approvalComment?: string;
176
-
177
- /**
178
- * Optional baking time after deployment before proceeding.
179
- * Useful for canary validation — gives time for alarms to fire.
180
- *
181
- * Implemented as a CodeBuild `sleep` step (~$0.005/min on
182
- * `BUILD_GENERAL1_SMALL`). An explicit timeout of bakeTime + 10 minutes
183
- * is set on the CodeBuild step to prevent pipeline hangs.
184
- *
185
- * For longer baking periods, use `requireApproval: true` with
186
- * external monitoring/alerting instead.
187
- */
188
- readonly bakeTime?: cdk.Duration;
189
-
190
- /**
191
- * User-defined configuration passed through to the `stageFactory`.
192
- *
193
- * Use this for per-stage settings like domain names, feature flags,
194
- * scaling parameters, etc.
195
- *
196
- * @example { domain: 'myapp.com', enableCanary: true }
197
- */
198
- readonly config?: TConfig;
199
-
200
- /**
201
- * Environment variables to set on `process.env` when importing the app file for this stage.
202
- *
203
- * These are synthesis-time variables (available during `cdk synth`), not deployment-time.
204
- * Use this for per-stage configuration that your CDK app reads from `process.env`
205
- * (e.g., domain names, feature flags). Only applies when using the `appFile` prop.
206
- *
207
- * @example { DOMAIN: 'myapp.com', ENABLE_CANARY: 'true' }
208
- */
209
- readonly environment?: Record<string, string>;
210
- }
211
-
212
- /**
213
- * Configuration for a single branch pipeline.
214
- *
215
- * Each branch entry creates its own independent CodePipeline that triggers
216
- * on pushes to the specified branch and deploys through its own ordered stages.
217
- */
218
- export interface BranchConfig<TConfig = Record<string, unknown>> {
219
- /**
220
- * Git branch that triggers this pipeline.
221
- *
222
- * @example 'main'
223
- */
224
- readonly branch: string;
225
-
226
- /**
227
- * Ordered list of deployment stages for this branch's pipeline.
228
- */
229
- readonly stages: Array<PipelineStageConfig<TConfig>>;
230
-
231
- /**
232
- * Whether to trigger this branch's pipeline on push.
233
- *
234
- * Overrides the top-level `source.triggerOnPush` for this specific branch.
235
- * Useful when you want most branches to auto-trigger but disable it for
236
- * specific branches (e.g., a release branch that deploys on manual trigger only).
237
- *
238
- * @default inherits from source.triggerOnPush (which defaults to true)
239
- */
240
- readonly triggerOnPush?: boolean;
241
- }
242
-
243
- /**
244
- * Props for the {@link Pipeline} L3 construct.
245
- *
246
- * @example Multi-branch configuration
247
- * ```ts
248
- * new Pipeline(stack, 'Pipeline', {
249
- * source: {
250
- * repo: 'my-org/my-app',
251
- * connectionArn: 'arn:aws:codeconnections:us-east-1:123456789:connection/abc',
252
- * },
253
- * branches: [
254
- * {
255
- * branch: 'main',
256
- * stages: [
257
- * { name: 'beta' },
258
- * { name: 'prod', requireApproval: true, config: { domain: 'myapp.com' } },
259
- * ],
260
- * },
261
- * {
262
- * branch: 'develop',
263
- * stages: [
264
- * { name: 'alpha', config: { domain: 'alpha.myapp.com' } },
265
- * ],
266
- * },
267
- * ],
268
- * stageFactory: (scope, stageConfig) => {
269
- * new MyAppStack(scope, 'App', {
270
- * stackName: `my-app-${stageConfig.name}`,
271
- * env: stageConfig.env,
272
- * });
273
- * },
274
- * });
275
- * ```
276
- *
277
- * @example With custom synth and bake time
278
- * ```ts
279
- * new Pipeline(stack, 'Pipeline', {
280
- * source: {
281
- * repo: 'my-org/my-app',
282
- * connectionArn: 'arn:aws:codeconnections:...',
283
- * },
284
- * branches: [
285
- * {
286
- * branch: 'release',
287
- * stages: [
288
- * { name: 'beta' },
289
- * { name: 'prod', requireApproval: true, bakeTime: Duration.minutes(30) },
290
- * ],
291
- * },
292
- * ],
293
- * synth: {
294
- * commands: ['npm ci', 'npm run build', 'npx cdk synth'],
295
- * },
296
- * stageFactory: (scope, stageConfig) => {
297
- * new MyAppStack(scope, 'App', { env: stageConfig.env });
298
- * },
299
- * });
300
- * ```
301
- */
302
- export interface PipelineProps<TConfig = Record<string, unknown>> {
303
- /** Source repository configuration. */
304
- readonly source: PipelineSourceConfig;
305
-
306
- /** Synth step configuration. */
307
- readonly synth?: PipelineSynthConfig;
308
-
309
- /**
310
- * Branch configurations. Each entry creates a separate CodePipeline.
311
- *
312
- * A single source repository can have multiple branch pipelines, each
313
- * with its own set of deployment stages and configuration.
314
- */
315
- readonly branches: Array<BranchConfig<TConfig>>;
316
-
317
- /**
318
- * Factory function that populates a CDK Stage with stacks.
319
- *
320
- * Called once per stage across all branches. The factory receives the Stage
321
- * scope and the full stage configuration object (including `name`, `env`,
322
- * and any user-defined `config`).
323
- *
324
- * May be async when using constructs that require async initialization
325
- * (e.g., `BlocksStack.create()`). When async, use `Pipeline.create()` instead
326
- * of `new Pipeline()` to ensure all stages are fully resolved before synth.
327
- *
328
- * Mutually exclusive with `appFile`. One of `stageFactory` or `appFile` must be provided
329
- * for the sync constructor (`new Pipeline()`). When using `Pipeline.create()`, if neither
330
- * is provided, `appFile` defaults to `'./index.cdk.ts'`.
331
- *
332
- * @param scope - The CDK Stage construct to add stacks to.
333
- * @param stageConfig - The full stage configuration including name, env, and user-defined config.
334
- */
335
- readonly stageFactory?: (
336
- scope: cdk.Stage,
337
- stageConfig: PipelineStageConfig<TConfig>,
338
- ) => void | Promise<void>;
339
-
340
- /**
341
- * Path to the CDK app file to import for each stage.
342
- *
343
- * When provided, the pipeline will dynamically import this file once per stage,
344
- * with the ambient `__PIPELINE_STAGE_SCOPE__` set on globalThis so that
345
- * `BlocksStack.create()` automatically attaches to the correct stage scope.
346
- *
347
- * The path is resolved **relative to the calling file** (not CWD), using
348
- * `Error.stack` to determine the caller's directory. Absolute paths are
349
- * used as-is.
350
- *
351
- * Each stage's `environment` vars are set on `process.env` before the import
352
- * and cleaned up afterward.
353
- *
354
- * Mutually exclusive with `stageFactory`. When using `Pipeline.create()` and
355
- * neither `appFile` nor `stageFactory` is provided, defaults to `'./index.cdk.ts'`
356
- * (resolved relative to the calling file).
357
- *
358
- * **Security:** This path is dynamically imported during CDK synth, executing
359
- * the module's code in the synth process. It MUST originate from a trusted source
360
- * (developer's pipeline definition file). Never wire this from external input
361
- * (environment variables, build args, plugin configs, or user-supplied values).
362
- * A path-containment check enforces that the resolved file stays within the
363
- * project root, and only `.ts`, `.js`, `.mjs`, `.cjs` extensions are accepted.
364
- *
365
- * @default './index.cdk.ts' (when using Pipeline.create() without stageFactory)
366
- * @example './infra/app.ts'
367
- */
368
- readonly appFile?: string;
369
-
370
- /**
371
- * Whether the pipeline should self-mutate (update its own definition).
372
- *
373
- * @default true
374
- */
375
- readonly selfMutation?: boolean;
376
-
377
- /**
378
- * Cross-account keys for artifact encryption.
379
- * Enable when deploying to accounts different from the pipeline account.
380
- *
381
- * @default false
382
- */
383
- readonly crossAccountKeys?: boolean;
384
- }