1.7.0 • Published 2 years ago

bsl-microservice-stockrunner v1.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

bsl-microservice-stockrunner

Dropshipper microservice for stockrunner.

Getting Started

git clone git@github.com:deBijenkorf/bsl-microservice-stockrunner.git

Technologies

The tech stack core of the project:

  • Node - JavaScript runtime built on Chrome's V8 JavaScript engine
  • Express - web framework for Node.js
  • Typescript - typed superset of JavaScript that compiles to plain JavaScript

Prerequisites

To run the code in this repository you need to have the following installed on your machine:

  • node - Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.

Installing

  • run npm ci

Build and Development

Build

  • run npm run build, it will perform a type check on the Typescript files and create a build folder with js files
"build": "npm run type-check && npm run build:js"

Development

  • run npm run start:dev, uses nodemon

Tests and Risk Assessment

Unit tests

Runs all

npm run test

Watches all changed tests

npm run test:watch

Build JSON schema from XSD

Run npm run build:schema, this will create a order detail JSON schema file from the XML schema file This is necessary to validate the JSON object containing order information to create and upload order XMLs to the SFTP server.

API documentation

Swagger documentation UI can be viewed at:

{base_url}/api/docs

It is uses library called swagger-autogen that autogenerates a swagger.json based on endpoints that are present in the routes file (this can be configured to include other source files in swagger.js). To generate a new version of the swagger docs, run:

npm run swagger-autogen

To generate more details such as a request body or to organize by tags, these details can be added as comments inside the app route's middleware function. The schema definitions exist in the doc object in swagger.js. Example below:

const saveBody = () => {
/* #swagger.tags = ['Items']
  #swagger.parameters = {
    name: 'Items',
    'in': 'body',
    required: true,
    schema: { $ref: '#/definitions/bodyObject' }
  }
  #swagger.requestBody = {
    required: true,
    content: {
      "application/json": {
        schema: { $ref: '#/definitions/bodyObject' }
      }
    }
  }
  #swagger.responses[200] = {
    description: 'Save successful.',
  } */

  // save body code
}

Containerisation

This project is configured to be containerised using Docker. To build the docker container:

$ docker build . -t bsl-microservice-stockrunner

To run the container locally on port 3000:

docker run -dp 3000:8090 bsl-microservice-stockrunner

To run container with mySQL DB using docker-compose:

docker-compose up --build

Deployment

To create a release branch, do the following:

  • Create a release branch out from master.
  • Run npm run release to bump your version, create a CHANGELOG.md file and create a git tag
  • Merge the release branch with master
  • Make a deployment:
    • Go to the jenkins job project
    • Select Build with parameters
    • Enter the last commit hash in VERSION like this: 1.0.0-161e2c6
    • Press the Build button

Logs and Dashboards

Elasticsearch Logs

For the PROD logs check here

For the BAU logs check here

Elasticsearch Dashboards

Metrics To check Grafana dashboard click here.

Notes

  • To decrypt/encrypt secrets files, use these commands (in the kubernetes-dbk-apps project):
  1. Install Helm, sops and gpg2 on your machine.

    brew install gnupg gnupg2
    brew install sops
  2. Follow the rest of the setup instructions here.

  3. Configure your environment variables for Helm secrets at the root level of kubernetes-dbk-apps project.

    . ./configure_helm_secrets.sh
  4. Then run this command:

    helm secrets dec secrets.sit.yaml
    helm secrets enc secrets.sit.yaml
  • To run kubectl commands first log in to gcloud:

    ```bash
    gcloud auth application-default login
    ```

    (P.S. first run this command, before run the kubectl command)

  • To see the result of the DB connection (in the kubernetes-dbk-apps project):

    kubectl --context gke_dbk-ecom-dev_europe-west4_dbk-dev -n ceres-stockrunner logs -f deploy/ceres-stockrunner-sit ceres-stockrunner
  • To list pods, you can use this:
    kubectl get pods --all-namespaces
  • To connect to Mysql DB and see tables, use these commands:

    ```bash
    kubectl exec -ti ceres-stockrunner-sit-XXXX -c ceres-stockrunner -n ceres-stockrunner -- /bin/sh
    
    mysql -h 127.0.0.1 -P 3306 -u dropshipper-sit -p
    ```

    (P.S. You can find the right version of ceres-stockrunner-sit-XXXX when you list pods)

  • You can use this command if you want to use your local Mysql DB when running the NodeJS project :

    ```bash
    DB_HOST=localhost DB_USERNAME=root DB_PASSWORD=XXXX npm run start:dev
    ```

    (P.S. You need to assign a password to the root user to be able to run this command)

Ownership

This project is owned by the Omnichannel squad.

NameRoleEmail
Nilay GökirmakCaptainnilay.gokirmak@debijenkorf.nl
Amaka AtoyebiCaptainamaka.atoyebi@debijenkorf.nl
Adnan LabiadhCaptainadnan.labiadh@debijenkorf.nl