Skip to content

Commit

Permalink
Use Node 20 in runtime Docker image
Browse files Browse the repository at this point in the history
- Build, package and run unit tests with Node 18 to ensure compatibility.
- Remove use of fs-extra since the standard Node fs package provides all required functionality.

Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Mar 3, 2024
1 parent 6126c09 commit 52392da
Show file tree
Hide file tree
Showing 55 changed files with 2,787 additions and 1,506 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repository:
homepage: https://wiki.hyperledger.org/display/fabric
default_branch: main
has_downloads: true
has_issues: false
has_issues: true
has_projects: false
has_wiki: false
archived: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
name: Pull request success
runs-on: ubuntu-latest
steps:
- run: true
- run: 'true'
5 changes: 0 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
workflow_dispatch:

env:
CHAINCODE_CONTAINER_NODE_VER: 18
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}

jobs:
Expand Down Expand Up @@ -47,15 +46,13 @@ jobs:
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
uses: actions/checkout@v4

Expand Down Expand Up @@ -86,5 +83,3 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NODE_VER=${{ env.CHAINCODE_CONTAINER_NODE_VER }}
12 changes: 0 additions & 12 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
BUILD_DATE: ${{ steps.builddata.outputs.BUILD_DATE }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: BuildData
id: builddata
run: |
Expand All @@ -41,7 +38,6 @@ jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -61,19 +57,16 @@ jobs:
with:
name: TestResults
path: ./**/test-results.xml

- name: Build Binaries
run: |
set -xev
node common/scripts/install-run-rush.js publish --include-all --pack --release-folder tgz --publish
docker image save hyperledger/fabric-nodeenv | gzip > fabric-nodeenv.tar.gz
- uses: actions/upload-artifact@v4
name: Binaries
with:
name: node-tgzs
path: tgz/

- uses: actions/upload-artifact@v4
name: Docker
with:
Expand All @@ -88,7 +81,6 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '18.x'

- uses: actions/download-artifact@v4
with:
name: nodeenv-docker-image
Expand All @@ -97,7 +89,6 @@ jobs:
with:
name: node-tgzs
path: build/

- name: Setup the fv build
env:
PIPELINE_WORKSPACE: workspace
Expand All @@ -111,7 +102,6 @@ jobs:
node common/scripts/install-run-rush.js update # should the tests need 'building' this will need to go here
node common/scripts/install-run-rush.js start-fabric
node common/scripts/install-run-rush.js start-verdaccio # script will check for the ci variable and use built images
- name: Run the FV Tests
run: |
set -xev
Expand All @@ -120,15 +110,13 @@ jobs:
node common/scripts/install-run-rush.js test:fv --verbose
node common/scripts/install-run-rush.js test:e2e --verbose
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
name: TestLogs
with:
name: TestLogs
path: "**/*.build.log"


# Job to handle the auditing of the code
# NPM audit is run on a 'fake' installation of the libraries
# Pulling in all the dependencies it will be able to run NPM AUDIT, and if that returns a
Expand Down
41 changes: 19 additions & 22 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ Github is used for code base management, issues should reported in the repositor

This table shows the summary of the compatibility of the Node modules at versions 1.4 and 2.x, together with the Node.js runtime they require and the Fabric Peer versions they can communicate with.

| | Peer Connectivity v1.4 | Supported NodeJS | Peer Connectivity v2.x |
| ------------------------------ | ---------------------- | ---------------- | ---------------------- |
| Node modules **v1.4.5** | Yes | 8 | Yes |
| Node modules **v2.2.x/v2.3.x** | Yes | 12 | Yes |
| Node modules **v2.4.x** | Yes | 16 | Yes |
| Node modules **v2.5.x** | Yes | 18 | Yes |
| Chaincode Docker image | Peer connectivity v1.4 | Peer connectivity v2.x | Minimum supported Node.js | Node.js runtime |
| --- | --- | --- | --- | --- |
| **v1.4.5** | Yes | Yes | 8 | 8 |
| **v2.2.x** | Yes | Yes | 12 | 12 |
| **v2.3.x** | Yes | Yes | 12 | 12 |
| **v2.4.x** | Yes | Yes | 16 | 16 |
| **v2.5.0** - **v2.5.4** | Yes | Yes | 18 | 18 |
| **v2.5.5+** | Yes | Yes | 18 | 20 |

Whilst these are defaults based on the corresponding `fabric-nodeenv` Docker image version, the Docker image used to host the chaincode and contracts can be altered. Set the environment variable `CORE_CHAINCODE_NODE_RUNTIME` on the peer to the name of the desired Docker image and version.

* Fabric peer v1.4 will create a Node.js v8 runtime
* Fabric peer v2.2/2.3 will create a Node.js 12 runtime
* Fabric peer v2.4 will create a Node.js 16 runtime
* Fabric peer v2.5 will create a Node.js 18 runtime

Whilst these are defaults based on the corresponding `fabric-nodeenv` docker image version, the docker image used to host the chaincode and contracts can be altered. Set the environment variable `CORE_CHAINCODE_NODE_RUNTIME` on the peer to the name of the desired docker image and version.

For example `CORE_CHAINCODE_NODE_RUNTIME=hyperledger/fabric-nodeenv:2.2` will allow the use of the latest Node 12 runtime to be used within a Peer v1.4.
For example `CORE_CHAINCODE_NODE_RUNTIME=hyperledger/fabric-nodeenv:2.2` will allow the use of a Node 12 runtime to be used within a Peer v1.4.

The Node chaincode modules will connect to the peer whilst running; this is referred to as 'Fabric Peer Connectivity' in the table. For example, whilst the Fabric Peer v1.4 will create a Node.js 8 runtime, if a Node.js 12 runtime was configured, the node chaincode modules at v2.x still function when connecting to the Fabric Peer v1.4.

Expand All @@ -39,7 +35,7 @@ The key elements are :
- the version of the Node.js runtime used to run the code
- When starting a chaincode container to run a Smart Contract, the version of the runtime that is used is determined by these factors:

Fabric v1.4.x, and Fabric v2.x will, by default, start up a docker container based on `fabric-nodeenv` to host the chaincode and contracts. The version of the docker image used is driven by the version of Fabric in use, but can be overridden by setting the peer's `CORE_CHAINCODE_NODE_RUNTIME` environment variable.
Fabric v1.4.x, and Fabric v2.x will, by default, start up a Docker container based on `fabric-nodeenv` to host the chaincode and contracts. The version of the Docker image used is driven by the version of Fabric in use, but can be overridden by setting the peer's `CORE_CHAINCODE_NODE_RUNTIME` environment variable.

With Fabric v2.x, the chaincode container can be configured to be started by other means, and not the Peer. In this case, the environment used is not in the control of Fabric.

Expand All @@ -50,19 +46,20 @@ Node modules that are produced are `fabric-contract-api`, `fabric-shim` & `fabri
* Fabric v1.4 Node.js chaincode modules are supported running Nodejs 8.16.1 with the x86_64 architecture.
* Fabric v2.2/v2.3 Node.js chaincode modules are supported running in Node.js 12.22.6, with the x86_64 architecture.
* Fabric v2.4 Node.js chaincode modules are supported running in Node.js 16.x, with the x86_64 architecture.
* Fabric v2.5 Node.js chaincode modules are supported running in Node.js 18.x, with the x86_64 and arm64 architectures.
* Fabric v2.5.x Node.js chaincode modules are supported running in Node.js 18.x, with the x86_64 and arm64 architectures.

Architecture Support: all docker images, runtimes, tools are tested under x86_64 ONLY
Architecture Support: all Docker images, runtimes, tools are tested under x86_64 ONLY

### Default Peer Runtime selection

* Fabric 2.2/2.3 `fabric-nodeenv` docker image is based on node:12.22.6-alpine.
* Fabric 2.4 `fabric-nodeenv` docker image is based on node:16-alpine.
* Fabric 2.5 `fabric-nodeenv` docker image is based on node:18-alpine.
* Fabric 2.2/2.3 `fabric-nodeenv` Docker image is based on node:12.22.6-alpine.
* Fabric 2.4 `fabric-nodeenv` Docker image is based on node:16-alpine.
* Fabric 2.5.0 - 2.5.4 `fabric-nodeenv` Docker image is based on node:18-alpine.
* Fabric 2.5.5+ `fabric-nodeenv` Docker image is based on node:20-alpine.

*Note:* With the default docker image used by Fabric 2.x, the packaged code will be installed with npm. If a `package-lock.json` or a `npm-shrinkwrap.json` file is present, `npm ci --only=production` will be used. Otherwise `npm install --production` will be used. 
*Note:* With the default Docker image used by Fabric 2.x, the packaged code will be installed with npm. If a `package-lock.json` or a `npm-shrinkwrap.json` file is present, `npm ci --only=production` will be used. Otherwise `npm install --production` will be used. 

When using Fabric 1.4.x, the docker image that is used to run the Node.js chaincode is node v8.16.1. It is installed with npm install --production
When using Fabric 1.4.x, the Docker image that is used to run the Node.js chaincode is node v8.16.1. It is installed with npm install --production

### Supported Runtime communication with the Peer

Expand Down
3 changes: 1 addition & 2 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
"name": "chaincode",
"description": "My first exciting chaincode implemented in node.js",
"engines": {
"node": "^12.16.1",
"npm": "^6.4.1"
"node": ">=18"
},
"scripts": {
"test": "mocha....."
Expand Down
11 changes: 6 additions & 5 deletions apis/fabric-contract-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Fabric Shim"
],
"engines": {
"node": "^18.0.0"
"node": ">=18"
},
"license": "Apache-2.0",
"types": "./types/index.d.ts",
Expand All @@ -45,28 +45,29 @@
"lines": 100
},
"dependencies": {
"class-transformer": "^0.5.1",
"fabric-shim-api": "2.5.4",
"class-transformer": "^0.4.0",
"fast-safe-stringify": "^2.1.1",
"get-params": "^0.1.2",
"reflect-metadata": "^0.1.13",
"winston": "^3.7.2"
},
"devDependencies": {
"@tsconfig/node18": "^18.2.2",
"ajv": "^6.12.2",
"ajv-cli": "^3.2.1",
"ajv-formats": "2.1.1",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-things": "^0.2.0",
"eslint": "^6.6.0",
"eslint": "^8.57.0",
"gulp": "^4.0.2",
"gulp-debug": "~4.0.0",
"gulp-eslint": "~6.0.0",
"gulp-eslint": "^6.0.0",
"mocha": "9.1.3",
"nyc": "15.1.0",
"rewire": "6.0.0",
"sinon": "13.0.1",
"typescript": "4.4.4"
"typescript": "5.2.2"
}
}
11 changes: 4 additions & 7 deletions apis/fabric-contract-api/test/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
*/
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"sourceMap": true,
"lib": [
"esnext"
]
"sourceMap": true
},
"exclude": [
"node_modules"
"node_modules"
]
}
34 changes: 0 additions & 34 deletions apis/fabric-contract-api/types/tsconfig.json

This file was deleted.

3 changes: 1 addition & 2 deletions apis/fabric-shim-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"Fabric Shim"
],
"engines": {
"node": "^18.0.0",
"eslint": "^6.6.0"
"node": ">=18"
},
"types": "./types/index.d.ts",
"license": "Apache-2.0",
Expand Down
37 changes: 0 additions & 37 deletions apis/fabric-shim-api/types/tsconfig.json

This file was deleted.

Loading

0 comments on commit 52392da

Please sign in to comment.