HFC: CC deployment successfull while PEER: "Error building images: ..." - hyperledger

TL;DR; Go to ---- EDIT section below
I am using hfc#0.6.5 in a standalone node.js application.
A membersrvc and peer are started with docker-compose, where:
membersrvc:
container_name: membersrvc
image: hyperledger/fabric-membersrvc:latest
ports:
- "7054:7054"
command: membersrvc
vp0:
container_name: peer
image: hyperledger/fabric-peer:latest
ports:
- "7050:7050"
- "7051:7051"
- "7053:7053"
environment:
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=vp0
- CORE_SECURITY_ENABLED=true
- CORE_PEER_PKI_ECA_PADDR=172.17.0.2:7054
- CORE_PEER_PKI_TCA_PADDR=172.17.0.2:7054
- CORE_PEER_PKI_TLSCA_PADDR=172.17.0.2:7054
- CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
[...]
links:
- membersrvc
command: sh -c "sleep 10; peer node start"
The node.js application successfully registers new users and tries to deploy a chaincode using the enrolledUser.deploy(deployRequest); method.
As a value of deployRequest.chaincodePath a path
'github.com/asset-chaincode/' is set.The directory contains a chaincode .go file.
A callback of deployTx.on('complete', cb) prints its log message:
SUCCESS: Successfully deployed chaincode [chainCodeId:415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58], deploy request={"fcn":"init","args":[],"confidential":true,"metadata":{"type":"Buffer","data":[48,...155,253,0]},"chaincodePath":"github.com/gvlax/chaincodes/asset-chaincode"}, response={"uuid":"415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58","chaincodeID":"415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58"}
chaincodeId=415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58
However, when I check an output of a peer console,
I can see error messages
--> full logs here:
peer | 15:40:00.416 [dockercontroller] deployImage -> ERRO 47a Error building images: The command '/bin/sh -c go install build-chaincode && cp src/build-chaincode/vendor/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin && mv $GOPATH/bin/build-chaincode $GOPATH/bin/23991376d1b935790631a448843fd12a9d60f7ab3f0b8b55f629cf0190077436' returned a non-zero code: 1
[...]
peer | ---> Running in 812439684bf7
peer | src/build-chaincode/asset-chaincode.go:25:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
peer | /opt/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)
peer | /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOPATH)
peer | src/build-chaincode/asset-chaincode.go:26:2: cannot find package "github.com/hyperledger/fabric/core/crypto/primitives" in any of:
peer | /opt/go/src/github.com/hyperledger/fabric/core/crypto/primitives (from $GOROOT)
peer | /opt/gopath/src/github.com/hyperledger/fabric/core/crypto/primitives (from $GOPATH)
peer | package build-chaincode
peer | imports github.com/hyperledger/fabric/vendor/github.com/op/go-logging: must be imported as github.com/op/go-logging
[...]
It looks like there are some issues not exactly related to the chaincode compilation on the peer.
Or the chaincode is deployed to a location on the peer where relative import paths in the chaincode cannot be resolved ....
---- EDIT (some hours later)
After many attempts and experiments, I think my problem is always the same:
Regardless of any valid chaincode (stored locally in a directory $GOPATH/src/gibhub.com/<mychaincode_dir> + building with no errors) after being deployed on a peer with the method enrolledUser.deploy(deployRequest) (hfc#0.6.5), a result gives always the same errors on the target node:
peer | Step 4 : RUN go install build-chaincode && cp src/build-chaincode/vendor/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin && mv $GOPATH/bin/build-chaincode $GOPATH/bin/0881d0fe8f4528e1369bfe917cd207d919a07758cc098e212ca74f6766c636d4
peer | ---> Running in b0ca2abbe609
peer | src/build-chaincode/asset-chaincode.go:25:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
peer | /opt/gopath/src/build-chaincode/vendor/github.com/hyperledger/fabric/core/chaincode/shim (vendor tree)
peer | /opt/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)
The imports of the cc the peer complains about are:
import (
"encoding/base64"
"errors"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
[...]
moreover, when I go to the peer CLI, the shim can be found there ...
$ docker exec -it peer bash
$ find / -name shim
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
$ echo $GOPATH/
/opt/gopath/
Isn't something wrong with the fabric-peer image ???

When you deploy with hfc, you need to "vendor" the fabric chaincode packages - see http://hyperledger-fabric.readthedocs.io/en/v0.6/nodeSDK/node-sdk-indepth/#chaincode-deployment
You can also have a look at https://github.com/IBM-Blockchain/SDK-Demo/tree/master/src/chaincode for an example of doing this with the SDK as well

Related

docker-compose issue: Permission denied when attempting to create/mount volume

I have the following docker-compose.yml file:
version: "3"
services:
dbs-poa-loc001d:
image: percona
volumes:
- ./mysql_backup:/var/lib/mysql
- ./create_databases:/docker-entrypoint-initdb.d
hostname: "dbs-poa-loc001d"
container_name: dbs-poa-loc001d
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
ports:
- "3306:3306"
networks:
- azion-network
...
When I try to create the dbs-poa-loc001d service (database for the project), I get the following error:
Starting dbs-poa-loc001d ... done
Attaching to dbs-poa-loc001d
dbs-poa-loc001d | Initializing database
dbs-poa-loc001d | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)
dbs-poa-loc001d | 2019-01-11T01:17:52.060984Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
dbs-poa-loc001d | 2019-01-11T01:17:52.062286Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
dbs-poa-loc001d | 2019-01-11T01:17:52.062299Z 0 [ERROR] Aborting
dbs-poa-loc001d |
dbs-poa-loc001d exited with code 1
This error doesn't happen on my MacOS computer at my job, but in my home computer (running Ubuntu 16.04) it does. I do noticed the mysql_backup folder on the host created to hold the volume data is set to group AND user root. Can anybody tell me what is going on, and how do I fix this? Already tried without success:
Running docker-compose commands using sudo
Manually changing the owner and user of the folder to my actual (low privileged) user.
My current setup and installed versions are:
Ubuntu 16.04
Docker version 18.09.0, build 4d60db4
docker-compose version 1.23.2, build 1110ad0
docker-compose was installed using sudo pip install docker-compose
Can you try to set permissions of mysql_backup to 1001:0?
something like sudo chown -R 1001:0 ./mysql_backup
or as an alternative but only if the folder is empty sudo chmod 777 ./mysql_backup
regarding to percona Dockerfile mysql user id is 1001
https://github.com/percona/percona-docker/blob/master/percona-server.80/Dockerfile

Docker two tier application issue: failed to connect to mongo container

I have a simple nodeJS application consisting of the frontend and a mongo database. I want to deploy it via Docker.
In my docker-compose file I have the following:
version: '2'
services:
express-container:
build: .
ports:
- "3000:3000"
depends_on:
- mongo-container
mongo-container:
image: mongo:3.0
When I run docker-compose up, I have the following error:
Creating todoangularv2_mongo-container_1 ...
Creating todoangularv2_mongo-container_1 ... done
Creating todoangularv2_express-container_1 ...
Creating todoangularv2_express-container_1 ... done
Attaching to todoangularv2_mongo-container_1, todoangularv2_express-container_1
mongo-container_1 | 2017-07-25T15:26:09.863+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=25f03f51322b
mongo-container_1 | 2017-07-25T15:26:09.864+0000 I CONTROL [initandlisten] db version v3.0.15
mongo-container_1 | 2017-07-25T15:26:09.864+0000 I CONTROL [initandlisten] git version: b8ff507269c382bc100fc52f75f48d54cd42ec3b
mongo-container_1 | 2017-07-25T15:26:09.864+0000 I CONTROL [initandlisten] build info: Linux ip-10-166-66-3 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64 BOOST_LIB_VERSION=1_49
mongo-container_1 | 2017-07-25T15:26:09.864+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongo-container_1 | 2017-07-25T15:26:09.864+0000 I CONTROL [initandlisten] options: {}
mongo-container_1 | 2017-07-25T15:26:09.923+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
mongo-container_1 | 2017-07-25T15:26:09.924+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
express-container_1 | Listening on port 3000
express-container_1 |
express-container_1 | events.js:72
express-container_1 | throw er; // Unhandled 'error' event
express-container_1 | ^
express-container_1 | Error: failed to connect to [mongo-container:27017]
So my frontend cannot reach the mongo container called 'mongo-container' in the docker-compose file. In the application itself I'm giving the URL for the mongo database as follows:
module.exports = {
url : 'mongodb://mongo-container:27017/todo'
}
Any idea how I can change my application so that when it is run on Docker, I don't have this connectivity issue?
EDIT: the mongo container gives the following output:
WAUTERW-M-T3ZT:vagrant wim$ docker logs f63
2017-07-26T09:15:02.824+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=f637f963c87f
2017-07-26T09:15:02.825+0000 I CONTROL [initandlisten] db version v3.0.15
2017-07-26T09:15:02.825+0000 I CONTROL [initandlisten] git version: b8ff507269c382bc100fc52f75f48d54cd42ec3b
...
2017-07-26T09:15:21.461+0000 I STORAGE [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0.024 secs
2017-07-26T09:15:21.476+0000 I NETWORK [initandlisten] waiting for connections on port 27017
The express container gives the following output:
WAUTERW-M-T3ZT:vagrant wim$ docker logs 25a
Listening on port 3000
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [mongo-container:27017]
at null.<anonymous> (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:555:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
EDIT: the issue appeared in the Dockerfile. Here is a corrected one (simplified a bit as I started from a node image rather than an Ubuntu image):
FROM node:0.10.40
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
CMD ["node", "/usr/src/app/bin/www"]
You could substitute depends_on by links session, that express dependency between services like depends_on and, according to the documentation, containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.
version: '2'
services:
express-container:
build: .
ports:
- "3000:3000"
links:
- "mongo-container"
mongo-container:
image: mongo:3.0
The issue appeared in the Dockerfile. Here is a corrected one (simplified a bit as I started from a node image rather than an Ubuntu image):
FROM node:0.10.40
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
CMD ["node", "/usr/src/app/bin/www"]

libGL error: failed to load driver swrast in docker container

I have a docker container from which I am trying to run a pyqt app. Everything works well except a chunk of the GUI is not able to render. The docker logs throw this out:
libGL error: failed to load driver: swrast
X Error: GLXBadContext 169
Extension: 154 (Uknown extension)
Minor opcode: 6 (Unknown request)
Resource id: 0x6400003
X Error: BadValue (integer parameter out of range for operation) 2
Extension: 154 (Uknown extension)
Minor opcode: 3 (Unknown request)
Resource id: 0x0
...
QGLContext::makeCurrent(): Failed.
In my Dockerfile, I tried installing pretty much all the packages I could find that might be related, including mesa-utils.
In terms of the docker-compose file, here's what it looks like:
version: '2'
services:
gui:
build: .
volumes:
- .:/usr/src
- /tmp/.X11-unix:/tmp/.X11-unix
command: /bin/bash -c "python start.py"
environment:
- DISPLAY=unix$DISPLAY
- QT_X11_NO_MITSHM=1
devices:
- "/dev/snd:/dev/snd"
- "/dev/dri:/dev/dri"
privileged: true
Any ideas what I might be missing?
Figured it out. I had to build the gui with hardware accelerated OpenGL support. Theres a repo (https://github.com/gklingler/docker3d) that contains docker images with nvidia or other graphics drivers support.
The other catch was, it didn't work for me unless the host and the container had the exact same driver. In order to resolve this, you can run the following shell script if you're running on linux:
#!/bin/bash
version="$(glxinfo | grep "OpenGL version string" | rev | cut -d" " -f1 | rev)"
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/"$version"/NVIDIA-Linux-x86_64-"$version".run
mv NVIDIA-Linux-x86_64-"$version".run NVIDIA-DRIVER.run

Can't deploy transaction to fabric-core

I'm using Vagrant enviroment. I managed to start peer, my chaincode was successfully registered, but when I try to deploy i'm getting the following
vagrant#hyperledger-devenv:v0.2.1-82e72f4:~$
CORE_PEER_ADDRESS=172.17.0.2:7051 peer chaincode deploy -n mytcc -c
'{"Args": ["init", "a","100", "b", "200"]}' - p
github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Error: Error endorsing chaincode: rpc error: code = 12 desc = unknown
service protos.Endorser
I'm using the following docker-compose.yml file, to launch fabric-peer
vp0:
image: hyperledger/fabric-peer
environment:
- CORE_PEER_ID=vp0
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=http://172.17.0.1:2375
- CORE_LOGGING_LEVEL=DEBUG
command: peer node start --peer-chaincodedev
The fllowing is the command for registering my transaction, and it succeds
CORE_CHAINCODE_ID_NAME=mytcc CORE_PEER_ADDRESS=172.17.0.2:7051 ./chaincode_example02
But then, the following command fails
CORE_PEER_ADDRESS=172.17.0.2:7051 peer chaincode deploy -n mytcc -c '{"Args": ["init", "a","100", "b", "200"]}'
-p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
What is protos.Endorser? Thank you!

ERRO : Error trying to connect to local peer: grpc: timed out trying to connect

Unable to deploy chaincode example in my local hyperledger fabric.
system config: mac osx, Docker toolbox for mac
One validating peer is up and running using docker-compose.yaml
membersrvc:
image: hyperledger/fabric-membersrvc
command: membersrvc
vp0:
image: hyperledger/fabric-peer
environment:
- CORE_PEER_ADDRESSAUTODETECT=false
- CORE_VM_ENDPOINT=http://172.17.0.1:2375
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=vp0
- CORE_SECURITY_ENROLLID=test_vp0
- CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
links:
- membersrvc
command: sh -c "sleep 5; peer node start --peer-chaincodedev"
While deploying chaincode by running
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:30303 ./test
Its showing the error as [shim] ERRO : Error trying to connect to local peer: grpc: timed out trying to connect
I tried replacing CORE_PEER_ADDRESS as suggested by grep timeout solution but no change in error.
First Validating peer output
Chaincode deployment error window
You need to use the correct port number on which peer process is listening to.
instead of using the following command,
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:30303 ./test
try this instead,
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:7052 ./test
if it doesn't work then run the following command to check your listening port and use that instead,
netstat -atp tcp | grep -i "listen"

Resources