Skip to content

Commit

Permalink
Merge pull request #1186 from alliance-genome/SCRUM-3289
Browse files Browse the repository at this point in the history
Added code for deploing a ALB with the UI code
  • Loading branch information
oblodgett authored Sep 11, 2023
2 parents 57ae86a + 768c74b commit 2141154
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ Thumbs.db
*.swp


cdk-outputs.json
cdk.context.json
cdk.out
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ test:
run:
npm start

alb-deploy:
npx aws-cdk deploy --outputs-file ./cdk-outputs.json

uirun:
npm start

Expand Down
4 changes: 4 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"app": "npx ts-node --prefer-ts-exts cdk/cdk-stage.ts",
"context": {}
}
13 changes: 13 additions & 0 deletions cdk/cdk-stage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import {StageALBStack} from './stage-alb-stack';

const app = new cdk.App();

new StageALBStack(app, 'stage-alb-stack', {
stackName: 'stage-alb-stack',
env: {
region: process.env.CDK_DEFAULT_REGION,
account: process.env.CDK_DEFAULT_ACCOUNT,
},
});
93 changes: 93 additions & 0 deletions cdk/stage-alb-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as autoscaling from 'aws-cdk-lib/aws-autoscaling';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as route53Targets from 'aws-cdk-lib/aws-route53-targets';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as targets from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets';
import * as cdk from 'aws-cdk-lib';

export class StageALBStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const vpc = ec2.Vpc.fromLookup(this, 'Docker', { vpcName: 'Docker' });
const sg1 = ec2.SecurityGroup.fromLookupById(this, 'default', 'sg-21ac675b');
const sg2 = ec2.SecurityGroup.fromLookupById(this, 'HTTP/HTTPS', 'sg-0415cab61ab6b45c5');
const cert = elbv2.ListenerCertificate.fromArn('arn:aws:acm:us-east-1:100225593120:certificate/047a56a2-09dd-4857-9f28-32d23650d4da');
const stage = new targets.InstanceIdTarget('i-0d7ea7b7cc11a2e8f')
const public_zone = route53.HostedZone.fromHostedZoneAttributes(this, 'Public Zone', { zoneName: 'alliancegenome.org', hostedZoneId: 'Z3IZ3D6V94JEC2' });
const private_zone = route53.HostedZone.fromHostedZoneAttributes(this, 'Private Zone', { zoneName: 'alliancegenome.org', hostedZoneId: 'Z007692222A6W93AZVSPD' });

const alb = new elbv2.ApplicationLoadBalancer(this, 'alb', {
vpc,
internetFacing: true,
securityGroup: sg1
});

alb.addSecurityGroup(sg2);

new route53.CnameRecord(this, "Public DNS", {
zone: public_zone,
recordName: "stage-alb",
domainName: alb.loadBalancerDnsName,
ttl: cdk.Duration.minutes(5)
});
new route53.CnameRecord(this, "Private DNS", {
zone: private_zone,
recordName: "stage-alb",
domainName: alb.loadBalancerDnsName,
ttl: cdk.Duration.minutes(5)
});

const listener_https = alb.addListener('HTTPS Listener', {
port: 443,
open: true,
certificates: [cert]
});

listener_https.addTargets("Backend Stage", {
healthCheck: {
path: '/robots.txt',
unhealthyThresholdCount: 3,
healthyThresholdCount: 5,
interval: cdk.Duration.seconds(60),
},
port: 80,
targets: [stage],
});

/*
listener_https.addAction("Redirect to Stage", {
priority: 10,
conditions: [
elbv2.ListenerCondition.hostHeaders(['stage-alb.alliancegenome.org']),
],
action: elbv2.ListenerAction.redirect({
protocol: 'HTTPS',
port: '443',
host: 'stage.alliancegenome.org',
path: '/#{path}',
query: '#{query}',
permanent: true,
}),
});
*/

const listener_http = alb.addListener('HTTP Listener', {
port: 80,
open: true,
defaultAction: elbv2.ListenerAction.redirect({
protocol: 'HTTPS',
port: '443',
host: 'stage.alliancegenome.org',
path: '/#{path}',
query: '#{query}',
permanent: true,
}),
});

new cdk.CfnOutput(this, 'albDNS', {
value: alb.loadBalancerDnsName
});
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
"@testing-library/jest-dom": "^5.16.1",
"abortcontroller-polyfill": "^1.5.0",
"agr_genomefeaturecomponent": "^0.3.24",
"aws-cdk": "^2.95.1",
"aws-cdk-lib": "^2.95.1",
"aws-lambda": "^1.0.7",
"bootstrap": "4.6.1",
"constructs": "^10.2.70",
"core-js": "^3.6.5",
"custom-event-polyfill": "^1.0.6",
"d3-selection": "2.0.0",
Expand Down Expand Up @@ -85,6 +89,7 @@
"regenerator-runtime": "^0.13.7",
"reselect": "^2.5.4",
"sitemap": "^1.13.0",
"source-map-support": "^0.5.21",
"tslib": "^2.0.0",
"twin.macro": "2.2.3",
"whatwg-fetch": "^3.4.0"
Expand Down
32 changes: 32 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"lib": ["es2018", "ESNext.AsyncIterable"],
"allowJs": true,
"checkJs": true,
"removeComments": true,
"resolveJsonModule": true,
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"inlineSourceMap": true,
"inlineSources": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"typeRoots": ["./node_modules/@types"],
"isolatedModules": true
},
"exclude": ["node_modules", "**/node_modules/*", "cdk.out"]
}

0 comments on commit 2141154

Please sign in to comment.