siena-backend-msvc-template
v1.0.0
Published
Siena Microservice backend template repository
Downloads
10
Readme
Siena Backend Repository Boilerplate
Installation Steps
- Clone the respository
git clone git+https://github.com/siena-ai/siena-backend-msvc-template.git
- Create a
.env
file in the root directory as shown in.env.example
. - Install the dependencies
npm install
- Launch the server
npm start
Migrations
- With every version upgrade, create a folder with version in the
migrations
folder. Example: For version 2.0.0, make a folder named 2.0.0 in the migrations directory. - Create one js file corresponding to each table in the database.
- Run the following command to create the migrations file. This would create a migration file inside the migrations folder. Create the up and down function in this migration file to upgrade to the next version or to undo the changes respectively.
npm run make --name "version_name"
ex: npm run make --name "1.0.0"
- Run the following command to apply the migrations
npm run latest
- Run the following command to undo the changes
npm run rollback
How to deploy
Manual build Docker image and push to Ecr
.env
File content to run commands. Please put theses to your file
REPO=<image repository uri>
APP_NAME=<image name>
PROFILE=<aws profile name>
You can build and push image to Ecr like below:
sh imageEcr.sh [OPTIONS] COMMAND
For example:
sh imageEcr.sh auth -> Login with your aws profile
sh imageEcr.sh build -> Build image, by default latest image
sh imageEcr.sh release -> Push to Ecr
sh imageEcr.sh -t <tag> build -> Builds the image with given tag
Local
You can also run Docker locally in your system. Run this command
npm run docker-build
If you want to pass options when running script, you could create .env file and define variables which using in script.
OPTIONS
| OPTIONS | DESCRIPTION | | ------------------ | ------------------------------------------------------------------------- | | -t | --tag | Tag of your docker image (beta, latest, version x.x.x ...) | | -r | --repository | Your aws image repository (You should push same image to same repository) | | -p | --profile | Your aws profile name for ecr | | -n | --name | Image name |
COMMAND
| COMMAND | DESCRIPTION | | ------- | ------------------------------------------- | | release | Push image to aws ecr | | build | Build image with tag version and tag latest | | auth | Login to Aws Ecr with authenticated profile |
If you dont pass no command script only build your image according to given options.
CDK
Install aws cli & Setup profile to your cli.
- Stick to this doc
- Then go tou your
.aws
folder, and opencredentials
. And add below ofdefault
this
[siena]
aws_access_key_id=<your access key>
aws_secret_access_key=<you secret acces key>
Then go to cdk
folder and run these commands
First time setup cdk to microservice
First go to
cdk/bin/app.ts
file and here change allnameConvention
to the proper one.While changing do'nt change constant values that like
arn
or cluster names which are.Start Changing from
devStack
.- First create ECR repo on aws.
- nameConvention: "dev-000-
<your cervice>
, - imageTag:
tag of image if you build manually
, - imageName:
here is you ECR repo name
, - apiHealthPath:
the health path of service
, - apiPathPattern: [
path pattern for all pathes
], - targetPriority:
Count services and here put the number of your service, such as if there is 4 services before the new one, then put here 5.
, - serviceDesiredCount:
The count of services for app
,
Then move to
proxyData
.- Change nameConvention: "dev-000-
<your cervice>
,
- Change nameConvention: "dev-000-
Then move to
cicdData
.- Change nameConvention: "dev-000-
<your cervice>
, - imageTag:
the tag of image if first time
, - imageName:
your image ecr repo name
, - githubRepository:
repo name of your service
, - branch:
branch that you want ci/cd
- Change nameConvention: "dev-000-
Then check your envs in
mesh-stack.ts
andmesh-stack-cicd.ts
files that are from getting Secrets manager. You should create Secrets manger secret for you service and change the name from this two files that are used with your new secret name.After you done it. The run below commands.
cdk synth --profile siena --all
run to synthesize the cdk.cdk diff --profile siena --all
check the diff from old version.cdk deploy --profile siena --all
deploy app to aws.Disclamer:
Not runcdk destroy --profile siena --all
because it removes whole infrastructure and makes app down. If needed contact[email protected]
or[email protected]
.