After setting up the network and writing the Chaincode, it's time to deploy the Chaincode. For that, we start by building and compiling the Chaincode using the following command: go build.
Many developers directly compile and install Chaincode from the project Chaincode folder, which isn't the best practice. Typically, we define GOPATH at /opt/gopath in the docker-compose-cli.yaml file, under the cli section:
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
....
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME} ${DELAY}; sleep $TIMEOUT'
volumes:
- /var/run/:/host/var/run/
- ./Chaincode/:/opt/gopath/src/github.com/Chaincode
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
The configuration will map the project Chaincode/ folder to /opt/gopath/src/github.com/Chaincode, and when we start to bring up the Fabric network through our Composer command, the Chaincode will be copied to the preceding-mapped address with the compiled Chaincode file. Afterwards, we start the Docker CLI using: docker exec -it cli bash.
From here, we deploy Chaincode on the default peer (Peer 0 of Organization 1) using:
peer Chaincode install -n fsccc -v 1.0 -p github.com/Chaincode/foodcontract
Here the -n argument specifies the network name and -v the Chaincode version. When this command executes successfully you will see a response indicating a status of 200.