Skip to content

Commit 8d0a277

Browse files
authored
Merge branch 'main' into test-gateway-ci
2 parents e537a1a + 4b0fde7 commit 8d0a277

21 files changed

+7591
-2010
lines changed

.github/workflows/test-on-push.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,27 @@ jobs:
243243
path: |
244244
e2e-network/docker/test-06-v3-bft.sh.logs/*
245245
e2e-network/docker/test-06-v3-bft.sh.tmpdir/fablo-target/**/*
246+
test-07-v2-peer-dev-mode:
247+
needs: test-main
248+
runs-on: ubuntu-latest
249+
steps:
250+
- name: Check out repository code
251+
uses: actions/checkout@v2
252+
253+
- name: Build Fablo
254+
run: |
255+
shellcheck --version && \
256+
yamllint -v && \
257+
npm install && \
258+
./fablo-build.sh
259+
260+
- name: Test v2 peer dev mode
261+
run: e2e-network/docker/test-07-v2-peer-dev-mode.sh
262+
263+
- uses: actions/upload-artifact@v4
264+
if: always()
265+
with:
266+
name: test-07-v2-peer-dev-mode-snapshot
267+
path: |
268+
e2e-network/docker/test-07-v2-peer-dev-mode.sh.logs/*
269+
e2e-network/docker/test-07-v2-peer-dev-mode.sh.tmpdir/fablo-target/**/*

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## 2.3.0
2-
3-
### Features
1+
## 2.3.0
2+
* Support for running Java chaincode in development mode
3+
[#553](https://github.com/hyperledger-labs/fablo/pull/553)
44
* Hardcode fablo config inside init generator
55
[#554](https://github.com/hyperledger-labs/fablo/pull/554)
66
* Publish sample chaincode Docker image
@@ -10,7 +10,6 @@
1010
* Export network topology with Mermaid
1111
[#565](https://github.com/hyperledger-labs/fablo/pull/565)
1212

13-
1413
## 2.2.0
1514

1615
### Features

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ This feature allows hot reload of chaincode code and speeds up the development a
264264
Fablo will run peers in dev mode when `global.peerDevMode` is set to `true`.
265265
Note: in this case TLS has to be disabled, otherwise config validation fails.
266266
267+
#### For Node.js Chaincode:
268+
267269
The simplest way of trying Fablo with dev mode is as follows:
268270
269271
1. Execute `fablo init node dev`.
@@ -278,7 +280,7 @@ The simplest way of trying Fablo with dev mode is as follows:
278280
```
279281
Now, when you update the chaincode source code, it will be automatically refreshed on Hyperledger Fabric Network.
280282
281-
Our sample chaincode definition contains some scripts for running chaincode in dev mode:
283+
The relevant scripts in `package.json` look like:
282284
283285
```json
284286
"scripts": {
@@ -288,13 +290,44 @@ Our sample chaincode definition contains some scripts for running chaincode in d
288290
...
289291
},
290292
```
291-
292-
Worth considering:
293+
**Worth considering for Node.js chaincode:**
293294
* If you want chaincode to be running on multiple peers, you need to start it multiple times, specifying different `--peer.address`
294295
* In case of errors ensure you have the same `--chaincode-id-name` as `CC_PACKAGE_ID` in Fablo output.
295296
296297
Feel free to update this scripts to adjust it to your chaincode definition.
297298
299+
300+
#### For Java Chaincode:
301+
302+
To run Java chaincode in dev mode:
303+
304+
1. Make sure your Fablo config has `global.peerDevMode` set to `true` and TLS disabled.
305+
306+
2. Start the network with `fablo up`.
307+
308+
3. Build and run the Java chaincode locally. As a sample you may use the chaincode from the Fablo source code from the `samples/chaincodes/java-chaincode` directory. Ensure a proper relative path is provided in Fablo config.
309+
```bash
310+
cd samples/chaincodes/java-chaincode
311+
./run-dev.sh
312+
```
313+
314+
The `run-dev.sh` script will:
315+
- Build the chaincode using Gradle's shadowJar task
316+
- Automatically detect the peer's IP address from the Docker container
317+
- Start the chaincode with debug logging enabled
318+
- Connect to the peer at port 7051
319+
320+
For local development and review:
321+
- The chaincode will run with the name `simple-asset:1.0`
322+
- Debug level logging is enabled via `CORE_CHAINCODE_LOGLEVEL=debug`
323+
- You can modify the Java code and rebuild/restart to see changes
324+
- The peer connection is automatically configured using the Docker container's IP
325+
326+
**Worth considering for Java chaincode:**
327+
- If you want the chaincode running on multiple peers, start multiple instances with different `CORE_PEER_ADDRESS` values
328+
- Ensure `CORE_CHAINCODE_ID_NAME` matches the chaincode name and version in your Fablo config (for instance `chaincode1:0.0.1`)
329+
- The Java chaincode uses Gradle's ShadowJar plugin to package all dependencies into a single JAR file
330+
298331
## Channel scripts
299332
300333
### channel help
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd))"
6+
TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))"
7+
FABLO_HOME="$TEST_TMP/../../.."
8+
9+
export FABLO_HOME
10+
11+
CONFIG="$FABLO_HOME/samples/fablo-config-hlf2-1org-1chaincode-peer-dev-mode.json"
12+
NODECHAINCODE="$FABLO_HOME/samples/chaincodes/chaincode-kv-node"
13+
14+
networkUp() {
15+
"$FABLO_HOME/fablo-build.sh"
16+
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" up "$CONFIG")
17+
}
18+
19+
dumpLogs() {
20+
echo "Saving logs of $1 to $TEST_LOGS/$1.log"
21+
mkdir -p "$TEST_LOGS"
22+
docker logs "$1" >"$TEST_LOGS/$1.log" 2>&1
23+
}
24+
25+
networkDown() {
26+
sleep 2
27+
(for name in $(docker ps --format '{{.Names}}'); do dumpLogs "$name"; done)
28+
(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" down)
29+
}
30+
31+
waitForContainer() {
32+
sh "$TEST_TMP/../wait-for-container.sh" "$1" "$2"
33+
}
34+
35+
waitForChaincode() {
36+
(cd "$TEST_TMP" && sh ../wait-for-chaincode.sh "$1" "$2" "$3" "$4")
37+
}
38+
39+
expectInvoke() {
40+
(cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "$6")
41+
}
42+
43+
expectCommand() {
44+
sh "$TEST_TMP/../expect-command.sh" "$1" "$2"
45+
}
46+
47+
trap networkDown EXIT
48+
trap 'networkDown ; echo "Test failed" ; exit 1' ERR SIGINT
49+
50+
# start the network
51+
networkUp
52+
53+
# check if all nodes are ready
54+
waitForContainer "orderer0.group1.orderer.example.com" "Beginning to serve requests"
55+
waitForContainer "db.ca.org1.example.com" "database system is ready to accept connections"
56+
waitForContainer "ca.org1.example.com" "Listening on http://0.0.0.0:7054"
57+
waitForContainer "couchdb.peer0.org1.example.com" "Apache CouchDB has started. Time to relax."
58+
waitForContainer "peer0.org1.example.com" "Joining gossip network of channel my-channel1 with 1 organizations"
59+
waitForChaincode "peer0.org1.example.com" "my-channel1" "chaincode1" "0.0.1"
60+
61+
echo "All nodes are ready"
62+
echo "Starting chaincode in development mode..."
63+
# make sure nodemon is installed and Install if not
64+
if ! command -v nodemon &> /dev/null; then
65+
echo "nodemon could not be found, installing..."
66+
npm install -g nodemon
67+
else
68+
echo "nodemon is already installed"
69+
fi
70+
# start the chaincode in development mode
71+
(cd "$NODECHAINCODE" && npm i && npm run start:watch) &
72+
73+
sleep 5
74+
75+
# Test simple chaincode
76+
expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \
77+
'{"Args":["KVContract:put", "name", "Willy Wonka"]}' \
78+
'{\"success\":\"OK\"}'

0 commit comments

Comments
 (0)