99# This script builds the docker compose file needed to run this sample.
1010#
1111
12+ # IMPORTANT: The following default FABRIC_TAG value should be updated for each
13+ # release after the fabric-orderer and fabric-peer images have been published
14+ # for the release.
15+ export FABRIC_TAG=${FABRIC_TAG:- 1.2.0}
16+
17+ export FABRIC_CA_TAG=${FABRIC_CA_TAG:- ${FABRIC_TAG} }
18+ export NS=${NS:- hyperledger}
19+
20+ export ARCH=" linux-amd64" # Docker images run on linux
21+ CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH} -${FABRIC_CA_TAG} .tar.gz
22+ URL=https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH} -${FABRIC_CA_TAG} /${CA_BINARY_FILE}
23+
1224SDIR=$( dirname " $0 " )
1325source $SDIR /scripts/env.sh
1426
1527function main {
1628 {
29+ createDockerFiles
1730 writeHeader
1831 writeRootFabricCA
1932 if $USE_INTERMEDIATE_CA ; then
@@ -26,6 +39,41 @@ function main {
2639 log " Created docker-compose.yml"
2740}
2841
42+ # Create various dockerfiles used by this sample
43+ function createDockerFiles {
44+ if [ " $FABRIC_TAG " = " local" ]; then
45+ ORDERER_BUILD=" image: hyperledger/fabric-ca-orderer"
46+ PEER_BUILD=" image: hyperledger/fabric-ca-peer"
47+ TOOLS_BUILD=" image: hyperledger/fabric-ca-tools"
48+ else
49+ createDockerFile orderer
50+ ORDERER_BUILD=" build:
51+ context: .
52+ dockerfile: fabric-ca-orderer.dockerfile"
53+ createDockerFile peer
54+ PEER_BUILD=" build:
55+ context: .
56+ dockerfile: fabric-ca-peer.dockerfile"
57+ createDockerFile tools
58+ TOOLS_BUILD=" build:
59+ context: .
60+ dockerfile: fabric-ca-tools.dockerfile"
61+ fi
62+ }
63+
64+ # createDockerFile
65+ function createDockerFile {
66+ {
67+ echo " FROM ${NS} /fabric-${1} :${FABRIC_TAG} "
68+ echo ' RUN apt-get update && apt-get install -y netcat jq && apt-get install -y curl && rm -rf /var/cache/apt'
69+ echo " RUN curl -o /tmp/fabric-ca-client.tar.gz $URL && tar -xzvf /tmp/fabric-ca-client.tar.gz -C /tmp && cp /tmp/bin/fabric-ca-client /usr/local/bin"
70+ echo ' RUN chmod +x /usr/local/bin/fabric-ca-client'
71+ echo ' ARG FABRIC_CA_DYNAMIC_LINK=false'
72+ # libraries needed when image is built dynamically
73+ echo ' RUN if [ "\$FABRIC_CA_DYNAMIC_LINK" = "true" ]; then apt-get install -y libltdl-dev; fi'
74+ } > $SDIR /fabric-ca-${1} .dockerfile
75+ }
76+
2977# Write services for the root fabric CA servers
3078function writeRootFabricCA {
3179 for ORG in $ORGS ; do
@@ -46,7 +94,7 @@ function writeIntermediateFabricCA {
4694function writeSetupFabric {
4795 echo " setup:
4896 container_name: setup
49- image: hyperledger/fabric-ca-tools
97+ $TOOLS_BUILD
5098 command: /bin/bash -c '/scripts/setup-fabric.sh 2>&1 | tee /$SETUP_LOGFILE ; sleep 99999'
5199 volumes:
52100 - ./scripts:/scripts
@@ -173,7 +221,7 @@ function writeOrderer {
173221 MYHOME=/etc/hyperledger/orderer
174222 echo " $ORDERER_NAME :
175223 container_name: $ORDERER_NAME
176- image: hyperledger/fabric-ca-orderer
224+ $ORDERER_BUILD
177225 environment:
178226 - FABRIC_CA_CLIENT_HOME=$MYHOME
179227 - FABRIC_CA_CLIENT_TLS_CERTFILES=$CA_CHAINFILE
@@ -210,7 +258,7 @@ function writePeer {
210258 MYHOME=/opt/gopath/src/github.com/hyperledger/fabric/peer
211259 echo " $PEER_NAME :
212260 container_name: $PEER_NAME
213- image: hyperledger/fabric-ca-peer
261+ $PEER_BUILD
214262 environment:
215263 - FABRIC_CA_CLIENT_HOME=$MYHOME
216264 - FABRIC_CA_CLIENT_TLS_CERTFILES=$CA_CHAINFILE
0 commit comments