Skip to content

Commit

Permalink
Merge pull request #32 from moduslabs/feature-cloudformation
Browse files Browse the repository at this point in the history
FET-769 - Create a CDK project to deploy the webapp at AWS
  • Loading branch information
rafaelwaterkemper authored Jun 6, 2022
2 parents ec48d28 + f1d3b43 commit a8b4ea9
Show file tree
Hide file tree
Showing 16 changed files with 11,706 additions and 1 deletion.
55 changes: 55 additions & 0 deletions .github/workflows/on-push-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deployment master

on:
push:
branches: [main]

env:
NAMESPACE: stage
QUALIFIER: stage

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@master
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Install dependencies to deploy project
run: npm install

- name: Build project
run: npm run build

- name: Install dependencies for cdk
run: npm install
working-directory: deploy

- name: Synth template
run: npm run cdk synth
working-directory: deploy

- name: Bootstrap stack
run: npm run cdk bootstrap -- --toolkit-stack-name CDKToolKitStage --qualifier ${{ env.QUALIFIER }}
working-directory: deploy

- name: Deploy stack
run: npm run cdk deploy -- --require-approval never
working-directory: deploy
55 changes: 55 additions & 0 deletions .github/workflows/on-release-published.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: On Release published

on:
release:
types: [published]

env:
NAMESPACE: production
QUALIFIER: production

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@master
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Install dependencies to deploy project
run: npm install

- name: Build project
run: npm run build

- name: Install dependencies for cdk
run: npm install
working-directory: deploy

- name: Synth template
run: npm run cdk synth
working-directory: deploy

- name: Bootstrap stack
run: npm run cdk bootstrap -- --toolkit-stack-name CDKToolKitProduction --qualifier ${{ env.QUALIFIER }}
working-directory: deploy

- name: Deploy stack
run: npm run cdk deploy -- --require-approval never
working-directory: deploy
7 changes: 7 additions & 0 deletions deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!jest.config.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out
6 changes: 6 additions & 0 deletions deploy/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
27 changes: 27 additions & 0 deletions deploy/cdk-ishihara-app-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "source-map-support/register";
import * as cdk from "aws-cdk-lib";
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import { capitalize, getNamespace } from "./utils";
import { getHTTPSCertificate } from "./resources/certificate-dns";
import { getHostedZone, getHostedZoneRecords } from "./resources/route-53";
import { getWebappResources } from "./resources/cloud-front-distribution";

export class CdkIshiharaAppStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const hostedZone = getHostedZone(this);
const certificate = getHTTPSCertificate(this, hostedZone);
const { cloudFrontDistribution } = getWebappResources(this, certificate);
getHostedZoneRecords(this, hostedZone, cloudFrontDistribution);
}
}

const app = new cdk.App();

new CdkIshiharaAppStack(app, `CdkIshiharaAppStack${capitalize(getNamespace())}`, {
synthesizer: new cdk.DefaultStackSynthesizer({
qualifier: process.env.QUALIFIER || 'local',
}),
});
33 changes: 33 additions & 0 deletions deploy/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"app": "npm run ts-node -- --prefer-ts-exts ./cdk-ishihara-app-stack.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
"@aws-cdk/core:stackRelativeExports": true,
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
]
}
}
6 changes: 6 additions & 0 deletions deploy/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cdk": {
"zoneName": "ishihara-app.com",
"hostedZoneId": "Z054722611ERV11JTXKBK"
}
}
8 changes: 8 additions & 0 deletions deploy/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
Loading

0 comments on commit a8b4ea9

Please sign in to comment.