Skip to content

Commit

Permalink
feat: Support IDEExternal Env deployment (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieweiyi authored Mar 7, 2024
1 parent b10d507 commit 7107e60
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/threat-composer-app/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8" />
<meta http-equiv='Content-Security-Policy'
content="default-src 'self' https://ide-toolkits.threat-composer.aws.dev http://local.ide-toolkits.threat-composer.aws.dev:3000; img-src 'self' * data:; font-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'; media-src 'none' ; frame-src 'none';" />
content="default-src 'self'; img-src 'self' * data:; font-src 'self' data:; script-src 'self' https://ide-toolkits.threat-composer.aws.dev; style-src 'self' 'unsafe-inline' https://ide-toolkits.threat-composer.aws.dev; media-src 'none' ; frame-src 'none';" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="threat-composer" />
Expand Down
2 changes: 1 addition & 1 deletion packages/threat-composer-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ReactDOM.render(
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
serviceWorkerRegistration.register();
!isMemoryRouterUsed() && serviceWorkerRegistration.register();

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
Expand Down
12 changes: 6 additions & 6 deletions packages/threat-composer-infra/cdk.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"repositoryName": "threat_composer_monorepo",
"accountPipeline": "",
"accountDev": "",
"accountProd": "",
"cidrTypeDev": "IPV4",
"cidrRangesDev": "192.168.0.0/24",
"cidrTypeProd": "IPV4",
"cidrRangesProd": "192.168.0.0/24",
"domainNameDev": "",
"certificateDev": "",
"domainNameProd": "",
"certificateProd": "",
"hostZoneDev": "",
"hostZoneNameDev": "",
"lambdaEdgeDev": "",
"accountProd": "",
"cidrTypeProd": "IPV4",
"cidrRangesProd": "192.168.0.0/24",
"domainNameProd": "",
"certificateProd": "",
"hostZoneProd": "",
"hostZoneNameProd": "",
"lambdaEdgeDev": "",
"lambdaEdgeProd": ""
}
26 changes: 19 additions & 7 deletions packages/threat-composer-infra/src/application-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from 'aws-cdk-lib/custom-resources';
import { NagSuppressions } from 'cdk-nag';
import { Construct } from 'constructs';
import { STAGE_PREFIX_IDE_EXTENSION_ENV } from './constants';

const PACKAGES_ROOT = path.join(__dirname, '..', '..');

Expand All @@ -58,7 +59,23 @@ export class ApplicationStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const stageName = Stage.of(this)?.stageName;
const stageName = Stage.of(this)?.stageName || 'Dev';

let assetPath = path.join(
PACKAGES_ROOT,
'threat-composer-app',
'build',
'website',
);

if (stageName?.startsWith(STAGE_PREFIX_IDE_EXTENSION_ENV)) {
assetPath = path.join(
PACKAGES_ROOT,
'threat-composer-app',
'build',
'ide-extension',
);
}

const domainName = this.node.tryGetContext(`domainName${stageName}`);
const certificate = this.node.tryGetContext(`certificate${stageName}`);
Expand Down Expand Up @@ -212,12 +229,7 @@ export class ApplicationStack extends Stack {
}

const websiteProps: StaticWebsiteProps = {
websiteContentPath: path.join(
PACKAGES_ROOT,
'threat-composer-app',
'build',
'website',
),
websiteContentPath: assetPath,
webAclProps: {
cidrAllowList: {
cidrType: cidrType === 'IPV6' ? 'IPV6' : 'IPV4',
Expand Down
16 changes: 16 additions & 0 deletions packages/threat-composer-infra/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************************************************** */
export const STAGE_PREFIX_IDE_EXTENSION_ENV = 'IDEExtension';
23 changes: 23 additions & 0 deletions packages/threat-composer-infra/src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { PDKNag } from '@aws/pdk/pdk-nag';
import { ManualApprovalStep } from 'aws-cdk-lib/pipelines';
import { ApplicationStage } from './application-stage';
import { STAGE_PREFIX_IDE_EXTENSION_ENV } from './constants';
import { PipelineStack } from './pipeline-stack';

const app = PDKNag.app();
Expand Down Expand Up @@ -58,6 +59,28 @@ if (prodAccount) {
});
}

const ideExtensionDevAccount =
app.node.tryGetContext(`account${STAGE_PREFIX_IDE_EXTENSION_ENV}Dev`) || process.env.CDK_DEFAULT_ACCOUNT;
const ideExtensionProdAccount = app.node.tryGetContext(`account${STAGE_PREFIX_IDE_EXTENSION_ENV}Prod`);

if (ideExtensionDevAccount) {
new ApplicationStage(app, `${STAGE_PREFIX_IDE_EXTENSION_ENV}Dev`, {
env: {
account: ideExtensionDevAccount,
region,
},
});
}

if (ideExtensionProdAccount) {
new ApplicationStage(app, `${STAGE_PREFIX_IDE_EXTENSION_ENV}Prod`, {
env: {
account: ideExtensionProdAccount,
region,
},
});
}

pipelineStack.pipeline.buildPipeline(); // Needed for CDK Nag

app.synth();

0 comments on commit 7107e60

Please sign in to comment.