From 8be0bd97d676e5eed6e19c8278681187f9527e61 Mon Sep 17 00:00:00 2001 From: Gagan Tunuguntla Date: Fri, 12 Apr 2019 17:55:58 -0400 Subject: [PATCH] add cdk files --- client-ui/.dockerignore | 44 ++++++++++++++++++++++++++++++++ client-ui/Dockerfile | 19 ++++++++++++++ client-ui/client-ui-construct.ts | 34 ++++++++++++++++++++++++ client-ui/package.json | 15 +++++++++++ client-ui/simple-server.js | 4 +++ 5 files changed, 116 insertions(+) create mode 100644 client-ui/.dockerignore create mode 100644 client-ui/Dockerfile create mode 100644 client-ui/client-ui-construct.ts create mode 100644 client-ui/package.json create mode 100644 client-ui/simple-server.js diff --git a/client-ui/.dockerignore b/client-ui/.dockerignore new file mode 100644 index 0000000..47765ad --- /dev/null +++ b/client-ui/.dockerignore @@ -0,0 +1,44 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp +/out-tsc + +# dependencies +/node_modules + +# profiling files +chrome-profiler-events.json +speed-measure-plugin.json + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history/* + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +yarn-error.log +testem.log +/typings + +# System Files +.DS_Store +Thumbs.db diff --git a/client-ui/Dockerfile b/client-ui/Dockerfile new file mode 100644 index 0000000..a8bd624 --- /dev/null +++ b/client-ui/Dockerfile @@ -0,0 +1,19 @@ +FROM node:10.15.0-alpine +ENV HOME=/usr/src/app + +# Create simple server that hosts compiled Angular Resources +WORKDIR $HOME +COPY ./package.json $HOME/ +RUN npm install --quiet +RUN node simple-server.js & + +#Set up angular code and dependencies +WORKDIR $HOME/angular-code +COPY ./angular-code/package.json $HOME/angular-code +RUN npm install --quiet +COPY . $HOME +EXPOSE 4200 +WORKDIR $HOME/angular-code + +# Main container process builds angular code to angular-output/ folder +CMD node ../simple-server.js & npm run build diff --git a/client-ui/client-ui-construct.ts b/client-ui/client-ui-construct.ts new file mode 100644 index 0000000..8aed1f4 --- /dev/null +++ b/client-ui/client-ui-construct.ts @@ -0,0 +1,34 @@ +import cdk = require('@aws-cdk/cdk'); +import s3 = require('@aws-cdk/aws-s3'); +import s3Deploy = require('@aws-cdk/aws-s3-deployment'); +import {CloudFrontWebDistribution} from '@aws-cdk/aws-cloudfront'; + +export class ClientUIConstruct extends cdk.Construct { + constructor(parent: cdk.Construct, name: string) { + super(parent, name); + const clientUIAssetsBucket = new s3.Bucket(this, 'Client UI Assets Bucket', { + websiteIndexDocument: 'index.html', + websiteErrorDocument: 'error.html', + removalPolicy: cdk.RemovalPolicy.Destroy + }); + clientUIAssetsBucket.grantPublicAccess('*', 's3:GetObject'); + + new s3Deploy.BucketDeployment(this, 'Client UI Deployment', { + source: s3Deploy.Source.asset('client-ui/assets'), + destinationBucket: clientUIAssetsBucket + }); + + new CloudFrontWebDistribution(this, 'Client UI CDN Distribution', { + originConfigs: [ + { + s3OriginSource: { + s3BucketSource: clientUIAssetsBucket + }, + behaviors : [ {isDefaultBehavior: true}], + + } + ] + }); + + } +} diff --git a/client-ui/package.json b/client-ui/package.json new file mode 100644 index 0000000..4e70573 --- /dev/null +++ b/client-ui/package.json @@ -0,0 +1,15 @@ +{ + "name": "server", + "version": "1.0.0", + "description": "", + "main": "simple-server.js", + "dependencies": { + "express": "^4.16.4" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/client-ui/simple-server.js b/client-ui/simple-server.js new file mode 100644 index 0000000..3d11c5b --- /dev/null +++ b/client-ui/simple-server.js @@ -0,0 +1,4 @@ +var express = require('express'); +var app = express(); +app.use(express.static('../angular-output')); +app.listen(4200);