Skip to content

Commit e69c79e

Browse files
authored
chore(toolkit): programmatic hotswap property overrides (#33227)
Hotswap property overrides can be added to programmatic deploy ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c83d61f commit e69c79e

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

packages/@aws-cdk/toolkit/lib/actions/deploy/index.ts

+35
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,39 @@ export interface DeployOptions extends BaseDeployOptions {
244244
* @deprecated Implement in IoHost instead
245245
*/
246246
readonly progress?: StackActivityProgress;
247+
248+
/**
249+
* Represents configuration property overrides for hotswap deployments.
250+
* Currently only supported by ECS.
251+
*
252+
* @default - no overrides
253+
*/
254+
readonly hotswapProperties?: HotswapProperties;
255+
}
256+
257+
/**
258+
* Property overrides for ECS hotswaps
259+
*/
260+
export interface EcsHotswapProperties {
261+
/**
262+
* The lower limit on the number of your service's tasks that must remain
263+
* in the RUNNING state during a deployment, as a percentage of the desiredCount.
264+
*/
265+
readonly minimumHealthyPercent: number;
266+
267+
/**
268+
* The upper limit on the number of your service's tasks that are allowed
269+
* in the RUNNING or PENDING state during a deployment, as a percentage of the desiredCount.
270+
*/
271+
readonly maximumHealthyPercent: number;
272+
}
273+
274+
/**
275+
* Property overrides for hotswap deployments.
276+
*/
277+
export interface HotswapProperties {
278+
/**
279+
* ECS specific hotswap property overrides
280+
*/
281+
readonly ecs: EcsHotswapProperties;
247282
}

packages/@aws-cdk/toolkit/lib/actions/deploy/private/helpers.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { DeployOptions } from '..';
2-
import { Deployments, WorkGraph } from '../../../api/aws-cdk';
1+
import { DeployOptions, HotswapProperties } from '..';
2+
import { Deployments, EcsHotswapProperties, HotswapPropertyOverrides, WorkGraph } from '../../../api/aws-cdk';
33

44
export function buildParameterMap(parameters?: Map<string, string | undefined>): { [name: string]: { [name: string]: string | undefined } } {
55
const parameterMap: {
@@ -33,3 +33,13 @@ export async function removePublishedAssets(graph: WorkGraph, deployments: Deplo
3333
stackName: assetNode.parentStack.stackName,
3434
}));
3535
}
36+
37+
/**
38+
* Create the HotswapPropertyOverrides class out of the Interface exposed to users
39+
*/
40+
export function createHotswapPropertyOverrides(hotswapProperties: HotswapProperties): HotswapPropertyOverrides {
41+
return new HotswapPropertyOverrides(new EcsHotswapProperties(
42+
hotswapProperties.ecs.minimumHealthyPercent,
43+
hotswapProperties.ecs.maximumHealthyPercent,
44+
));
45+
}

packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export { WorkGraph } from '../../../../aws-cdk/lib/util/work-graph';
2828
export type { Concurrency } from '../../../../aws-cdk/lib/util/work-graph';
2929
export { WorkGraphBuilder } from '../../../../aws-cdk/lib/util/work-graph-builder';
3030
export type { AssetBuildNode, AssetPublishNode, StackNode } from '../../../../aws-cdk/lib/util/work-graph-types';
31+
export { HotswapPropertyOverrides, EcsHotswapProperties } from '../../../../aws-cdk/lib/api/hotswap/common';
3132

3233
// @todo Cloud Assembly and Executable - this is a messy API right now
3334
export { CloudAssembly, sanitizePatterns, StackCollection, ExtendedStackSelection } from '../../../../aws-cdk/lib/api/cxapp/cloud-assembly';

packages/@aws-cdk/toolkit/lib/toolkit/toolkit.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as chokidar from 'chokidar';
55
import * as fs from 'fs-extra';
66
import { ToolkitServices } from './private';
77
import { AssetBuildTime, type DeployOptions, RequireApproval } from '../actions/deploy';
8-
import { type ExtendedDeployOptions, buildParameterMap, removePublishedAssets } from '../actions/deploy/private';
8+
import { type ExtendedDeployOptions, buildParameterMap, createHotswapPropertyOverrides, removePublishedAssets } from '../actions/deploy/private';
99
import { type DestroyOptions } from '../actions/destroy';
1010
import { type DiffOptions } from '../actions/diff';
1111
import { diffRequiresApproval } from '../actions/diff/private';
@@ -242,15 +242,6 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
242242
].join('\n')));
243243
}
244244

245-
// @TODO
246-
// let hotswapPropertiesFromSettings = this.props.configuration.settings.get(['hotswap']) || {};
247-
248-
// let hotswapPropertyOverrides = new HotswapPropertyOverrides();
249-
// hotswapPropertyOverrides.ecsHotswapProperties = new EcsHotswapProperties(
250-
// hotswapPropertiesFromSettings.ecs?.minimumHealthyPercent,
251-
// hotswapPropertiesFromSettings.ecs?.maximumHealthyPercent,
252-
// );
253-
254245
const stacks = stackCollection.stackArtifacts;
255246

256247
const stackOutputs: { [key: string]: any } = {};
@@ -370,7 +361,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
370361
rollback,
371362
hotswap: hotswapMode,
372363
extraUserAgent: options.extraUserAgent,
373-
// hotswapPropertyOverrides: hotswapPropertyOverrides,
364+
hotswapPropertyOverrides: options.hotswapProperties ? createHotswapPropertyOverrides(options.hotswapProperties) : undefined,
374365
assetParallelism: options.assetParallelism,
375366
});
376367

packages/@aws-cdk/toolkit/test/actions/deploy.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,32 @@ describe('deploy', () => {
135135
notificationArns: [arn],
136136
})).rejects.toThrow(/Notification arn arn:aws:sqs:us-east-1:1111111111:resource is not a valid arn for an SNS topic/);
137137
});
138+
139+
test('hotswap property overrides', async () => {
140+
// WHEN
141+
const cx = await builderFixture(toolkit, 'stack-with-role');
142+
await toolkit.deploy(cx, {
143+
hotswapProperties: {
144+
ecs: {
145+
maximumHealthyPercent: 100,
146+
minimumHealthyPercent: 0,
147+
},
148+
},
149+
});
150+
151+
// THEN
152+
// passed through correctly to Deployments
153+
expect(mockDeployStack).toHaveBeenCalledWith(expect.objectContaining({
154+
hotswapPropertyOverrides: {
155+
ecsHotswapProperties: {
156+
maximumHealthyPercent: 100,
157+
minimumHealthyPercent: 0,
158+
},
159+
},
160+
}));
161+
162+
successfulDeployment();
163+
});
138164
});
139165

140166
describe('deployment results', () => {

0 commit comments

Comments
 (0)