1.0.0 • Published 7 months ago

siena-backend-msvc-template v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Siena Backend Repository Boilerplate

Installation Steps

  1. Clone the respository
git clone git+https://github.com/siena-ai/siena-backend-msvc-template.git
  1. Create a .env file in the root directory as shown in .env.example.
  2. Install the dependencies
npm install
  1. Launch the server
npm start

Migrations

  1. 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.
  2. Create one js file corresponding to each table in the database.
  3. 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"
  1. Run the following command to apply the migrations
npm run latest
  1. 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

OPTIONSDESCRIPTION
-t | --tagTag of your docker image (beta, latest, version x.x.x ...)
-r | --repositoryYour aws image repository (You should push same image to same repository)
-p | --profileYour aws profile name for ecr
-n | --nameImage name

COMMAND

COMMANDDESCRIPTION
releasePush image to aws ecr
buildBuild image with tag version and tag latest
authLogin 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 open credentials. And add below of default 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 all nameConvention 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>,
  • 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
  • Then check your envs in mesh-stack.ts and mesh-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 run cdk destroy --profile siena --all because it removes whole infrastructure and makes app down. If needed contact murodjon@cartloop.io or rajan@.cartloop.io.