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

feat: webapp infrastructure #34

Merged
merged 7 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions .projen/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@
"version": "^1.101.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-cloudfront-origins",
"version": "^1.101.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-cloudfront",
"version": "^1.101.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-cloudwatch",
"version": "^1.101.0",
Expand All @@ -127,6 +137,16 @@
"version": "^1.101.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-s3-deployment",
"version": "^1.101.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-s3",
"version": "^1.101.0",
"type": "peer"
},
{
"name": "@aws-cdk/aws-sns",
"version": "^1.101.0",
Expand Down Expand Up @@ -156,6 +176,16 @@
"version": "^1.101.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-cloudfront-origins",
"version": "^1.101.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-cloudfront",
"version": "^1.101.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-cloudwatch",
"version": "^1.101.0",
Expand All @@ -176,6 +206,16 @@
"version": "^1.101.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-s3-deployment",
"version": "^1.101.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-s3",
"version": "^1.101.0",
"type": "runtime"
},
{
"name": "@aws-cdk/aws-sns",
"version": "^1.101.0",
Expand Down
4 changes: 4 additions & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ const project = new AwsCdkConstructLibrary({
cdkDependencies: [
'@aws-cdk/core',
'@aws-cdk/cx-api',
'@aws-cdk/aws-cloudfront',
'@aws-cdk/aws-cloudfront-origins',
'@aws-cdk/aws-cloudwatch',
'@aws-cdk/aws-certificatemanager',
'@aws-cdk/aws-route53',
'@aws-cdk/aws-lambda-nodejs',
'@aws-cdk/aws-lambda',
'@aws-cdk/aws-s3',
'@aws-cdk/aws-s3-deployment',
'@aws-cdk/aws-sns',
],

Expand Down
4 changes: 2 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ __Extends__: [Construct](#aws-cdk-core-construct)


```ts
new ConstructHub(scope: Construct, id: string, _props: ConstructHubProps)
new ConstructHub(scope: Construct, id: string, props: ConstructHubProps)
```

* **scope** (<code>[Construct](#aws-cdk-core-construct)</code>) *No description*
* **id** (<code>string</code>) *No description*
* **_props** (<code>[ConstructHubProps](#construct-hub-constructhubprops)</code>) *No description*
* **props** (<code>[ConstructHubProps](#construct-hub-constructhubprops)</code>) *No description*
* **hostedZone** (<code>[IHostedZone](#aws-cdk-aws-route53-ihostedzone)</code>) The root domain name where this instance of Construct Hub will be served.
* **contactUrls** (<code>[ContactURLs](#construct-hub-contacturls)</code>) Contact URLs to be used for contacting this Construct Hub operators. __*Default*__: none
* **dashboardName** (<code>string</code>) The name of the CloudWatch Dashboard created to observe this application. __*Default*__: the path to this construct is used as the dashboard name.
Expand Down
8 changes: 8 additions & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/construct-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as route53 from '@aws-cdk/aws-route53';
import * as sns from '@aws-cdk/aws-sns';
import { Construct } from '@aws-cdk/core';
import { Dummy } from './dummy';
import { WebApp } from './webapp';
import { Monitoring } from './monitoring';

export interface ConstructHubProps {
Expand Down Expand Up @@ -82,12 +83,17 @@ export interface ContactURLs {
}

export class ConstructHub extends Construct {
public constructor(scope: Construct, id: string, _props: ConstructHubProps) {
public constructor(scope: Construct, id: string, props: ConstructHubProps) {
super(scope, id);

// add some dummy resources so that we have _something_ to monitor.
new Dummy(this, 'Dummy');

new WebApp(this, 'WebApp', {
hostedZone: props.hostedZone,
tlsCertificate: props.tlsCertificate,
});

new Monitoring(this, 'Monitoring', {
watchScope: this,
});
Expand Down
53 changes: 53 additions & 0 deletions src/webapp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as path from 'path';
import * as certificatemanager from '@aws-cdk/aws-certificatemanager';
import * as cloudfront from '@aws-cdk/aws-cloudfront';
import * as origins from '@aws-cdk/aws-cloudfront-origins';
import * as route53 from '@aws-cdk/aws-route53';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3deploy from '@aws-cdk/aws-s3-deployment';
import { Construct } from '@aws-cdk/core';

export interface WebAppProps {
/**
* The root domain name where this instance of Construct Hub will be served.
*/
readonly hostedZone: route53.IHostedZone;

/**
* The certificate to use for serving the Construct Hub over a custom domain.
*
* @default - a DNS-Validated certificate will be provisioned using the
* provided `hostedZone`.
*/
readonly tlsCertificate?: certificatemanager.ICertificate;

/**
* An optional path prefix to use for serving the Construct Hub.
*
* @default - none.
*/
readonly pathPrefix?: string;
}

export class WebApp extends Construct {
public readonly bucket: s3.Bucket;
public readonly distribution: cloudfront.Distribution;
public constructor(scope: Construct, id: string, _props: WebAppProps) {
super(scope, id);
this.bucket = new s3.Bucket(this, 'WebsiteBucket', {
websiteIndexDocument: 'index.html',
publicReadAccess: false
});

this.distribution = new cloudfront.Distribution(this, 'Distribution', {
defaultBehavior: { origin: new origins.S3Origin(this.bucket) },
});

const webappDir = path.join(__dirname, '..', '..', 'node_modules', 'construct-hub-webapp', 'build');
MrArnoldPalmer marked this conversation as resolved.
Show resolved Hide resolved
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
sources: [s3deploy.Source.asset(webappDir)],
destinationBucket: this.bucket,
distribution: this.distribution,
});
}
}
Loading