-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from yeasy/add-hlf-image
Add hyperledger fabric image
- Loading branch information
Showing
8 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
# https://github.com/yeasy/docker-hyperledger-fabric | ||
# | ||
# Dockerfile for Hyperledger fabric all-in-one development and experiments, including: | ||
# * fabric-peer | ||
# * fabric-orderer | ||
# * fabric-ca | ||
# * cryptogen | ||
# * configtxgen | ||
# * configtxlator | ||
# * gotools | ||
|
||
# If you only need quickly deploy a fabric network, please see | ||
# * yeasy/hyperledger-fabric-peer | ||
# * yeasy/hyperledger-fabric-orderer | ||
# * yeasy/hyperledger-fabric-ca | ||
|
||
# Workdir is set to $GOPATH/src/github.com/hyperledger/fabric | ||
# Data is stored under /var/hyperledger/production | ||
|
||
FROM golang:1.14 | ||
LABEL version=2.2.0 | ||
|
||
# Orderer, peer, ca, operation api | ||
EXPOSE 7050 7051 7054 8443 9443 | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
# Only useful for this Dockerfile | ||
ENV FABRIC_ROOT=$GOPATH/src/github.com/hyperledger/fabric \ | ||
FABRIC_CA_ROOT=$GOPATH/src/github.com/hyperledger/fabric-ca | ||
|
||
# BASE_VERSION is used in metadata.Version as major version | ||
ENV BASE_VERSION=2.2.0 | ||
|
||
# PROJECT_VERSION is required in core.yaml for fabric-baseos and fabric-ccenv | ||
ENV PROJECT_VERSION=2.2.0 | ||
ENV HLF_CA_VERSION=1.4.8 | ||
|
||
# generic environment (core.yaml) for builder and runtime: builder: $(DOCKER_NS)/fabric-ccenv:$(TWO_DIGIT_VERSION) | ||
ENV DOCKER_NS=hyperledger | ||
ENV TWO_DIGIT_VERSION=2.2 | ||
|
||
ENV BASE_DOCKER_NS=hyperledger | ||
ENV LD_FLAGS="-X github.com/hyperledger/fabric/common/metadata.Version=${PROJECT_VERSION} \ | ||
-X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric \ | ||
-X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger \ | ||
-X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" | ||
|
||
# -X github.com/hyperledger/fabric/common/metadata.Experimental=true \ | ||
# -linkmode external -extldflags '-static -lpthread'" | ||
|
||
# peer envs. DONOT combine in one line as the former variable won't work on-the-fly | ||
ENV FABRIC_CFG_PATH=/etc/hyperledger/fabric | ||
|
||
# peer env | ||
ENV CORE_PEER_MSPCONFIGPATH=$FABRIC_CFG_PATH/msp \ | ||
FABRIC_LOGGING_SPEC=DEBUG | ||
|
||
# orderer env | ||
ENV ORDERER_GENERAL_LOCALMSPDIR=$FABRIC_CFG_PATH/msp \ | ||
ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 \ | ||
ORDERER_GENERAL_GENESISPROFILE=TwoOrgsOrdererGenesis | ||
|
||
# ca env. ca-server and ca-client will check the following env in order, to get the home cfg path | ||
ENV FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server \ | ||
FABRIC_CA_SERVER_HOME=/etc/hyperledger/fabric-ca-server \ | ||
FABRIC_CA_CLIENT_HOME=/root/.fabric-ca-client \ | ||
CA_CFG_PATH=/etc/hyperledger/fabric-ca | ||
|
||
RUN mkdir -p /var/hyperledger/production \ | ||
$GOPATH/src/github.com/hyperledger \ | ||
$FABRIC_CFG_PATH \ | ||
$FABRIC_CFG_PATH/crypto-config \ | ||
$FABRIC_CA_SERVER_HOME \ | ||
$FABRIC_CA_CLIENT_HOME \ | ||
$CA_CFG_PATH \ | ||
/chaincode/input \ | ||
/chaincode/output \ | ||
/var/hyperledger/fabric-ca-server | ||
|
||
# Install development dependencies | ||
RUN apt-get update \ | ||
&& apt-get install -y apt-utils python-dev \ | ||
&& apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev libyaml-dev libltdl-dev libtool \ | ||
&& apt-get install -y python-pip \ | ||
&& apt-get install -y vim tree jq unzip \ | ||
&& pip install behave nose docker-compose \ | ||
&& pip install pyinotify \ | ||
&& rm -rf /var/cache/apt | ||
|
||
# Install yq to update config for fabric-ca | ||
RUN wget -O /go/bin/yq https://github.com/mikefarah/yq/releases/download/2.4.1/yq_linux_amd64 \ | ||
&& chmod a+x /go/bin/yq | ||
|
||
# install gotools | ||
RUN go get github.com/golang/protobuf/protoc-gen-go \ | ||
&& go get github.com/maxbrunsfeld/counterfeiter \ | ||
&& go get github.com/axw/gocov/... \ | ||
&& go get github.com/AlekSi/gocov-xml \ | ||
&& go get golang.org/x/tools/cmd/goimports \ | ||
&& go get golang.org/x/lint/golint \ | ||
&& go get github.com/estesp/manifest-tool \ | ||
&& go get github.com/client9/misspell/cmd/misspell \ | ||
&& go get github.com/estesp/manifest-tool \ | ||
&& go get github.com/onsi/ginkgo/ginkgo | ||
|
||
# Clone the Hyperledger Fabric code and cp sample config files | ||
RUN cd $GOPATH/src/github.com/hyperledger \ | ||
&& wget https://github.com/hyperledger/fabric/archive/v${PROJECT_VERSION}.zip \ | ||
&& unzip v${PROJECT_VERSION}.zip \ | ||
&& rm v${PROJECT_VERSION}.zip \ | ||
&& mv fabric-${PROJECT_VERSION} fabric \ | ||
&& echo "* hard nofile 65536" >> /etc/security/limits.conf \ | ||
&& echo "* soft nofile 8192" >> /etc/security/limits.conf \ | ||
&& cp -r $FABRIC_ROOT/sampleconfig/* $FABRIC_CFG_PATH/ | ||
|
||
# Add external fabric chaincode dependencies | ||
RUN go get github.com/hyperledger/fabric-chaincode-go/shim \ | ||
&& go get github.com/hyperledger/fabric-protos-go/peer | ||
|
||
# Install configtxgen, cryptogen, configtxlator, discover and idemixgen | ||
RUN cd $FABRIC_ROOT/ \ | ||
&& CGO_CFLAGS=" " go install -tags "" github.com/hyperledger/fabric/cmd/configtxgen \ | ||
&& CGO_CFLAGS=" " go install -tags "" github.com/hyperledger/fabric/cmd/cryptogen \ | ||
&& CGO_CFLAGS=" " go install -tags "" github.com/hyperledger/fabric/cmd/configtxlator \ | ||
&& CGO_CFLAGS=" " go install -tags "" -ldflags "-X github.com/hyperledger/fabric/cmd/discover/metadata.Version=${PROJECT_VERSION}" github.com/hyperledger/fabric/cmd/discover \ | ||
&& CGO_CFLAGS=" " go install -tags "" github.com/hyperledger/fabric/cmd/idemixgen | ||
|
||
# Install fabric peer | ||
RUN CGO_CFLAGS=" " go install -tags "" -ldflags "$LD_FLAGS" github.com/hyperledger/fabric/cmd/peer \ | ||
&& go clean | ||
|
||
# Install fabric orderer | ||
RUN CGO_CFLAGS=" " go install -tags "" -ldflags "$LD_FLAGS" github.com/hyperledger/fabric/cmd/orderer \ | ||
&& go clean | ||
|
||
#ADD crypto-config $FABRIC_CFG_PATH/crypto-config | ||
|
||
# Install fabric-ca | ||
RUN cd $GOPATH/src/github.com/hyperledger \ | ||
&& wget https://github.com/hyperledger/fabric-ca/archive/v${HLF_CA_VERSION}.zip \ | ||
&& unzip v${HLF_CA_VERSION}.zip \ | ||
&& rm v${HLF_CA_VERSION}.zip \ | ||
&& mv fabric-ca-${HLF_CA_VERSION} fabric-ca \ | ||
# This will install fabric-ca-server and fabric-ca-client into $GOPATH/bin/ | ||
&& go install -ldflags "-X github.com/hyperledger/fabric-ca/lib/metadata.Version=$PROJECT_VERSION -linkmode external -extldflags '-static -lpthread'" github.com/hyperledger/fabric-ca/cmd/... \ | ||
# Copy example ca and key files | ||
#&& cp $FABRIC_CA_ROOT/images/fabric-ca/payload/*.pem $FABRIC_CA_HOME/ \ | ||
&& go clean | ||
|
||
# This is useful to debug local code with mapping inside | ||
VOLUME $GOPATH/src/github.com/hyperledger | ||
# The data and config dir, can map external one with -v | ||
VOLUME /var/hyperledger | ||
VOLUME $FABRIC_CFG_PATH | ||
VOLUME $FABRIC_CA_SERVER_HOME | ||
VOLUME $FABRIC_CA_CLIENT_HOME | ||
|
||
# Useful scripts for quickly compiling local code | ||
ADD scripts/ /tmp/ | ||
|
||
# Remove the go pkg files in case polluting debugging env | ||
RUN bash /tmp/clean_pkg.sh | ||
|
||
# Temporarily fix the `go list` complain problem, which is required in chaincode packaging, see core/chaincode/platforms/golang/platform.go#GetDepoymentPayload | ||
ENV GOROOT=/usr/local/go | ||
|
||
WORKDIR $FABRIC_ROOT | ||
|
||
# This is only a workaround for current hard-coded problem when using as fabric-baseimage. | ||
RUN ln -s $GOPATH /opt/gopath | ||
|
||
LABEL org.hyperledger.fabric.version=${PROJECT_VERSION} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
echo "Restarting fabric-ca" | ||
killall fabric-ca-server | ||
go install -ldflags " -linkmode external -extldflags '-static -lpthread'" github.com/hyperledger/fabric-ca/cmd/... | ||
|
||
fabric-ca-server start \ | ||
--ca.certfile $FABRIC_CA_HOME/ca-cert.pem \ | ||
--ca.keyfile $FABRIC_CA_HOME/ca-key.pem \ | ||
-c $FABRIC_CA_HOME/fabric-ca-server-config.yaml \ | ||
-b admin:adminpw \ | ||
-n test_ca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Old version pkgs may pollute the build env | ||
echo "Clean up old version pkgs under $GOPATH" | ||
rm -rf $GOPATH/pkg/linux_amd64/github.com/hyperledger/fabric | ||
rm -rf $GOPATH/pkg/linux_amd64/github.com/hyperledger/fabric-ca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
# This script will read the files from env variables and store them under $FABRIC_CFG_PATH. | ||
# Will run the optional passed command if everything is OK. | ||
# | ||
# It will read the following env variables | ||
# HLF_NODE_MSP: store a base64 encoded zipped "msp" path | ||
# HLF_NODE_TLS: store a base64 encoded zipped "tls" path | ||
# HLF_NODE_BOOTSTRAP_BLOCK: store a base64 encoded zipped bootstrap block | ||
# HLF_NODE_PEER_CONFIG: store a base64 encoded zipped peer configuration file (core.yaml) | ||
# HLF_NODE_ORDERER_CONFIG: store a base64 encoded zipped orderer configuration file (orderer.yaml) | ||
|
||
|
||
# storeFile will read the variable with given name, and store its data under the given path | ||
# $1: variable-name to decode and then unzip, e.g., HLF_NODE_MSP | ||
# $2: path to put the result under, e.g., $cfg_path | ||
function storeFile { | ||
name="$1" | ||
path="$2" | ||
value="${!name}" # get the data that stored in the env variable | ||
if [[ -z "${value}" || -z "${path}" ]]; then | ||
echo "Parameter ${name} or ${path} is empty or undefined" | ||
return | ||
else | ||
echo "Store data in ${name} to ${path}" | ||
echo "${value}" | base64 -d > /tmp/1.zip | ||
unzip -o -d ${path} /tmp/1.zip | ||
rm /tmp/1.zip | ||
ls ${path} | ||
fi | ||
} | ||
|
||
|
||
# The optional cmd to run after storing every file | ||
cmd=$1 | ||
|
||
# The path to store the files | ||
cfg_path=${FABRIC_CFG_PATH:-/etc/hyperledger/fabric} | ||
|
||
# Read each file from env and store under the ${cfg_path} | ||
for name in HLF_NODE_MSP \ | ||
HLF_NODE_TLS \ | ||
HLF_NODE_BOOTSTRAP_BLOCK \ | ||
HLF_NODE_PEER_CONFIG \ | ||
HLF_NODE_ORDERER_CONFIG | ||
do | ||
storeFile ${name} ${cfg_path} | ||
done | ||
|
||
# Run optional cmd | ||
if [[ ! -z "${cmd}" ]]; then | ||
echo "Run ${cmd}" | ||
${cmd} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pyinotify | ||
|
||
wm = pyinotify.WatchManager() # Watch Manager | ||
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO | pyinotify.IN_MOVE_SELF | pyinotify.IN_DELETE_SELF # watched events | ||
|
||
class EventHandler(pyinotify.ProcessEvent): | ||
def process_IN_CREATE(self, event): | ||
print "Creating:", event.pathname | ||
|
||
def process_IN_DELETE(self, event): | ||
print "Removing:", event.pathname | ||
|
||
def process_IN_MODIFY(self, event): | ||
print "Modifying:", event.pathname | ||
|
||
def process_IN_MOVED_FROM(self, event): | ||
print "Moved From:", event.pathname | ||
|
||
def process_IN_MOVED_TO(self, event): | ||
print "Moved To:", event.pathname | ||
|
||
def process_IN_MOVE_SELF(self, event): | ||
print "Moving Self:", event.pathname | ||
|
||
def process_IN_DELETE_SELF(self, event): | ||
print "Deleting Self:", event.pathname | ||
|
||
handler = EventHandler() | ||
notifier = pyinotify.Notifier(wm, handler) | ||
|
||
# watch Hyperledger and HOME | ||
from os.path import expanduser | ||
home = expanduser("~") | ||
dirs = ['/etc/hyperledger/', '/var/hyperledger/', home] | ||
for d in dirs: | ||
print "Add watcher to "+d | ||
wdd = wm.add_watch(d, mask, rec=True, auto_add=True) | ||
|
||
notifier.loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
echo "Building fabric orderer" | ||
cd $FABRIC_ROOT/orderer \ | ||
&& CGO_CFLAGS=" " go install -ldflags "$LD_FLAGS -linkmode external -extldflags '-static -lpthread'" \ | ||
&& go clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
echo "Building fabric peer" | ||
|
||
cd $FABRIC_ROOT/peer \ | ||
&& CGO_CFLAGS=" " go install -ldflags "$LD_FLAGS -linkmode external -extldflags '-static -lpthread'" \ | ||
&& go clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
echo "Building configtxgen" | ||
CGO_CFLAGS=" " go install -tags "nopkcs11" -ldflags "$LD_FLAGS" github.com/hyperledger/fabric/common/configtx/tool/configtxgen | ||
|
||
echo "Building cryptogen" | ||
CGO_CFLAGS=" " go install -tags "" -ldflags "$LD_FLAGS" github.com/hyperledger/fabric/common/tools/cryptogen | ||
|
||
echo "Building configtxlator" | ||
CGO_CFLAGS=" " go install -tags "" -ldflags "$LD_FLAGS" github.com/hyperledger/fabric/common/tools/configtxlator | ||
|
||
|
||
echo "Install configtxgen, cryptogen and configtxlator" | ||
cd $FABRIC_ROOT/ \ | ||
&& CGO_CFLAGS=" " go install -tags "nopkcs11" -ldflags "-X github.com/hyperledger/fabric/common/tools/configtxgen/metadata.Version=${PROJECT_VERSION}" github.com/hyperledger/fabric/common/tools/configtxgen \ | ||
&& CGO_CFLAGS=" " go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/tools/cryptogen/metadata.Version=${PROJECT_VERSION}" github.com/hyperledger/fabric/common/tools/cryptogen \ | ||
&& CGO_CFLAGS=" " go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/tools/configtxlator/metadata.Version=${PROJECT_VERSION}" github.com/hyperledger/fabric/common/tools/configtxlator | ||
|
||
echo "Install block-listener" | ||
RUN cd $FABRIC_ROOT/examples/events/block-listener \ | ||
&& go install |