Skip to content

Commit

Permalink
feat(COND-1): Integrate the Amazon CDK to deploy the app and set up t…
Browse files Browse the repository at this point in the history
…he CI/CD pipeline in the development environment
  • Loading branch information
kenyipp committed Oct 27, 2024
1 parent 72d4bb1 commit 2746def
Show file tree
Hide file tree
Showing 40 changed files with 4,232 additions and 10 deletions.
File renamed without changes.
26 changes: 26 additions & 0 deletions .github/workflows/deploy-to-develop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy to Develop

on:
workflow_run:
workflows: ['Continuous Integration'] # Triggers after the specified workflow completes
types:
- completed

jobs:
deploy:
name: Deploy to Develop
environment:
name: develop
runs-on: ubuntu-latest
if: |
github.event.workflow_run.conclusion == 'success' &&
contains(github.event.workflow_run.head_branch, 'develop')
steps:
- name: Trigger AWS CodePipeline
run:
aws codepipeline start-pipeline-execution --name ${{
vars.CODE_BUILD_PIPELINE }} --region ${{ vars.AWS_REGION }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>
<!-- The badges section -->
<p align="center">
<a href="https://github.com/kenyipp/realworld-nodejs-example-app/actions/workflows/ci.yml"><img src="https://github.com/kenyipp/realworld-nodejs-example-app/workflows/CI/badge.svg" alt="Actions Status"></a>
<a href="https://github.com/kenyipp/realworld-nodejs-example-app/actions/workflows/ci.yml"><img src="https://github.com/kenyipp/realworld-nodejs-example-app/workflows/Continuous Integration/badge.svg" alt="Actions Status"></a>
<a href="https://app.codacy.com/gh/kenyipp/realworld-nodejs-example-app/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img src="https://img.shields.io/codacy/grade/d920979be4dc45feb55dcd462ef88229" /></a>
<a href="https://codecov.io/gh/kenyipp/realworld-nodejs-example-app"><img src="https://codecov.io/gh/kenyipp/realworld-nodejs-example-app/branch/master/graph/badge.svg?token=AMBNXM57T8" alt="codecov"></a>
<!-- Snyk.io vulnerabilities badge -->
Expand All @@ -18,6 +18,8 @@
This repository has been approved and included on the <a href="https://codebase.show/projects/realworld?category=backend&language=typescript">project page</a> by the <a href="https://codebase.show">Codebase.show</a> team. I am committed to continuously improving this codebase and incorporating new technologies and useful Node modules as I discover them.
</p>

<p align="center"> I created a separate <a href="https://github.com/kenyipp/realworld-nodejs-example-app-infra?tab=readme-ov-file">repository</a> to deploy this project architecture via <a href="https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html">Aws Cdk</>. Please check this repository. </p>

<p align="center"> This repository has complete functionality — pull requests and issues are welcome! </p>

<p align="center">
Expand All @@ -30,13 +32,11 @@ This repository has been approved and included on the <a href="https://codebase.
<a href="#contributing">Contributing</a>
</p>

<a id="demo"></a>

## Demo

To demonstrate the functionality of the backend, we have deployed a live demo version of the application. You can visit the demo by following this link: [https://conduit-api-production.kenyip.cc](https://conduit-api-production.kenyip.cc).
To demonstrate the functionality of the backend, we have deployed a live demo version of the application. You can visit the demo by following this link: [https://conduit-api-production.kenyip.cc](https://conduit-api-develop.kenyip.cc).

The API has several endpoints that you can test out using a tool like Postman or cURL. You can find the documentation for the API endpoints on the [API documentation page](https://conduit-api-production.kenyip.cc). Feel free to use this endpoint to create your amazing frontend applications!
The API has several endpoints that you can test out using a tool like Postman or cURL. You can find the documentation for the API endpoints on the [API documentation page](https://conduit-api-develop.kenyip.cc). Feel free to use this endpoint to create your amazing frontend applications!

Please note that the demo version of the application is intended for demonstration purposes only and may not be suitable for production use. If you would like to deploy the application yourself, please follow the instructions in the <a href="#get_started">Get Started</a> section of this README.

Expand Down
2 changes: 1 addition & 1 deletion apps/local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"dependencies": {
"@conduit/app": "*",
"@conduit/article": "*",
"@conduit/user": "*",
"@conduit/middleware": "*",
"@conduit/user": "*",
"@conduit/utils": "*",
"dotenv": "^16.4.5",
"express": "^4.21.1"
Expand Down
6 changes: 4 additions & 2 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"nodeEnv": "NODE_ENV",
"mode": "MODE",
"domain": "DOMAIN",
"aws": {
"region": "AWS_REGION",
"accountId": "AWS_ACCOUNT_ID"
},
"auth": {
"expiresIn": "AUTH_EXPIRES_IN",
"jwtSecret": "AUTH_JWT_SECRET"
Expand Down
75 changes: 75 additions & 0 deletions infra/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"extends": [
"eslint:recommended",
"eslint-config-airbnb-base",
"airbnb-typescript",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"env": {
"es2021": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"import/prefer-default-export": "off",
"no-tabs": ["off"],
"max-len": ["off"],
"no-await-in-loop": "off",
"react/jsx-filename-extension": "off",
"class-methods-use-this": "off",
"no-new": "off",
"no-param-reassign": "off",
"@typescript-eslint/quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"@typescript-eslint/comma-dangle": ["error", "never"],
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/lines-between-class-members": [
"error",
"always",
{
"exceptAfterSingleLine": true
}
],
"prettier/prettier": [
"error",
{
"tabWidth": 2
}
]
},
"overrides": [
{
"files": ["*.spec.{js,ts}"],
"env": {
"mocha": true,
"node": true
},
"rules": {
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-throw-literal": "off"
}
}
],
"parserOptions": {
"project": "./tsconfig.json"
},
"ignorePatterns": [
"dist",
"node_modules",
".eslintrc.js",
"jest.config.js",
"cdk.out"
]
}
1 change: 1 addition & 0 deletions infra/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cdk.out
22 changes: 22 additions & 0 deletions infra/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"printWidth": 85,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "always",
"proseWrap": "always",
"plugins": [
"prettier-plugin-packagejson",
"@trivago/prettier-plugin-sort-imports"
],
"importOrder": ["^dotenv/config$", "<THIRD_PARTY_MODULES>", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrderCaseInsensitive": false
}
2 changes: 2 additions & 0 deletions infra/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
qa:
yarn prettify && yarn lint:fix
3 changes: 3 additions & 0 deletions infra/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "ts-node main.ts"
}
16 changes: 16 additions & 0 deletions infra/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"nodeEnv": "NODE_ENV",
"aws": {
"region": "AWS_REGION",
"accountId": "AWS_ACCOUNT_ID",
"arn": {
"role": {
"lambda": "AWS_ROLE_LAMBDA_ARN"
}
}
},
"github": {
"repository": "GITHUB_REPOSITORY",
"owner": "GITHUB_OWNER"
}
}
9 changes: 9 additions & 0 deletions infra/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"aws": {
"region": "us-east-1"
},
"github": {
"repository": "realworld-nodejs-example-app",
"owner": "kenyipp"
}
}
3 changes: 3 additions & 0 deletions infra/config/develop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nodeEnv": "develop"
}
3 changes: 3 additions & 0 deletions infra/config/prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nodeEnv": "prod"
}
8 changes: 8 additions & 0 deletions infra/constants/Lambdas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ResourcePrefix } from './constants';

export const Lambdas = {
UserServerFunction: `${ResourcePrefix}-user-server-lambda`,
AppServerFunction: `${ResourcePrefix}-app-server-lambda`,
ArticleServerFunction: `${ResourcePrefix}-article-server-lambda`,
TestingCron: `${ResourcePrefix}-testing-cron-lambda`
};
8 changes: 8 additions & 0 deletions infra/constants/Secrets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { config } from '../utils';

export const Secrets = {
GithubToken: 'conduit/github-token',
DatabaseConfig: `conduit/${config.nodeEnv}/database`,
JwtSecret: `conduit/${config.nodeEnv}/jwt-token`,
DomainCert: `conduit/${config.nodeEnv}/acm-certificate`
};
6 changes: 6 additions & 0 deletions infra/constants/Stacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ResourcePrefix } from './constants';

export const Stacks = {
ApiGateway: `${ResourcePrefix}-api-gateway-stack`,
Lambda: `${ResourcePrefix}-lambda-stack`
};
6 changes: 6 additions & 0 deletions infra/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { config } from '../utils';

const app = 'conduit-api';
const { accountId } = config.aws;

export const ResourcePrefix = `${app}-${config.nodeEnv}-${accountId}`;
4 changes: 4 additions & 0 deletions infra/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './constants';
export * from './Lambdas';
export * from './Stacks';
export * from './Secrets';
57 changes: 57 additions & 0 deletions infra/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'dotenv/config';

import { CdkGraph, FilterPreset } from '@aws/pdk/cdk-graph';
import {
CdkGraphDiagramPlugin,
DiagramFormat
} from '@aws/pdk/cdk-graph-plugin-diagram';
import { App, Environment } from 'aws-cdk-lib';

import { Stacks } from './constants';
import { ApiGatewayStack, LambdaStack } from './stacks';
import { config } from './utils';

// eslint-disable-next-line no-void, func-names
void (async function () {
const app = new App();

const env: Environment = {
region: config.aws.region,
account: config.aws.accountId
};

const lambdaStack = new LambdaStack(app, Stacks.Lambda, {
env,
roleArn: config.aws.arn.role.lambda
});

new ApiGatewayStack(app, Stacks.ApiGateway, {
env,
userFunctionArn: lambdaStack.userServerFunction.functionArn,
appFunctionArn: lambdaStack.appServerFunction.functionArn,
articleServerFunctionArn: lambdaStack.articleServerFunction.functionArn
});

// Generate a diagram for the whole architecture
const group = new CdkGraph(app, {
plugins: [
new CdkGraphDiagramPlugin({
diagrams: [
{
name: 'conduit-api-stack-diagram',
title: 'Conduit Api Stack Diagram',
format: DiagramFormat.PNG,
theme: 'light',
filterPlan: {
preset: FilterPreset.COMPACT
}
}
]
})
]
});

app.synth();

await group.report();
})();
43 changes: 43 additions & 0 deletions infra/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@conduit/lamba-infra",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "ken.yip",
"main": "main.ts",
"scripts": {
"cdk:list": "cdk list",
"check-types": "tsc --skipLibCheck --noEmit",
"deploy": "cdk deploy --require-approval never",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prettify": "prettier --write .",
"synth": "cdk synth"
},
"dependencies": {
"@aws/pdk": "^0.25.0",
"aws-cdk": "2.161.1",
"aws-cdk-lib": "2.161.1",
"config": "^3.3.12",
"constructs": "^10.4.1",
"dotenv": "^16.4.5"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/config": "^3.3.5",
"@types/node": "^22.7.5",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.19.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"prettier-plugin-packagejson": "^2.5.3",
"ts-node": "^10.9.1",
"typescript": "^5.6.3"
}
}
Loading

0 comments on commit 2746def

Please sign in to comment.