Skip to content

Commit f62952f

Browse files
author
Keith Smith
committed
[FABC-131] Change fabric-ca sample to build images
Since fabric-ca-orderer/peer/tools images are no longer being published, this updates the fabric-ca sample to not use them. Instead, it either uses locally built images or it builds them by using curl to download the published fabric-ca-client binary from nexus. Change-Id: I29776c72445660ab02a5e82a4e6b0ade0d0167e7 Signed-off-by: Keith Smith <bksmith@us.ibm.com> Signed-off-by: Saad Karim <skarim@us.ibm.com>
1 parent 9c6acee commit f62952f

File tree

5 files changed

+83
-41
lines changed

5 files changed

+83
-41
lines changed

fabric-ca/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
docker-compose.yml
2+
fabric-ca-orderer.dockerfile
3+
fabric-ca-peer.dockerfile
4+
fabric-ca-tools.dockerfile
25
data

fabric-ca/README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,31 @@ The Hyperledger Fabric CA sample demonstrates the following:
1818

1919
## Running this sample
2020

21-
1. The following images are required to run this sample:
22-
*hyperledger/fabric-ca-orderer*, *hyperledger/fabric-ca-peer*, and *hyperledger/fabric-ca-tools*
21+
1. To run this sample, simply run the *start.sh* script. You may do this
22+
multiple times in a row as needed since the *start.sh* script cleans up before
23+
starting each time. This sample can be run with the latest released version,
24+
an older released version, or from locally built docker images as follows:
2325

24-
#### install the images
25-
Run the *bootstrap.sh* script provided with this sample to download the
26-
required images for fabric-ca sample. For the v1.2.0-rc1 release, you
27-
will need to specify the version as follows:
26+
a. By default, the sample is run with the latest released version of Fabric
27+
and Fabric CA.
2828

29-
```
30-
bootstrap.sh 1.2.0-rc1
31-
```
29+
b. Older versions of Fabric and Fabric CA can be used by setting the
30+
`FABRIC_TAG` environment variable. For example, `export FABRIC_TAG=1.2.0`
31+
will run the sample with 1.2.0 version of Fabric and Fabric CA.
3232

33-
2. To run this sample, simply run the *start.sh* script. You may do this
34-
multiple times in a row as needed since the *start.sh* script cleans up before
35-
starting each time.
33+
c. The sample can also be run with locally built Fabric and Fabric CA
34+
docker images. Fabric and Fabric CA repositories must be cloned with following
35+
commands:
36+
37+
`git clone https://github.com/hyperledger/fabric.git`
38+
`git clone https://github.com/hyperledger/fabric-ca.git`
39+
40+
Then execute the `make docker-all` command from the fabric-ca repository. This will
41+
build the necessary images based on the local source code. Before executing the
42+
*start.sh* script, set the `FABRIC_TAG` environment variable to 'local' as follows:
43+
`export FABRIC_TAG=local`.
3644

37-
3. To stop the containers which are started by the *start.sh* script, you may run the *stop.sh* script.
45+
2. To stop the containers which are started by the *start.sh* script, you may run the *stop.sh* script.
3846

3947
## Understanding this sample
4048

fabric-ca/bootstrap.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

fabric-ca/makeDocker.sh

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@
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+
1224
SDIR=$(dirname "$0")
1325
source $SDIR/scripts/env.sh
1426

1527
function 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
3078
function writeRootFabricCA {
3179
for ORG in $ORGS; do
@@ -46,7 +94,7 @@ function writeIntermediateFabricCA {
4694
function 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

fabric-ca/start.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#
99
# This script does everything required to run the fabric CA sample.
1010
#
11+
# By default, this test is run with the latest released docker images.
12+
#
13+
# To run against a specific fabric/fabric-ca version:
14+
# export FABRIC_TAG=1.2.0
15+
#
16+
# To run with locally built images:
17+
# export FABRIC_TAG=local
1118

1219
set -e
1320

@@ -54,7 +61,7 @@ tail -f ${SDIR}/${RUN_SUMFILE}&
5461
TAIL_PID=$!
5562

5663
# Wait for the run container to complete
57-
while true; do
64+
while true; do
5865
if [ -f ${SDIR}/${RUN_SUCCESS_FILE} ]; then
5966
kill -9 $TAIL_PID
6067
exit 0

0 commit comments

Comments
 (0)