Skip to content

Commit

Permalink
Use Node 20 runtime in Docker image (#410)
Browse files Browse the repository at this point in the history
- Code remains compatible with Node 18.
- Project continues to be built and tested with Node 18.
- Node 20 is used as the runtime for the nodeenv Docker image to allow chaincode access to latest Node features and security fixes.

Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday authored May 28, 2024
1 parent a1f421b commit 44c95bd
Show file tree
Hide file tree
Showing 28 changed files with 150 additions and 137 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 }}
11 changes: 0 additions & 11 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,7 +110,6 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ yarn.lock
**/typescript/*.js.map

fabric*.tgz
install-fabric.sh

libraries/fabric-ledger/lib

Expand All @@ -28,6 +29,7 @@ common/temp/**
**/.rush/temp/**
**/*.build.error.log
**/*.build.log
**/*.test_fv.log

package-deps.json
test-results.xml
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
2 changes: 1 addition & 1 deletion common/scripts/install-run-rush-pnpm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions common/scripts/install-run-rush.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/scripts/install-run-rushx.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 44c95bd

Please sign in to comment.