10

Using the Hyperledger Fabric Test Network on Windows 11 with WSL

 2 years ago
source link: https://dev.to/hannudaniel/using-the-hyperledger-fabric-test-network-on-windows-11-with-wsl-2cac
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

We will try to start up the Hyperledger Fabric Test Network on a Laptop running Windows 11. You can find more information here.

Take care of the pre-requisites:

  • install Docker from here - "Docker Compose" is not required for Windows users, as this is part of the desktop installs.
  • install Windows Subsystem for Linux with Ubuntu partition from here
  • I've not installed anything else. The Laptop already had JDK & Git installed, but nothing else.

First Step - Start WSL

We'll start WSL from the Windows start menu.

This opens up a Linux command prompt, as we know it from Linux.

Second Step - Install the Fabric Binaries and Samples

First, we'll navigate to a folder in the WSL command prompt, where we want to install Hyperledger Fabric.
Then we'll execute the command "curl -sSL https://bit.ly/2ysbOFE | bash -s"
This will install the Fabric samples as well. Tutorials, which mention the installation of the samples as a pre-requisite, are wrong.

hannu@HannusLaptop:/mnt/c/Hyperledger$ curl -sSL https://bit.ly/2ysbOFE | bash -s

Clone hyperledger/fabric-samples repo

===> Cloning hyperledger/fabric-samples repo
Cloning into 'fabric-samples'...
remote: Enumerating objects: 9735, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 9735 (delta 13), reused 26 (delta 4), pack-reused 9693
Receiving objects: 100% (9735/9735), 5.59 MiB | 1.33 MiB/s, done.
Resolving deltas: 100% (5230/5230), done.
Updating files: 100% (849/849), done.
fabric-samples v2.4.2 does not exist, defaulting to main. fabric-samples main branch is intended to work with recent versions of fabric.

Pull Hyperledger Fabric binaries

===> Downloading version 2.4.2 platform specific fabric binaries
===> Downloading:  https://github.com/hyperledger/fabric/releases/download/v2.4.2/hyperledger-fabric-linux-amd64-2.4.2.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   680  100   680    0     0   1708      0 --:--:-- --:--:-- --:--:--  1708
100 76.7M  100 76.7M    0     0  1519k      0  0:00:51  0:00:51 --:--:-- 1549k
==> Done.
===> Downloading version 1.5.2 platform specific fabric-ca-client binary
===> Downloading:  https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   683  100   683    0     0   1778      0 --:--:-- --:--:-- --:--:--  1774
100 25.4M  100 25.4M    0     0  1248k      0  0:00:20  0:00:20 --:--:-- 1157k
==> Done.

Pull Hyperledger Fabric docker images

FABRIC_IMAGES: peer orderer ccenv tools baseos
===> Pulling fabric Images
====> hyperledger/fabric-peer:2.4.2
2.4.2: Pulling from hyperledger/fabric-peer
97518928ae5f: Pull complete
42bd03df3e1a: Pull complete
3182c3c96871: Pull complete
44ae96fc98a2: Pull complete
2b2d34b5ab5c: Pull complete
eff95e52b961: Pull complete
650bde1fc3f7: Pull complete
Digest: sha256:5eaad9fd093fdfb449310ae851912ab2cf6cd5b634380497404b9cb8bf91dcd2
Status: Downloaded newer image for hyperledger/fabric-peer:2.4.2
docker.io/hyperledger/fabric-peer:2.4.2
====> hyperledger/fabric-orderer:2.4.2
2.4.2: Pulling from hyperledger/fabric-orderer
97518928ae5f: Already exists
42bd03df3e1a: Already exists
a565d10714cf: Pull complete
cf01ceab4d02: Pull complete
641b37dc6c30: Pull complete
a4f70ee0bbbe: Pull complete
3a78beab9d5d: Pull complete
Digest: sha256:fc9fbf6d8c88ef7cff09835c5bf978388897a191ed9c9cf1ba33bc131a50799b
Status: Downloaded newer image for hyperledger/fabric-orderer:2.4.2
docker.io/hyperledger/fabric-orderer:2.4.2
====> hyperledger/fabric-ccenv:2.4.2
2.4.2: Pulling from hyperledger/fabric-ccenv
97518928ae5f: Already exists
b78c28b3bbf7: Pull complete
248309d37e25: Pull complete
8f893ed93684: Pull complete
60b34f272e36: Pull complete
bde889820d2b: Pull complete
759d90edbc0f: Pull complete
81a0619aeb06: Pull complete
fc7be8cce065: Pull complete
Digest: sha256:bd2fa8d04b7bb74f422c34b03cfce62750fc7d99f78410c6f4dd7ce4eaf5f594
Status: Downloaded newer image for hyperledger/fabric-ccenv:2.4.2
docker.io/hyperledger/fabric-ccenv:2.4.2
====> hyperledger/fabric-tools:2.4.2
2.4.2: Pulling from hyperledger/fabric-tools
97518928ae5f: Already exists
b78c28b3bbf7: Already exists
248309d37e25: Already exists
8f893ed93684: Already exists
60b34f272e36: Already exists
fb1c258a462f: Pull complete
cddf115ada33: Pull complete
24ea6585952d: Pull complete
Digest: sha256:c3c4cdf3c73877c9d3dba1fcbbd59e152ecd23876a1ccb9f9bc9c4bed69824e7
Status: Downloaded newer image for hyperledger/fabric-tools:2.4.2
docker.io/hyperledger/fabric-tools:2.4.2
====> hyperledger/fabric-baseos:2.4.2
2.4.2: Pulling from hyperledger/fabric-baseos
97518928ae5f: Already exists
42bd03df3e1a: Already exists
368f3bf0ffdc: Pull complete
Digest: sha256:bdf4646cc0e98ab4cfab4a8cb109ebba5424ae5c84c799d5ec0f5eb7ae2ae2ca
Status: Downloaded newer image for hyperledger/fabric-baseos:2.4.2
docker.io/hyperledger/fabric-baseos:2.4.2
===> Pulling fabric ca Image
====> hyperledger/fabric-ca:1.5.2
1.5.2: Pulling from hyperledger/fabric-ca
a0d0a0d46f8b: Pull complete
ac8258c0aeb1: Pull complete
6c802cf1fa97: Pull complete
Digest: sha256:faa3b743d9ed391c30f518a7cc1168160bf335f3bf60ba6aaaf1aa49c1ed023e
Status: Downloaded newer image for hyperledger/fabric-ca:1.5.2
docker.io/hyperledger/fabric-ca:1.5.2
===> List out hyperledger docker images
hyperledger/fabric-tools     2.4       eb40f70b1174   8 weeks ago    473MB
hyperledger/fabric-tools     2.4.2     eb40f70b1174   8 weeks ago    473MB
hyperledger/fabric-tools     latest    eb40f70b1174   8 weeks ago    473MB
hyperledger/fabric-peer      2.4       43b970f84604   8 weeks ago    62.3MB
hyperledger/fabric-peer      2.4.2     43b970f84604   8 weeks ago    62.3MB
hyperledger/fabric-peer      latest    43b970f84604   8 weeks ago    62.3MB
hyperledger/fabric-orderer   2.4       5edf6bdb4489   8 weeks ago    37.3MB
hyperledger/fabric-orderer   2.4.2     5edf6bdb4489   8 weeks ago    37.3MB
hyperledger/fabric-orderer   latest    5edf6bdb4489   8 weeks ago    37.3MB
hyperledger/fabric-ccenv     2.4       e377a02242aa   8 weeks ago    517MB
hyperledger/fabric-ccenv     2.4.2     e377a02242aa   8 weeks ago    517MB
hyperledger/fabric-ccenv     latest    e377a02242aa   8 weeks ago    517MB
hyperledger/fabric-baseos    2.4       4cfe0148d657   8 weeks ago    6.94MB
hyperledger/fabric-baseos    2.4.2     4cfe0148d657   8 weeks ago    6.94MB
hyperledger/fabric-baseos    latest    4cfe0148d657   8 weeks ago    6.94MB
hyperledger/fabric-ca        1.5       4ea287b75c63   6 months ago   69.8MB
hyperledger/fabric-ca        1.5.2     4ea287b75c63   6 months ago   69.8MB
hyperledger/fabric-ca        latest    4ea287b75c63   6 months ago   69.8MB
hannu@HannusLaptop:/mnt/c/Hyperledger$

Enter fullscreen mode

Exit fullscreen mode

Third Step - Start up the Test Network

Now we'll navigate to the folder "fabric-samples/test-network". This contains a shell script called "network.sh". The script will also be there if we'd only have installed the samples and not the binaries, but we wouldn't be able to bring up the Test-Network.

Just executing "./network.sh" will give us an overview of the options.

hannu@HannusLaptop:/mnt/c/Hyperledger/fabric-samples/test-network$ ./network.sh
Using docker and docker-compose
Usage:
  network.sh <Mode> [Flags]
    Modes:
      up - Bring up Fabric orderer and peer nodes. No channel is created
      up createChannel - Bring up fabric network with one channel
      createChannel - Create and join a channel after the network is created
      deployCC - Deploy a chaincode to a channel (defaults to asset-transfer-basic)
      down - Bring down the network

    Flags:
    Used with network.sh up, network.sh createChannel:
    -ca <use CAs> -  Use Certificate Authorities to generate network crypto material
    -c <channel name> - Name of channel to create (defaults to "mychannel")
    -s <dbtype> - Peer state database to deploy: goleveldb (default) or couchdb
    -r <max retry> - CLI times out after certain number of attempts (defaults to 5)
    -d <delay> - CLI delays for a certain number of seconds (defaults to 3)
    -verbose - Verbose mode

    Used with network.sh deployCC
    -c <channel name> - Name of channel to deploy chaincode to
    -ccn <name> - Chaincode name.
    -ccl <language> - Programming language of the chaincode to deploy: go, java, javascript, typescript
    -ccv <version>  - Chaincode version. 1.0 (default), v2, version3.x, etc
    -ccs <sequence>  - Chaincode definition sequence. Must be an integer, 1 (default), 2, 3, etc
    -ccp <path>  - File path to the chaincode.
    -ccep <policy>  - (Optional) Chaincode endorsement policy using signature policy syntax. The default policy requires an endorsement from Org1 and Org2
    -cccg <collection-config>  - (Optional) File path to private data collections configuration file
    -cci <fcn name>  - (Optional) Name of chaincode initialization function. When a function is provided, the execution of init will be requested and the function will be invoked.

    -h - Print this message

 Possible Mode and flag combinations
   up -ca -r -d -s -verbose
   up createChannel -ca -c -r -d -s -verbose
   createChannel -c -r -d -verbose
   deployCC -ccn -ccl -ccv -ccs -ccp -cci -r -d -verbose

 Examples:
   network.sh up createChannel -ca -c mychannel -s couchdb
   network.sh createChannel -c channelName
   network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
   network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript
hannu@HannusLaptop:/mnt/c/Hyperledger/fabric-samples/test-network$

Enter fullscreen mode

Exit fullscreen mode

Now, we'll start up the Test Network by executing "/network.sh up"

hannu@HannusLaptop:/mnt/c/Hyperledger/fabric-samples/test-network$ ./network.sh up
Using docker and docker-compose
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.4.2
DOCKER_IMAGE_VERSION=2.4.2
/mnt/c/Hyperledger/fabric-samples/test-network/../bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
[+] Running 8/8
 ⠿ Network fabric_test                      Created                                                                0.7s
 ⠿ Volume "compose_orderer.example.com"     Created                                                                0.0s
 ⠿ Volume "compose_peer0.org1.example.com"  Created                                                                0.0s
 ⠿ Volume "compose_peer0.org2.example.com"  Created                                                                0.0s
 ⠿ Container peer0.org2.example.com         Started                                                                4.0s
 ⠿ Container orderer.example.com            Started                                                                4.0s
 ⠿ Container peer0.org1.example.com         Started                                                                4.3s
 ⠿ Container cli                            Started                                                                4.3s
CONTAINER ID   IMAGE                               COMMAND             CREATED             STATUS                         PORTS                                                                    NAMES
463eaff80abc   hyperledger/fabric-tools:latest     "/bin/bash"         4 seconds ago       Up Less than a second                                                                                   cli
de452296018a   hyperledger/fabric-peer:latest      "peer node start"   4 seconds ago       Up 1 second                    0.0.0.0:9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp                 peer0.org2.example.com
2bd8b0ccc851   hyperledger/fabric-peer:latest      "peer node start"   4 seconds ago       Up 1 second                    0.0.0.0:7051->7051/tcp, 0.0.0.0:9444->9444/tcp                           peer0.org1.example.com
32c1d1de81c9   hyperledger/fabric-orderer:latest   "orderer"           4 seconds ago       Up 1 second                    0.0.0.0:7050->7050/tcp, 0.0.0.0:7053->7053/tcp, 0.0.0.0:9443->9443/tcp   orderer.example.com
8aed63f3c3b0   hello-world                         "/hello"            About an hour ago   Exited (0) About an hour ago                                                                            nervous_bose
hannu@HannusLaptop:/mnt/c/Hyperledger/fabric-samples/test-network$

Enter fullscreen mode

Exit fullscreen mode

A quick look at Docker Desktop, and we can see that the Hyperledger Fabric Test Network is up! AMAZING!

Fourth Step - Stop the Test Network

Now, let's take the network down again by executing "./network.sh down".

hannu@HannusLaptop:/mnt/c/Hyperledger/fabric-samples/test-network$ ./network.sh down
Using docker and docker-compose
Stopping network
[+] Running 9/9
 ⠿ Container orderer.example.com          Removed                                                                  1.9s
 ⠿ Container cli                          Removed                                                                 11.3s
 ⠿ Container peer0.org2.example.com       Removed                                                                  1.1s
 ⠿ Container peer0.org1.example.com       Removed                                                                  0.7s
 ⠿ Volume compose_peer0.org1.example.com  Removed                                                                  0.0s
 ⠿ Volume compose_peer0.org3.example.com  Removed                                                                  0.0s
 ⠿ Network fabric_test                    Removed                                                                  0.5s
 ⠿ Volume compose_peer0.org2.example.com  Removed                                                                  0.0s
 ⠿ Volume compose_orderer.example.com     Removed                                                                  0.0s
Error: No such volume: docker_orderer.example.com
Error: No such volume: docker_peer0.org1.example.com
Error: No such volume: docker_peer0.org2.example.com
Removing remaining containers
Removing generated chaincode docker images
"docker kill" requires at least 1 argument.
See 'docker kill --help'.

Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]

Kill one or more running containers
Unable to find image 'busybox:latest' locally
/usr/bin/docker-credential-desktop.exe: Invalid argument
latest: Pulling from library/busybox
554879bb3004: Pull complete
Digest: sha256:caa382c432891547782ce7140fb3b7304613d3b0438834dce1cad68896ab110a
Status: Downloaded newer image for busybox:latest
hannu@HannusLaptop:/mnt/c/Hyperledger/fabric-samples/test-network$

Enter fullscreen mode

Exit fullscreen mode

If we check the output above, there were some errors while taking the network down. But we can see in Docker, that the images are not "in use" anymore.

Conclusion

Amazing. We have successfully brought up the Hyperledger Fabric Test Network on Windows 11 and installed the pre-requisites. (The only things I had installed on this laptop before were JDK and Git.) Next time we'll create a channel and deploy chaincode!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK