Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(mojaloop/#3522): upgrade nodejs version #167

Merged
merged 52 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a79489b
chore: upgrade nodejs version
aaronreynoza Sep 13, 2023
ed434e1
update dependencies and tests libraries
aaronreynoza Sep 13, 2023
f089240
update tests to newer library implementation
aaronreynoza Sep 13, 2023
caf8490
upgrade nodejs version .nvmrc
aaronreynoza Sep 13, 2023
ae4a966
change jest mocked function implementation
aaronreynoza Sep 14, 2023
1aa36bd
update packages, ts config, fix tests
aaronreynoza Sep 15, 2023
599478e
update tests
aaronreynoza Sep 18, 2023
71dcd7a
reduce failing tests to 3
aaronreynoza Sep 18, 2023
6885575
upgraded all unit tests to jest v29
aaronreynoza Sep 18, 2023
f79d457
lint
aaronreynoza Sep 18, 2023
4cfa810
fix integration and definition tests
aaronreynoza Sep 18, 2023
a0e3101
fix dependencies
aaronreynoza Sep 18, 2023
217ff61
fix junit
aaronreynoza Sep 18, 2023
dd11818
readd test bdd
aaronreynoza Sep 19, 2023
0a5b057
change wait4docker method
aaronreynoza Sep 19, 2023
4ae9b1b
update tests config for ci
aaronreynoza Sep 19, 2023
3ee3bad
update test-bdd dependency install method
aaronreynoza Sep 19, 2023
ef799f6
restore wait4
aaronreynoza Sep 19, 2023
1e9bb24
npm dep update
aaronreynoza Sep 19, 2023
979f3a1
update wait4 npm command
aaronreynoza Sep 19, 2023
b6fc0ea
change wait4docker method
aaronreynoza Sep 19, 2023
d779069
change integration tests curl port
aaronreynoza Sep 19, 2023
9e64b4f
remove curl
aaronreynoza Sep 19, 2023
e1534d8
update readme
aaronreynoza Sep 20, 2023
0402540
update dependencies
aaronreynoza Sep 20, 2023
51b9e96
log docker version on integration tests
aaronreynoza Sep 20, 2023
6eb2fae
update dependencies
aaronreynoza Sep 20, 2023
f734780
update docker in default-machine configs
aaronreynoza Sep 20, 2023
518b7f9
move docker upgrade at the setup start
aaronreynoza Sep 20, 2023
a55f373
update docker upgrade method
aaronreynoza Sep 20, 2023
3437cee
change docker upgrade method
aaronreynoza Sep 20, 2023
4b53d7a
revert
aaronreynoza Sep 20, 2023
86eafcb
add caching to docker-compose
aaronreynoza Sep 20, 2023
c8b35b9
change image name
aaronreynoza Sep 20, 2023
9268217
add image to docker-compose
aaronreynoza Sep 20, 2023
d33216f
remove curl to healthcheck
aaronreynoza Sep 20, 2023
106be57
change redis host
aaronreynoza Sep 20, 2023
2b337fc
change docker integration config redis endpoint
aaronreynoza Sep 20, 2023
6fbcbee
update dependencies
aaronreynoza Sep 20, 2023
3b1db13
update readme docs for redis
aaronreynoza Sep 20, 2023
d7e1a70
update more ports
aaronreynoza Sep 20, 2023
d1f24db
doc updates
aaronreynoza Sep 20, 2023
2c69b76
it was the wait4 script hehe
aaronreynoza Sep 20, 2023
3518296
change integration tests command
aaronreynoza Sep 20, 2023
8f139cf
correct hosts
aaronreynoza Sep 20, 2023
ffb45fe
add wait4containers script
aaronreynoza Sep 20, 2023
c582d25
parsing
aaronreynoza Sep 20, 2023
1831d95
setup compose healthcheck
aaronreynoza Sep 20, 2023
86b057f
setup redis host
aaronreynoza Sep 20, 2023
f6a4432
remove unnecesary dependencies
aaronreynoza Sep 21, 2023
6bd493a
fix husky
aaronreynoza Sep 21, 2023
b6b93f5
remove unused dependencies
aaronreynoza Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
502 changes: 348 additions & 154 deletions .circleci/config.yml

Large diffs are not rendered by default.

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