0
votes

I tried to setup a persistent data store for REST server but was unable to do it.I am posting the steps which I have followed to do it.

Steps which I followed to set a persistent data store for REST server.

  1. Started an instance of MongoDB: root@ubuntu:~# docker run -d --name mongo --network composer_default -p 27017:27017 mongo dda3340e4daf7b36a244c5f30772f50a4ee1e8f81cc7fc5035f1090cdcf46c58

  2. Created a new, empty directory. Created a new file named Dockerfile the new directory, with the following contents:

FROM hyperledger/composer-rest-server

RUN npm install --production loopback-connector-mongodb passport-github && \ npm cache clean && \ ln -s node_modules .node_modules

  1. Changed into the directory created in step 2, and build the Docker image: root@ubuntu:~# cd examples/dir/ root@ubuntu:~/examples/dir# ls Dockerfile ennvars.txt root@ubuntu:~/examples/dir# docker build -t myorg/my-composer-rest-server . Sending build context to Docker daemon 4.096 kB Step 1/2 : FROM hyperledger/composer-rest-server ---> 77cd6a591726 Step 2/2 : RUN npm install --production loopback-connector-couch passport-github && npm cache clean && ln -s node_modules .node_modules ---> Using cache ---> 2ff9537656d1 Successfully built 2ff9537656d1 root@ubuntu:~/examples/dir#

  2. Created file named ennvars.txt in the same directory. The contents are as follows:

    COMPOSER_CONNECTION_PROFILE=hlfv1 COMPOSER_BUSINESS_NETWORK=blockchainv5 COMPOSER_ENROLLMENT_ID=admin COMPOSER_ENROLLMENT_SECRET=adminpw COMPOSER_NAMESPACES=never COMPOSER_SECURITY=true COMPOSER_CONFIG='{ "type": "hlfv1", "orderers": [ { "url": "grpc://localhost:7050" } ], "ca": { "url": "http://localhost:7054", "name": "ca.example.com" }, "peers": [ { "requestURL": "grpc://localhost:7051", "eventURL": "grpc://localhost:7053" } ], "keyValStore": "/home/ubuntu/.hfc-key-store", "channel": "mychannel", "mspID": "Org1MSP", "timeout": "300" }' COMPOSER_DATASOURCES='{ "db": { "name": "db", "connector": "mongodb", "host": "mongo" } }' COMPOSER_PROVIDERS='{ "github": { "provider": "github", "module": "passport-github", "clientID": "a88810855b2bf5d62f97", "clientSecret": "f63e3c3c65229dc51f1c8964b05e9717bf246279", "authPath": "/auth/github", "callbackURL": "/auth/github/callback", "successRedirect": "/", "failureRedirect": "/" } }'

  3. Loaded the env variables by the following command. root@ubuntu:~/examples/dir# source ennvars.txt

  4. Started the docker container by the below command

root@ubuntu:~/examples/dir# docker run \ -d \ -e COMPOSER_CONNECTION_PROFILE=${COMPOSER_CONNECTION_PROFILE} \ -e COMPOSER_BUSINESS_NETWORK=${COMPOSER_BUSINESS_NETWORK} \ -e COMPOSER_ENROLLMENT_ID=${COMPOSER_ENROLLMENT_ID} \ -e COMPOSER_ENROLLMENT_SECRET=${COMPOSER_ENROLLMENT_SECRET} \ -e COMPOSER_NAMESPACES=${COMPOSER_NAMESPACES} \ -e COMPOSER_SECURITY=${COMPOSER_SECURITY} \ -e COMPOSER_CONFIG="${COMPOSER_CONFIG}" \ -e COMPOSER_DATASOURCES="${COMPOSER_DATASOURCES}" \ -e COMPOSER_PROVIDERS="${COMPOSER_PROVIDERS}" \ --name rest \ --network composer_default \ -p 3000:3000 \ myorg/my-composer-rest-server 942eb1bfdbaf5807b1fe2baa2608ab35691e9b6912fb0d3b5362531b8adbdd3a

It got executed successfully. So now I should be able to access the persistent and secured REST server by going to explorer page of loopback But when tried to open the above url got the below error.

Error Image

Have I missed any step or done something wrong.

1
Your link to a document doesn't work. Please post the steps here (as text) so they will be indexed and are searchable. - Dan Selman
It looks like the composer-rest-server is not running on localhost. What host name or IP address did you run it on? - Dan Selman

1 Answers

0
votes

Two things:

  1. You need to put export in front of the envvars in your envvars.txt file.
  2. Check the version of Composer you are running. The FROM hyperledger/composer-rest-server command will pull the latest version of the rest server down, and if your composer version is not updated, the two will be incompatible.