-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 226eff7
Showing
84 changed files
with
3,691 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.vscode/* | ||
node_modules/ | ||
dist/ | ||
temp/ | ||
deploy/ | ||
global-s3-assets/ | ||
regional-s3-assets/ | ||
*.build.log | ||
tsconfig.tsbuildinfo | ||
*.zip | ||
.pnpm-debug.log | ||
pnpm-lock.yaml | ||
repo-state.json | ||
app-config-dev.json | ||
app-config-prod.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Boilerplate CHANGELOG.md | ||
|
||
## 1.0.0 | ||
|
||
### Notes | ||
|
||
- [X] Docs: add CHANGELOG.md | ||
- [X] Docs: What to do after cloned the boilerplate | ||
- [X] Docs: for updating source/common/config/rush/deploy.json | ||
- [X] Remove .vscode from git | ||
- [X] Fix: The location of compiled temp file problem | ||
- [X] Logger: Declare/export logger in utils, can set level and can be used directly | ||
- [X] Folder structure: The structure of service source (src) | ||
- [X] Folder structure: The naming of source, want to plus "handler" to api controller | ||
- [X] Fix: cdk deploy same s3/bootstrapping problem | ||
- [X] Fix: cdk deploy can set env parameters | ||
- [X] Create CDK custom template | ||
- [X] Test: add integration test using Cucumber.js | ||
- [X] Feat: add destroy stacks script | ||
- [X] Test: add code coverage report using Jest | ||
- [X] Feat: add build stacks script and publish packages to npm registry | ||
- [X] Util: managing environment variables of business service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# PREPARE | ||
|
||
## jq | ||
|
||
```sh | ||
$sudo apt update | ||
$sudo apt install -y jq | ||
``` | ||
|
||
## aws-cli | ||
|
||
```sh | ||
$curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
$unzip awscliv2.zip | ||
$sudo ./aws/install | ||
$/usr/local/bin/aws --version | ||
aws-cli/2.11.2 Python/3.11.2 Linux/4.14.305-227.531.amzn2.x86_64 exe/x86_64.amzn.2 prompt/off | ||
``` | ||
|
||
## nodejs | ||
|
||
```sh | ||
$nvm install 16 | ||
$nvm use 16 | ||
Now using node v16.19.1 (npm v8.19.3) | ||
|
||
$node --version | ||
v16.19.1 | ||
``` | ||
|
||
## pnpm | ||
|
||
```sh | ||
npm install -g [email protected] | ||
npm install -g [email protected] | ||
``` | ||
|
||
## git | ||
|
||
```sh | ||
$git --version | ||
git version 2.39.2 | ||
``` | ||
|
||
## rush | ||
|
||
```bash | ||
$git config --global user.name "sample" | ||
$git config --local user.email "[email protected]" | ||
$npm install -g @microsoft/rush | ||
$git clone https://github.com/microsoft/rushstack | ||
$cd rushstack | ||
$rush update | ||
$rush rebuild | ||
$rush build | ||
$rush rebuild --verbose | ||
``` | ||
|
||
## aws profile(if necessary) | ||
|
||
```bash | ||
aws configue | ||
cat ~/.aws/credentials | ||
[defaule] | ||
aws_access_key_id=xxx | ||
aws_secret_access_key=yyy | ||
aws_session_token=zzz | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Monorepo Microservices Boilerplate | ||
|
||
This is microservices boilerplate for monorepo with CDK and Rush. | ||
|
||
- CDK is used for producing CloudFormation output and microservice deployments | ||
- Rush.js is used for managing dependencies and compiling multiple business service repos | ||
|
||
![CDK Intro](docs/assets/aws_cdk_intro.png) | ||
|
||
![Rush Monorepo](docs/assets/monorepo.png) | ||
|
||
## 1. Get started | ||
|
||
### 1.1. Clone the boilerplate repo from Github | ||
|
||
```bash | ||
$git clone https://github.com/hanhdt/ts-microservices-rush-boilerplate.git | ||
``` | ||
|
||
### 1.2. Rename the boilerplate repo to your own repo name | ||
|
||
## 2. Prerequisites | ||
|
||
- see PREPARE.md | ||
|
||
### AWS Account & IAM User | ||
|
||
First of all, AWS Account and IAM User is required. IAM user's credential keys also are required. | ||
|
||
### Dependencies | ||
|
||
To execute this template codes, the following modules must be installed. | ||
|
||
- AWS CLI: aws --version | ||
|
||
- Node.js: node --version | ||
|
||
- AWS CDK: cdk --version | ||
|
||
- Rush: rush --version | ||
|
||
## 3. Setup target environment configuration (for example: dev) | ||
|
||
![app-config-demo](docs/assets/app-config-sample.png) | ||
|
||
Because we need to ensure that a single source code is maintained, all configurations are managed in config/app-config-[your-suffix].json. And several files are made according to the environment you want to deploy to, and you have to choose one of them when deploying. | ||
For example, if you want to deploy to dev environment, you have to create `config/app-config-dev.json` | ||
|
||
- reference to config/app-config-sample.json | ||
|
||
## 4. Initial setup and bootstrap | ||
|
||
Execute the following command: | ||
|
||
```bash | ||
$./script/initial_setup.sh config/app-config-dev.json | ||
``` | ||
|
||
## 5. Init a new service repo (for example: sample-service) | ||
|
||
<img src="docs/assets/service-repo-sample.png" height="640px"> | ||
|
||
To create new service repository, do the following step: | ||
|
||
- Change `App` to your new `service-folder` name in `config/app-config-[environment].json` | ||
|
||
- Execute the following command: | ||
|
||
```bash | ||
$./script/create_new_service.sh config/app-config-dev.json <service-folder> | ||
``` | ||
|
||
- Rename `@hanhdt/sample-service` in `package.json` to your new `service-name` | ||
|
||
## 6. Deploy procedure | ||
|
||
To deploy stacks, run the following commands: | ||
|
||
```bash | ||
$./script/deploy_stacks.sh config/app-config-dev.json | ||
``` | ||
|
||
Read more details about adding Rush configuration at `script/README.md` | ||
|
||
## 7. Local Test | ||
|
||
- see source/package/services/sample-service/README.md | ||
|
||
## Appendixes | ||
|
||
### Fix error: "SSM parameter /cdk-bootstrap/hnb659fds/version not found" in the Step 7 | ||
|
||
```bash | ||
$cd source/packages/services/<appName> | ||
$cdk deploy --no-previous-parameters -c config=dev | ||
``` | ||
|
||
### Create local configuration file | ||
|
||
The `.env` file will be placed at the service folder. | ||
And it is scoped to the service. | ||
|
||
You can put `.env` file in the `source/packages/services/<ServiceName>/config` folder. | ||
|
||
```bash | ||
$cd source/packages/services/<ServiceName>/config | ||
$touch .env | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"AWSAccountID": "<accountId>", | ||
"AWSProfileName": "<profileName>", | ||
"AWSProfileRegion": "ap-northeast-1", | ||
|
||
"Solution": "<solutionName>", | ||
"Environment": "dev", | ||
"App": "<appName>", | ||
|
||
"Version": "0.0.1", | ||
"Build": "0", | ||
"QualifierCustom": "hnb659fds", | ||
|
||
"LogLevel": "info" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Deployment services | ||
|
||
## 1. Update Rush configuration files | ||
|
||
Add your service project to | ||
|
||
* source/rush.json | ||
* source/common/config/rush/deploy.json | ||
|
||
![Add Rush Config](../docs/assets/add-rush-configs.png) | ||
|
||
## 1. Quick deploy | ||
|
||
This script will deploy all services under `source/packages/services` folder and its infrastructure to AWS. | ||
|
||
```sh | ||
$cd ~/ts-monorepo-microservices-boilerplate | ||
$chmod +x ./deployment/*.sh | ||
$./deployment/deploy_stacks.sh config/app-config-dev.json | ||
``` | ||
|
||
## 2. Single service deploy | ||
|
||
If you want to deploy a single service, you can use the following command. | ||
|
||
```sh | ||
$cd ~/source/packages/services/sample-service | ||
$npm run deploy:[dev|prod] | ||
``` | ||
|
||
## 3. Confirm deployed services | ||
|
||
```sh | ||
$ curl --location --request GET 'https://x6wlyex6pg.execute-api.ap-northeast-1.amazonaws.com/prod/canframes/?sort=asc' --header 'Accept: application/vnd.aws-cdf-v1.0+json' --header 'Content-Type: application/vnd.aws-cdf-v1.0+json' --header 'Content-Type: text/plain' | ||
{"canframemodels":[{"year":"2023","model":"sample1-01"},{"year":"2023","model":"sample1-02"}]} | ||
|
||
|
||
$ curl --location --request GET 'https://wnsjf6x03g.execute-api.ap-northeast-1.amazonaws.com/prod/canframes/?sort=asc' --header 'Accept: application/vnd.aws-cdf-v1.0+json' --header 'Content-Type: application/vnd.aws-cdf-v1.0+json' --header 'Content-Type: text/plain' | ||
{"canframemodels":[{"year":"2023","model":"sample2-01"},{"year":"2023","model":"sample2-02"}]} | ||
``` | ||
|
||
## 4. Destroy all services | ||
|
||
```sh | ||
$cd ~/ts-monorepo-microservices-boilerplate | ||
$chmod +x ./deployment/*.sh | ||
$./script/destroy_stacks.sh config/app-config-dev.json | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# Configuration File Path | ||
export GLOBAL_APP_CONFIG=$1 | ||
export PROJECT_STAGE=$(cat $GLOBAL_APP_CONFIG | jq -r '.Environment') #ex> development | ||
export SOLUTION_NAME=$(cat $GLOBAL_APP_CONFIG | jq -r '.Solution') | ||
export APP_NAME=$(cat $GLOBAL_APP_CONFIG | jq -r '.App') | ||
|
||
currntPWD=`pwd` | ||
cd ${currntPWD}/source/ | ||
|
||
echo ==--------CheckDedendencies---------== | ||
aws --version | ||
node --version | ||
npm --version | ||
cdk --version | ||
rush version | ||
pnpm --version | ||
git --version | ||
jq --version | ||
|
||
echo ==--------ConfigInfo---------== | ||
echo $GLOBAL_APP_CONFIG | ||
echo $AWS_PROFILE | ||
echo $PROJECT_STAGE | ||
echo $SOLUTION_NAME | ||
echo $APP_NAME | ||
echo . | ||
echo . | ||
|
||
echo ==--------BuildEnvironment---------== | ||
# rush purge | ||
rush install | ||
rush update | ||
rush rebuild | ||
|
||
echo . | ||
echo . | ||
|
||
echo "Build Stacks Completed" | ||
|
||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
# Configuration File Path | ||
export GLOBAL_APP_CONFIG=$1 | ||
export SERVICE_NAME=$2 | ||
export SOLUTION_NAME=$(cat $GLOBAL_APP_CONFIG | jq -r '.Solution') | ||
export APP_NAME=$(cat $GLOBAL_APP_CONFIG | jq -r '.App') | ||
export PROJECT_STAGE=$(cat $GLOBAL_APP_CONFIG | jq -r '.Environment') #ex> development | ||
|
||
echo ==--------ConfigInfo---------== | ||
echo "$GLOBAL_APP_CONFIG" | ||
echo "Profile: $AWS_PROFILE" | ||
echo "Env: $PROJECT_STAGE" | ||
echo "Solution: $SOLUTION_NAME" | ||
echo "App: $APP_NAME" | ||
echo "Service: $SERVICE_NAME" | ||
echo . | ||
echo . | ||
|
||
echo ==--------CreateServiceRepo---------== | ||
currntPWD=`pwd` | ||
cd ${currntPWD}/source/packages/services | ||
mkdir $SERVICE_NAME | ||
SAMPLE_REPO_DIR="${currntPWD}/source/packages/services/sample-service" | ||
cd $SAMPLE_REPO_DIR | ||
tar cf - --exclude="./dist" --exclude="./node_modules" --exclude="./cdk.out" . | (cd ${currntPWD}/source/packages/services/$SERVICE_NAME && tar xvf -) | ||
echo . | ||
echo . | ||
exit |
Oops, something went wrong.