Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(app-staging-synthesizer): reduce the size of DefaultStagingStack template by 5KB #26024

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ import {
StackProps,
} from 'aws-cdk-lib/core';
import { StringSpecializer } from 'aws-cdk-lib/core/lib/helpers-internal';
import * as cxapi from 'aws-cdk-lib/cx-api';
import { Construct } from 'constructs';
import { BootstrapRole } from './bootstrap-roles';
import { FileStagingLocation, IStagingResources, IStagingResourcesFactory, ImageStagingLocation } from './staging-stack';

export const DEPLOY_TIME_PREFIX = 'deploy-time/';

/**
* This is a dummy construct meant to signify that a stack is utilizing
* the AppStagingSynthesizer. It does not do anything, and is not meant
* to be created on its own. This construct will be a part of the
* construct tree only and not the Cfn template. The construct tree is
* then encoded in the AWS::CDK::Metadata resource of the stack and
* injested in our metrics like every other construct.
*/
export class UsingAppStagingSynthesizer extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
}
}

/**
* User configurable options to the DefaultStagingStack.
*/
Expand Down Expand Up @@ -128,6 +144,12 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
throw new Error(`Stack ${stack.stackName} must be part of an App`);
}

// Because we do not keep metrics in the DefaultStagingStack, we will inject
// a dummy construct into the stack using the DefaultStagingStack instead.
if (cxapi.ANALYTICS_REPORTING_ENABLED_CONTEXT) {
new UsingAppStagingSynthesizer(stack, `UsingAppStagingSynthesizer/${stack.stackName}`);
}

const stackId = `StagingStack-${appId}-${context.environmentString}`;
return new DefaultStagingStack(app, stackId, {
...options,
Expand Down Expand Up @@ -199,7 +221,10 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
super(scope, id, {
...props,
synthesizer: new BootstraplessSynthesizer(),
analyticsReporting: false, // removing AWS::CDK::Metadata construct saves ~3KB
});
// removing path metadata saves ~2KB
this.node.setContext(cxapi.PATH_METADATA_ENABLE_CONTEXT, false);

this.appId = this.validateAppId(props.appId);
this.dependencyStack = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ describe(AppStagingSynthesizer, () => {
expect(depStack.stackName).toEqual(`StagingStack-${APP_ID}`);
});

test('stack has dummy construct for metrics', () => {
// WHEN
const dummyConstruct = stack.node.tryFindChild(`UsingAppStagingSynthesizer/${stack.stackName}`);
expect(dummyConstruct).toBeDefined();
});

test('add file asset', () => {
// WHEN
const location = stack.synthesizer.addFileAsset({
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"31.0.0"}
{"version":"32.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"testCases": {
"integ-tests/DefaultTest": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"artifacts": {
"synthesize-default-resources.assets": {
"type": "cdk:asset-manifest",
Expand Down Expand Up @@ -78,6 +78,15 @@
"type": "aws:cdk:logicalId",
"data": "lambdaecr2615DAF68"
}
],
"UsingDefaultStagingStacksynthesizedefaultresources": [
{
"type": "aws:cdk:logicalId",
"data": "UsingDefaultStagingStacksynthesizedefaultresources",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
]
},
"displayName": "synthesize-default-resources"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"files": {
"68539effc3f7ad46fff9765606c2a01b7f7965833643ab37e62799f19a37f650": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"id": "synthesize-default-resources",
"path": "synthesize-default-resources",
"children": {
"UsingAppStagingSynthesizer--synthesize-default-resources": {
"id": "UsingAppStagingSynthesizer--synthesize-default-resources",
"path": "synthesize-default-resources/UsingAppStagingSynthesizer--synthesize-default-resources",
"constructInfo": {
"fqn": "@aws-cdk/app-staging-synthesizer-alpha.UsingAppStagingSynthesizer",
"version": "0.0.0"
}
},
"lambda-s3": {
"id": "lambda-s3",
"path": "synthesize-default-resources/lambda-s3",
Expand Down Expand Up @@ -1150,7 +1158,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.Stack",
"fqn": "@aws-cdk/app-staging-synthesizer-alpha.DefaultStagingStack",
"version": "0.0.0"
}
},
Expand All @@ -1167,7 +1175,7 @@
"path": "integ-tests/DefaultTest/Default",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.26"
"version": "10.2.52"
}
},
"DeployAssert": {
Expand Down Expand Up @@ -1213,7 +1221,7 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.26"
"version": "10.2.52"
}
}
},
Expand Down