|
1 |
| -# Dockerfile for Hyperledger fabric all-in-one development and experiments, including: |
2 |
| -# * fabric-peer |
3 |
| -# * fabric-orderer |
4 |
| -# * fabric-ca |
5 |
| -# * cryptogen |
6 |
| -# * configtxgen |
7 |
| -# * configtxlator |
8 |
| - |
9 |
| -# * gotools |
10 |
| - |
11 |
| -# Workdir is set to $GOPATH/src/github.com/hyperledger/fabric |
12 |
| -# Data is stored under /var/hyperledger/db and /var/hyperledger/production |
13 |
| - |
14 |
| -# See https://stackoverflow.com/questions/55173477/hyperledger-fabric-dial-unix-host-var-run-docker-sock-connect-no-such-file-o |
15 |
| -# On why do we need Docker-in-Docker |
| 1 | +# We need to use the older, more stable v18 here because of |
| 2 | +# https://github.com/docker-library/docker/issues/170 |
| 3 | +FROM docker:18.09.9-dind |
16 | 4 |
|
17 | 5 | ARG FABRIC_VERSION=1.4.8
|
18 |
| -ARG DIND_VERSION=19.03.12-dind |
19 | 6 |
|
20 |
| -FROM docker:$DIND_VERSION as dind |
21 |
| -FROM hyperledger/fabric-ca:$FABRIC_VERSION as ca |
22 |
| -FROM hyperledger/fabric-orderer:$FABRIC_VERSION as orderer |
23 |
| -FROM hyperledger/fabric-peer:$FABRIC_VERSION as peer |
| 7 | +WORKDIR / |
24 | 8 |
|
25 |
| -COPY --from=ca /usr/local/bin/fabric-ca-server /usr/local/bin/ |
26 |
| -COPY --from=ca /usr/local/bin/fabric-ca-client /usr/local/bin/ |
27 |
| -COPY --from=orderer /usr/local/bin/orderer /usr/local/bin/ |
28 |
| -COPY --from=dind /usr/local/bin/dind /usr/local/bin/dind |
| 9 | +RUN apk update |
29 | 10 |
|
30 |
| -ENV CACTUS_CFG_PATH=/etc/hyperledger/cactus |
31 |
| -ENV FABRIC_CFG_PATH=/etc/hyperledger/fabric |
32 |
| -ENV PROJECT_VERSION=1.4.8 |
| 11 | +# Install dependencies of Docker Compose |
| 12 | +RUN apk add py-pip python3-dev libffi-dev openssl-dev gcc libc-dev make |
33 | 13 |
|
34 |
| -ARG KEYPATH=~/.ssh/id_rsa.pub |
35 |
| -ARG GO_VERSION=1.15 |
36 |
| -ARG GO_SHA256=2d75848ac606061efe52a8068d0e647b35ce487a15bb52272c427df485193602 |
37 |
| -ARG GO_TAR_GZ="go${GO_VERSION}.linux-amd64.tar.gz" |
| 14 | +# Install python/pip - We need this because DinD 18.x has Python 2 |
| 15 | +# And we cannot upgrade to DinD 19 because of |
| 16 | +# https://github.com/docker-library/docker/issues/170 |
| 17 | +ENV PYTHONUNBUFFERED=1 |
| 18 | +RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python |
| 19 | +RUN python3 -m ensurepip |
| 20 | +RUN pip3 install --no-cache --upgrade pip setuptools |
38 | 21 |
|
39 |
| -RUN apt-get update |
| 22 | +# Install Docker Compose which is a dependency of Fabric Samples |
| 23 | +RUN pip install docker-compose |
40 | 24 |
|
41 |
| -# Required for DinD to work |
42 |
| -RUN apt-get install -y iptables bash |
| 25 | +# Need git to clone the sources of the Fabric Samples repository from GitHub |
| 26 | +RUN apk add --no-cache git |
43 | 27 |
|
44 |
| -# Install go - START |
45 |
| -RUN cd ~ |
46 |
| -RUN wget https://golang.org/dl/${GO_TAR_GZ} |
| 28 | +# Fabric Samples needs bash, sh is not good enough here |
| 29 | +RUN apk add --no-cache bash |
47 | 30 |
|
48 |
| -## Make sure the downloaded go tar file is what we want it to be not some malware |
49 |
| -RUN echo "${GO_SHA256} ${GO_TAR_GZ}" sha256sum --check --strict |
50 |
| -RUN tar -xvf ./${GO_TAR_GZ} |
51 |
| -RUN chown -R root:root ./go |
52 |
| -RUN mv go /usr/local |
| 31 | +# Need curl to download the Fabric bootstrap script |
| 32 | +RUN apk add --no-cache curl |
53 | 33 |
|
54 |
| -RUN echo "export PATH=/usr/local/go/bin:$PATH" > /etc/environment |
55 |
| -# Install go - END |
| 34 | +# The file binary is used to inspect exectubles when debugging container image issues |
| 35 | +RUN apk add --no-cache file |
56 | 36 |
|
57 |
| -# Set up Open-SSH server |
58 |
| -RUN apt-get install -y openssh-server augeas-tools |
| 37 | +# Needed because the Fabric binaries need the GNU libc dynamic linker to be executed |
| 38 | +# and alpine does not have that by default |
| 39 | +# @see https://askubuntu.com/a/1035037/1008695 |
| 40 | +# @see https://github.com/gliderlabs/docker-alpine/issues/219#issuecomment-254741346 |
| 41 | +RUN apk add --no-cache libc6-compat |
59 | 42 |
|
60 |
| -# See below link to understand why this is necessary |
61 |
| -# https://serverfault.com/questions/721026/docker-container-sshopen-not-staying-up |
62 |
| -RUN mkdir /var/run/sshd |
| 43 | +ENV CACTUS_CFG_PATH=/etc/hyperledger/cactus |
| 44 | +RUN mkdir -p $CACTUS_CFG_PATH |
| 45 | +# OpenSSH - need to have it so we can shell in and install/instantiate contracts |
| 46 | +RUN apk add --no-cache openssh augeas |
63 | 47 |
|
64 |
| -RUN mkdir -p ~root/.ssh /etc/authorized_keys && chmod 700 ~root/.ssh/ |
| 48 | +# Configure the OpenSSH server we just installed |
65 | 49 | RUN augtool 'set /files/etc/ssh/sshd_config/AuthorizedKeysFile ".ssh/authorized_keys /etc/authorized_keys/%u"'
|
66 | 50 | RUN augtool 'set /files/etc/ssh/sshd_config/PermitRootLogin yes'
|
67 |
| -RUN augtool 'set /files/etc/ssh/sshd_config/PasswordAuthentication yes' |
| 51 | +RUN augtool 'set /files/etc/ssh/sshd_config/PasswordAuthentication no' |
68 | 52 | RUN augtool 'set /files/etc/ssh/sshd_config/Port 22'
|
69 |
| -RUN cp -a /etc/ssh /etc/ssh.cache |
| 53 | +# Create the server's key - without this sshd will refuse to start |
70 | 54 | RUN ssh-keygen -A
|
71 |
| -RUN echo 'root:root' | chpasswd |
72 |
| - |
73 |
| -RUN chmod 700 ~/ |
74 |
| -RUN chmod 700 ~/.ssh |
75 |
| -RUN touch ~/.ssh/authorized_keys |
76 |
| -RUN chmod 600 ~/.ssh/authorized_keys |
77 |
| -RUN mkdir -p $CACTUS_CFG_PATH |
78 | 55 |
|
79 | 56 | # Generate an RSA keypair on the fly to avoid having to hardcode one in the image
|
80 | 57 | # which technically does not pose a security threat since this is only a development
|
81 |
| -# image, but still it is just best not to tempt fate with things like private keys |
82 |
| -# So here we go: |
| 58 | +# image, but we do it like this anyway. |
| 59 | +RUN mkdir ~/.ssh |
| 60 | +RUN chmod 700 ~/.ssh/ |
| 61 | +RUN touch ~/.ssh/authorized_keys |
83 | 62 | RUN ["/bin/bash", "-c", "ssh-keygen -t rsa -N '' -f $CACTUS_CFG_PATH/fabric-aio-image <<< y"]
|
84 | 63 | RUN mv $CACTUS_CFG_PATH/fabric-aio-image $CACTUS_CFG_PATH/fabric-aio-image.key
|
85 |
| - |
86 | 64 | RUN cp $CACTUS_CFG_PATH/fabric-aio-image.pub ~/.ssh/authorized_keys
|
87 | 65 |
|
88 |
| -RUN wget https://github.com/hyperledger/fabric/releases/download/v${PROJECT_VERSION}/hyperledger-fabric-linux-amd64-${PROJECT_VERSION}.tar.gz \ |
89 |
| - && tar -xvf hyperledger-fabric-linux-amd64-${PROJECT_VERSION}.tar.gz \ |
90 |
| - && rm hyperledger-fabric-linux-amd64-${PROJECT_VERSION}.tar.gz |
91 |
| - |
92 |
| -RUN mkdir -p $FABRIC_CFG_PATH/config \ |
93 |
| - && mkdir -p /etc/hyperledger/fabric-ca-server \ |
94 |
| - && mkdir -p /etc/hyperledger/fabric-ca-server-config \ |
95 |
| - && mkdir -p /etc/hyperledger/fabric/orderer \ |
96 |
| - && mkdir -p /etc/hyperledger/fabric/peer |
97 |
| - |
98 |
| -COPY ./configtx.yaml $FABRIC_CFG_PATH |
99 |
| -COPY ./crypto-config.yaml $FABRIC_CFG_PATH |
100 |
| -COPY ./generate.sh $FABRIC_CFG_PATH |
101 |
| -COPY ./start_ca.sh /etc/hyperledger/fabric-ca-server |
102 |
| -COPY ./start_orderer.sh /etc/hyperledger/fabric/orderer |
103 |
| -COPY ./start_peer.sh /etc/hyperledger/fabric/peer |
104 |
| -COPY ./join_channel.sh /etc/hyperledger/fabric/peer |
105 |
| -RUN ./$FABRIC_CFG_PATH/generate.sh |
106 |
| - |
107 |
| -# SUPERVISORD |
108 |
| -RUN apt-get install -y supervisor |
109 |
| -RUN mkdir -p /var/log/supervisor |
110 |
| -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf |
111 |
| - |
112 |
| -# OpenSSH Server |
113 |
| -EXPOSE 22 |
114 |
| - |
115 |
| -# fabric-orderer |
116 |
| -EXPOSE 7050 |
| 66 | +# Download and execute the Fabric bootstrap script, but instruct it with the -d |
| 67 | +# flag to avoid pulling docker images because during the build phase of this image |
| 68 | +# there is no docker daemon running yet so this has to happen in the CMD once a |
| 69 | +# container has been started from the image => see ./run-fabric-network-sh |
| 70 | +RUN curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/release-2.2/scripts/bootstrap.sh > /bootstrap.sh |
| 71 | +RUN chmod +x bootstrap.sh |
| 72 | +# Run the bootstrap here so that at least we can pre-fetch the git clone and the binary downloads resulting in |
| 73 | +# faster container startup speed since these steps will not have to be done, only the docker image pulls. |
| 74 | +RUN /bootstrap.sh $FABRIC_VERSION $FABRIC_VERSION -d |
| 75 | + |
| 76 | +# Install supervisord because we need to run the docker daemon and also the fabric network |
| 77 | +# meaning that we have multiple processes to run. |
| 78 | +RUN apk add --no-cache supervisor |
| 79 | +COPY supervisord.conf /etc/supervisord.conf |
| 80 | + |
| 81 | +COPY run-fabric-network.sh / |
| 82 | + |
| 83 | +# supervisord web ui/dashboard |
| 84 | +EXPOSE 9001 |
| 85 | + |
| 86 | +# peer1.org2.example.com |
| 87 | +EXPOSE 10051 |
117 | 88 |
|
118 |
| -# - Port 7053 used to be used for Events in older versions of Fabric, |
119 |
| -# but it is not used in 1.4.1 |
| 89 | +# peer0.org1.example.com |
| 90 | +EXPOSE 7051 |
120 | 91 |
|
121 |
| -# fabric-peers |
122 |
| -EXPOSE 7051 7052 |
| 92 | +# peer0.org2.example.com |
| 93 | +EXPOSE 9051 |
123 | 94 |
|
124 |
| -# fabric-ca-server RESTful |
| 95 | +# peer1.org1.example.com |
| 96 | +EXPOSE 8051 |
| 97 | + |
| 98 | +# orderer.example.com |
| 99 | +EXPOSE 7050 |
| 100 | + |
| 101 | +# ca_peerOrg1 |
125 | 102 | EXPOSE 7054
|
126 | 103 |
|
127 |
| -# fabric-peer operations |
128 |
| -EXPOSE 9443 |
| 104 | +# ca_peerOrg2 |
| 105 | +EXPOSE 8054 |
129 | 106 |
|
130 |
| -# SUPERVISORD PORTS |
131 |
| -EXPOSE 9001 |
| 107 | +# couchdb0, couchdb1, couchdb2, couchdb3 |
| 108 | +EXPOSE 5984 6984 7984 8984 |
132 | 109 |
|
| 110 | +# Extend the parent image's entrypoint |
| 111 | +# https://superuser.com/questions/1459466/can-i-add-an-additional-docker-entrypoint-script |
133 | 112 | ENTRYPOINT ["/usr/bin/supervisord"]
|
134 |
| -CMD ["--configuration", "/etc/supervisor/conf.d/supervisord.conf", "--nodaemon"] |
| 113 | +CMD ["--configuration", "/etc/supervisord.conf", "--nodaemon"] |
| 114 | + |
| 115 | +# We consider the container healthy once the default example fabcar contract has been deployed |
| 116 | +# and is responsive to queries as well |
| 117 | +HEALTHCHECK --interval=1s --timeout=5s --start-period=60s --retries=300 CMD docker exec cli peer chaincode query --channelID mychannel --name fabcar --ctor '{"Args": [], "Function": "queryAllCars"}' |
0 commit comments