bsl-microservice-stockrunner
v1.7.0
Published
Dropshipper microservice
Downloads
2
Readme
bsl-microservice-stockrunner
Dropshipper microservice for stockrunner.
- Getting Started
- Technologies
- Build and Development
- Tests and Risk Assessment
- API documentation
- Containerisation
- Deployment
- Logs and Dashboards
- Notes
- Ownership
Getting Started
git clone [email protected]: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](https://d1e6859699ea42038e527617b73487a4.europe-west1.gcp.cloud.es.io/app/discover#/view/42665420-8826-11ec-bf7d-89dd1f6db379?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1w,to:now))&_a=(columns:!(url.path),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:b9f1f330-d59b-11ea-b12b-cbf585b1e45c,key:kubernetes.namespace_name,negate:!f,params:(query:ceres-stockrunner),type:phrase),query:(match_phrase:(kubernetes.namespace_name:ceres-stockrunner))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:b9f1f330-d59b-11ea-b12b-cbf585b1e45c,key:kubernetes.container_name,negate:!t,params:(query:cloudsqlproxy),type:phrase),query:(match_phrase:(kubernetes.container_name:cloudsqlproxy)))),grid:(),hideChart:!f,index:b9f1f330-d59b-11ea-b12b-cbf585b1e45c,interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc))))
For the BAU logs check [here](https://d1e6859699ea42038e527617b73487a4.europe-west1.gcp.cloud.es.io/app/discover#/view/2a600590-89b3-11ec-8d44-67153f7c93eb?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1w,to:now))&_a=(columns:!(url.path),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:b9f1f330-d59b-11ea-b12b-cbf585b1e45c,key:kubernetes.namespace_name,negate:!f,params:(query:ceres-stockrunner),type:phrase),query:(match_phrase:(kubernetes.namespace_name:ceres-stockrunner))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:cc1c4f50-d277-11ea-b12b-cbf585b1e45c,key:kubernetes.labels.env,negate:!f,params:(query:bau),type:phrase),query:(match_phrase:(kubernetes.labels.env:bau))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:cc1c4f50-d277-11ea-b12b-cbf585b1e45c,key:kubernetes.container_name,negate:!f,params:(query:ceres-stockrunner),type:phrase),query:(match_phrase:(kubernetes.container_name:ceres-stockrunner)))),grid:(),hideChart:!f,index:cc1c4f50-d277-11ea-b12b-cbf585b1e45c,interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc))))
Elasticsearch Dashboards
Metrics To check Grafana dashboard click here.
Notes
- To decrypt/encrypt secrets files, use these commands (in the
kubernetes-dbk-apps
project):
Install Helm, sops and gpg2 on your machine.
brew install gnupg gnupg2
brew install sops
Follow the rest of the setup instructions here.
Configure your environment variables for Helm secrets at the root level of
kubernetes-dbk-apps
project.. ./configure_helm_secrets.sh
Then run this command:
helm secrets dec secrets.sit.yaml helm secrets enc secrets.sit.yaml
- To run
kubectl
commands first log in togcloud
: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:
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 :
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.
| Name | Role | Email | | ------------------ | ------- | --------------------------------- | | Nilay Gökirmak | Captain | [email protected] | | Amaka Atoyebi | Captain | [email protected] | | Adnan Labiadh | Captain | [email protected] |