Skip to content

Commit 4797987

Browse files
Use Node 24 in Docker image with Node 18 minimum
Node 24 is the latest LTS release and is used as the runtime in the fabric-nodeenv Docker image to provide access to the latest features and performance improvements. Node 20 is now the minimum supported version since Node 18 is no longer supported. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
1 parent a750bac commit 4797987

File tree

27 files changed

+93
-110
lines changed

27 files changed

+93
-110
lines changed

.github/workflows/scan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
ref: ${{ inputs.ref }}
2626
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
2727
with:
28-
node-version: 18
28+
node-version: "lts/*"
2929
- name: Install
3030
run: node common/scripts/install-run-rush.js install
3131
- name: Build packages

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4343
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
4444
with:
45-
node-version: "18.x"
45+
node-version: "20.x"
4646
- name: Install/Rebuild/UnitTest
4747
run: |
4848
set -xev
@@ -80,7 +80,7 @@ jobs:
8080
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8181
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
8282
with:
83-
node-version: "18.x"
83+
node-version: "20.x"
8484
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
8585
with:
8686
name: nodeenv-docker-image

TUTORIAL.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
1515
"name": "chaincode",
1616
"description": "My first exciting chaincode implemented in node.js",
1717
"engines": {
18-
"node": ">=18"
18+
"node": ">=20"
1919
},
2020
"scripts": {
2121
"test": "mocha....."
@@ -33,6 +33,7 @@ The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
3333
}
3434
3535
```
36+
3637
Remember to add in any additional business logic, and testing libraries needed
3738

3839
Adding `fabric-shim` as a dependency, gives a command `fabric-chaincode-node` that is the script to run for `npm start`.
@@ -45,7 +46,6 @@ Adding `fabric-shim` as a dependency, gives a command `fabric-chaincode-node` th
4546
},
4647
```
4748

48-
4949
### 2: How is chaincode deployed?
5050

5151
Chaincode is deployed by the peer in response to issuing a number of (usually CLI) commands. For node.js chaincode the location of the chaincode npm project is required (the directory that the package.json is in). This does not need to be an installed project, but has to have all the code, and the package.json.
@@ -54,7 +54,7 @@ A docker image is built for this chaincode, the package.json and code copied in.
5454

5555
After the install there is a 'bootstrap' process that starts the chaincode up (more details later). The constructors of the exported Contracts will be run at this point; these constructors are for setting the name and optional setup of the 'error/monitoring functions', (again more later). This instance of the contract will existing whilst this chaincode docker image is up.
5656

57-
When chaincode is instantiated or updated, the `init()` function in the chaincode is called. As with the `invoke()` call from the client, a fn name and parameters can be passed. Remember therefore to have specific functions to call on `init()` and `update()` in order to do any data initialisation or migration that might be needed. These two functions have been abstracted away to focus on specific function implementations.
57+
When chaincode is instantiated or updated, the `init()` function in the chaincode is called. As with the `invoke()` call from the client, a fn name and parameters can be passed. Remember therefore to have specific functions to call on `init()` and `update()` in order to do any data initialisation or migration that might be needed. These two functions have been abstracted away to focus on specific function implementations.
5858

5959
It is strongly recommended to use the npm shrinkwrap mechanism so the versions of the modules that are used are fixed.
6060

@@ -77,7 +77,7 @@ module.exports.contracts = [UpdateValues, RemoveValues];
7777
```
7878

7979
This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
80-
*Note that the 'contracts' word is mandatory.*
80+
_Note that the 'contracts' word is mandatory._
8181

8282
### 4: What do these classes need to contain?
8383

@@ -159,15 +159,13 @@ Then you can invoke the chaincode via this command.
159159
$ peer chaincode invoke --orderer localhost:7050 --channelID mychannel -c '{"Args":["UpdateValuesContract:getAssetValue"]}' -n mycontract4
160160
```
161161

162-
163162
## Additional support provided by the SmartContract class
164163

165164
In case you ask for a function to be executed, it could be that this doesn't exist.
166165
If so, you can provide you own function to be executed, the default is to throw and error but you're able to customise this if you wish.
167166

168167
For example
169168

170-
171169
```
172170
/**
173171
* Sets a name so that the functions in this particular class can
@@ -206,14 +204,14 @@ async aroundTransaction(ctx, fn, parameters) {
206204

207205
### Structure of the Transaction Context
208206

209-
In Fabric, there is a *stub* api that provides chaincode with functionality.
207+
In Fabric, there is a _stub_ api that provides chaincode with functionality.
210208
No functionality has been removed, but a new approach to providing abstractions on this to facilitate programming.
211209

212-
*user additions*: additional properties can be added to the object to support for example common handling of the data serialization.
210+
_user additions_: additional properties can be added to the object to support for example common handling of the data serialization.
213211

214212
The context object contains
215213

216-
- `ctx.stub` the same stub instance as in earlier versions for compatibility
214+
- `ctx.stub` the same stub instance as in earlier versions for compatibility
217215
- `ctx.identity` and instance of the Client Identity object
218216

219217
You are at liberty to create a subclass of the Context to provide additional functions, or per-transaction context storage. For example
@@ -249,29 +247,29 @@ class ScenarioContext extends Context {
249247

250248
Definitions as per https://www.ietf.org/rfc/rfc2119.txt
251249

252-
- All the functions that are present in the prototype of a class that extends *Contract* will be invokable
253-
- The exports from the node module *MUST* include *contracts* that is an array of constructors (1 or more)
254-
- Each class *MAY* call in it's constructor pass a name. This is prefixed to each of the function names by an _ (underscore)
255-
- Each class *MAY* define functions that are executed before and functions that are executed after the invoked function.
250+
- All the functions that are present in the prototype of a class that extends _Contract_ will be invokable
251+
- The exports from the node module _MUST_ include _contracts_ that is an array of constructors (1 or more)
252+
- Each class _MAY_ call in it's constructor pass a name. This is prefixed to each of the function names by an \_ (underscore)
253+
- Each class _MAY_ define functions that are executed before and functions that are executed after the invoked function.
256254
- These are part of the same fabric transaction
257255
- They are scoped per name
258-
- Each class *MAY* define a function that would be executed if a matching function name does not exist; otherwise a 'no function exists' error will be thrown
256+
- Each class _MAY_ define a function that would be executed if a matching function name does not exist; otherwise a 'no function exists' error will be thrown
259257
- If too many parameters are passed, they will be discarded
260258
- If too few parameters are passed, the remainder will be set to undefined
261-
- as per node.js language standard
259+
- as per node.js language standard
262260
- Having duplicate function names in a single class is an error
263261
- Any function that is dynamically added will not be registered as an invokable function
264-
- There is no specific function that is invoked per Fabric's *init* chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
265-
a dedicated function that will be called for new chaincode deployments, and for upgrade deployments.
262+
- There is no specific function that is invoked per Fabric's _init_ chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
263+
a dedicated function that will be called for new chaincode deployments, and for upgrade deployments.
266264

267265
## Restrictions on programming in side a Contract function
268266

269267
Hyperledger Fabric's consensus algorithm permits the ability to use general purpose languages; rather than a more restrictive language. But the following restrictions apply
270268

271269
- Functions should not create random variables, or use any function whose return values are functions of the current time or location of execution
272-
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
270+
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
273271
- Functions should be aware that they may read state, and write state. But they are producing a set of changes that will be applied to the state. The implication is that updates to the state
274-
may not be read back.
272+
may not be read back.
275273

276274
```
277275
let v1 = getState("key");

apis/fabric-contract-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"Fabric Shim"
2323
],
2424
"engines": {
25-
"node": ">=18"
25+
"node": ">=20"
2626
},
2727
"license": "Apache-2.0",
2828
"types": "./types/index.d.ts",
@@ -70,6 +70,6 @@
7070
"typescript": "~5.8.3",
7171
"typescript-eslint": "^8.46.0",
7272
"@eslint/js": "^9.37.0",
73-
"@tsconfig/node18": "~18.2.4"
73+
"@tsconfig/node20": "~20.1.6"
7474
}
7575
}

apis/fabric-contract-api/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
{
77
"$schema": "https://json.schemastore.org/tsconfig",
8-
"extends": "@tsconfig/node18/tsconfig.json",
8+
"extends": "@tsconfig/node20/tsconfig.json",
99
"compilerOptions": {
1010
"types": ["./types/"],
1111
"declaration": true,

apis/fabric-shim-api/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
"Fabric Shim"
1919
],
2020
"engines": {
21-
"node": ">=18"
21+
"node": ">=20"
2222
},
2323
"types": "./types/index.d.ts",
2424
"license": "Apache-2.0",
2525
"devDependencies": {
2626
"@types/long": "^4.0.1",
2727
"eslint": "^9.37.0",
28-
"@eslint/js": "^9.37.0"
28+
"@eslint/js": "^9.37.0",
29+
"@tsconfig/node20": "~20.1.6"
2930
}
3031
}

apis/fabric-shim-api/tsconfig.json

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
{
7-
"compilerOptions": {
8-
"types": ["./types/"],
9-
"alwaysStrict": true,
10-
"module": "commonjs",
11-
"declaration": true,
12-
"sourceMap": true,
13-
"strict": true,
14-
"target": "es2017",
15-
"lib": [
16-
"esnext",
17-
]
18-
},
19-
"files": [
20-
"types/index.d.ts"
21-
],
22-
"exclude": [
23-
"node_modules/**/*"
24-
]
7+
"$schema": "https://json.schemastore.org/tsconfig",
8+
"extends": "@tsconfig/node20/tsconfig.json",
9+
"compilerOptions": {
10+
"types": ["./types/"],
11+
"declaration": true,
12+
"declarationMap": true,
13+
"erasableSyntaxOnly": true,
14+
"isolatedModules": true,
15+
"sourceMap": true,
16+
"strict": true
17+
},
18+
"files": ["types/index.d.ts"],
19+
"exclude": ["node_modules/**/*"]
2520
}

common/config/rush/pnpm-lock.yaml

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/fabric-nodeenv/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
#
5-
ARG NODE_IMAGE_TAG=22-alpine
5+
ARG NODE_IMAGE_TAG=24-alpine
66
FROM node:${NODE_IMAGE_TAG}
77
RUN apk add --no-cache \
88
make \

0 commit comments

Comments
 (0)