Skip to content

Commit

Permalink
chore(mojaloop/#3522): upgrade nodejs version (#167)
Browse files Browse the repository at this point in the history
* chore: upgrade nodejs version

* update dependencies and tests libraries

* update tests to newer library implementation

* upgrade nodejs version .nvmrc

* change jest mocked function implementation

* update packages, ts config, fix tests

* update tests

* reduce failing tests to 3

* upgraded all unit tests to jest v29

* lint

* fix integration and definition tests

* fix dependencies

* fix junit

* readd test bdd

* change wait4docker method

* update tests config for ci

* update test-bdd dependency install method

* restore wait4

* npm dep update

* update wait4 npm command

* change wait4docker method

* change integration tests curl port

* remove curl

* update readme

* update dependencies

* log docker version on integration tests

* update dependencies

* update docker in default-machine configs

* move docker upgrade at the setup start

* update docker upgrade method

* change docker upgrade method

* revert

* add caching to docker-compose

* change image name

* add image to docker-compose

* remove curl to healthcheck

* change redis host

* change docker integration config redis endpoint

* update dependencies

* update readme docs for redis

* update more ports

* doc updates

* it was the wait4 script hehe

* change integration tests command

* correct hosts

* add wait4containers script

* parsing

* setup compose healthcheck

* setup redis host

* remove unnecesary dependencies

* fix husky

* remove unused dependencies
  • Loading branch information
aaronreynoza authored Sep 21, 2023
1 parent 79660f5 commit a1b0523
Show file tree
Hide file tree
Showing 58 changed files with 22,503 additions and 35,030 deletions.
486 changes: 332 additions & 154 deletions .circleci/config.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

git update-index --again
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint && npm run test
7 changes: 0 additions & 7 deletions .ncurc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
module.exports = {
reject: [
// Upgrading past husky@4 to involves a full config migration with no current and apparent benefit.
// So we are just sticking to husky@4.x.x for the time being.
'husky',
// Caution advised in upgrading redis-mock past 0.52.0. Investigation needed.
'redis-mock',
// Upgrading past redis@3 to the next major version introduces a lot of breaking changes.
'redis',
'@types/redis',
// Upgrading past jest|ts-jest|@types/jest@26 introduces a lot of breaking changes to current tests.
'jest',
'ts-jest',
'@types/jest',
// Upgrading past commander@7 introduces a lot of breaking changes.
'commander'
]
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.0
18.17.1
42 changes: 27 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
FROM node:16.15.0-alpine as builder
USER root

# Arguments
ARG NODE_VERSION=lts-alpine

# NOTE: Ensure you set NODE_VERSION Build Argument as follows...
#
# export NODE_VERSION="$(cat .nvmrc)-alpine" \
# docker build \
# --build-arg NODE_VERSION=$NODE_VERSION \
# -t mojaloop/sdk-scheme-adapter:local \
# . \
#

# Build Image
FROM node:${NODE_VERSION} as builder
WORKDIR /opt/app

RUN apk update \
&& apk add --no-cache -t build-dependencies git make gcc g++ python3 libtool autoconf automake openssh \
&& cd $(npm root -g)/npm \
&& npm config set unsafe-perm true \
&& npm install -g node-gyp
RUN apk --no-cache add git
RUN apk add --no-cache -t build-dependencies make gcc g++ python3 libtool openssl-dev autoconf automake bash \
&& cd $(npm root -g)/npm

COPY package.json package-lock.json* /opt/app/

RUN npm ci

COPY ./ /opt/app/
RUN npm run build
RUN rm -rf src secrets test docs
RUN npm prune --production


FROM node:16.15.0-alpine
WORKDIR /opt/app/
FROM node:${NODE_VERSION}
WORKDIR /opt/app

# Create empty log file & link stdout to the application log file
RUN mkdir ./logs && touch ./logs/combined.log
RUN ln -sf /dev/stdout ./logs/combined.log

# Create a non-root user: app-user
RUN adduser -D app-user
USER app-user
COPY --chown=app-user --from=builder /opt/app/ ./
# Create a non-root user: ml-user
RUN adduser -D ml-user
USER ml-user

COPY --chown=ml-user --from=builder /opt/app .
RUN npm prune --production

EXPOSE 4005 4006
CMD ["npm", "run", "start"]
42 changes: 4 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,12 @@ This package exemplifies the use of the Mojaloop SDK Standard Components for TLS
```bash
npm install
```
3. Modify the hosts to setup local DNS for Redis
3. Start servers
```bash
127.0.0.1 redis
```
4. Start Redis container through docker-compose in a separate terminal window
```bash
docker-compose up redis
```
5. Start Inbound API server
```bash
npm run start:inbound
```
then visit in your web browser http://localhost:4005/health

In case to start the test environment
```bash
NODE_ENV=test npm run start:inbound
```
6. Start Outbound API server
```bash
npm run start:outbound
```
then visit in your web browser http://localhost:4006/health

In case to start the test environment
```bash
NODE_ENV=test npm run start:outbound
npm run start
```
then visit in your web browser for outbound API http://localhost:4006/health
and inbound API http://localhost:4005/health

## Inbound & Outbound API
> This package delivers implementation Inbound and Outbound API services which will be used by Thirdparty to integrate with `Mojaloop Switch`
Expand Down Expand Up @@ -143,18 +121,6 @@ This package exemplifies the use of the Mojaloop SDK Standard Components for TLS
docker-compose build && docker-compose up
```

then start `docker-compose` inside `docker` folder in a separate window.
```bash
cd docker
docker-compose build && docker-compose up
```

then start `docker-compose` inside `docker/contract` folder in a separate window.
```bash
cd docker/contract
docker-compose build && docker-compose up
```

Finally run the following command to execute tests
```bash
npm run test:integration
Expand Down
20 changes: 20 additions & 0 deletions audit-ci.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json",
// audit-ci supports reading JSON, JSONC, and JSON5 config files.
// Only use one of ["low": true, "moderate": true, "high": true, "critical": true]
"moderate": true,
"allowlist": [ // NOTE: Please add as much information as possible to any items added to the allowList
// Currently no fixes available for the following
"GHSA-v88g-cgmw-v5xw",
"GHSA-phwq-j96m-2c2q",
"GHSA-282f-qqgm-c34q",
"GHSA-6vfc-qv3f-vr6c",
"GHSA-wc69-rhjr-hc9g",
"GHSA-g954-5hwp-pp24",
"GHSA-h755-8qp9-cq85",
"GHSA-mjxr-4v3x-q3m4",
"GHSA-rjqq-98f6-6j3r",
"GHSA-f9xv-q969-pqx4",
"GHSA-p9pc-299p-vxgp"
]
}
2 changes: 1 addition & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"redis": {
"port": 6379,
"host": "localhost",
"host": "redis",
"timeout": 100
},
"inspect": {
Expand Down
17 changes: 8 additions & 9 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ npm run release
```
before pushing changes to remote repository. The [CHANGELOG.md](CHANGELOG.md) file will be generated.

## Code Audit
There are two `npm script` commands dedicated to code audit:
## Auditing Dependencies

We use `audit-ci` along with `npm audit` to check dependencies for node vulnerabilities, and keep track of resolved dependencies with an `audit-ci.jsonc` file.

To start a new resolution process, run:

`audit:check` is used to check vulnerability in code dependencies
```bash
npm run audit:check
npm run audit:fix
```
This command is run as guard in CI/CD pipeline to ensure our code is not vulnerable.

You can then check to see if the CI will pass based on the current dependencies with:

`audit:resolve` should be used to resolve audit problems.
Generated `audit-resolve.json` file should be committed,
elsewhere CI/CD pipeline will stop with error in case of any audit problems.
```bash
npm run audit:resolve
npm run audit:check
```

The [audit-ci.jsonc](./audit-ci.jsonc) contains any audit-exceptions that cannot be fixed to ensure that CircleCI will build correctly.
## Pre-commit hook
> Pull Requests with broken code will not be accepted to merge.
Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ networks:

services:
thirdparty-sdk:
image: mojaloop/thirdparty-sdk:local
container_name: thirdparty-sdk
build:
context: ./
context: .
dockerfile: ./Dockerfile
command: sh -c "/opt/thirdparty-sdk/wait4/wait4.js thirdparty-sdk && NODE_ENV=integration npm run start"
volumes:
- ./docker/wait4:/opt/thirdparty-sdk/wait4
cache_from:
- mojaloop/thirdparty-sdk
command: sh -c "NODE_ENV=integration npm run start"
environment:
- NODE_ENV=integration
# - CONTROL_MGMT_API_WS_URL=172.17.0.1
Expand Down
4 changes: 2 additions & 2 deletions docker/wait4/wait4.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
},
{
description: 'Redis Cache',
uri: 'localhost:6379',
uri: '0.0.0.0:6379',
method: 'ncat'
},
{
Expand Down Expand Up @@ -60,7 +60,7 @@ module.exports = {
wait4: [
{
description: 'Redis Cache',
uri: 'redis:6379',
uri: '0.0.0.0:6379',
method: 'ncat'
}
]
Expand Down
2 changes: 1 addition & 1 deletion jest.bdd.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const { pathsToModuleNameMapper } = require('ts-jest/utils')
const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig')
module.exports = {
verbose: true,
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const { pathsToModuleNameMapper } = require('ts-jest/utils')
const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig')
module.exports = {
verbose: true,
Expand Down
2 changes: 1 addition & 1 deletion jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const { pathsToModuleNameMapper } = require('ts-jest/utils')
const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig')
module.exports = {
roots: ['<rootDir>/src/', '<rootDir>/test/integration'],
Expand Down
Loading

0 comments on commit a1b0523

Please sign in to comment.