From f62952f980cf47d31d53ab3cbc6b9617026fa6b4 Mon Sep 17 00:00:00 2001 From: Keith Smith Date: Sat, 15 Sep 2018 13:39:27 -0400 Subject: [PATCH] [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 Signed-off-by: Saad Karim --- fabric-ca/.gitignore | 3 +++ fabric-ca/README.md | 34 ++++++++++++++++---------- fabric-ca/bootstrap.sh | 24 ------------------ fabric-ca/makeDocker.sh | 54 ++++++++++++++++++++++++++++++++++++++--- fabric-ca/start.sh | 9 ++++++- 5 files changed, 83 insertions(+), 41 deletions(-) delete mode 100755 fabric-ca/bootstrap.sh diff --git a/fabric-ca/.gitignore b/fabric-ca/.gitignore index a5a77b4574..d21ef6d81e 100644 --- a/fabric-ca/.gitignore +++ b/fabric-ca/.gitignore @@ -1,2 +1,5 @@ docker-compose.yml +fabric-ca-orderer.dockerfile +fabric-ca-peer.dockerfile +fabric-ca-tools.dockerfile data diff --git a/fabric-ca/README.md b/fabric-ca/README.md index d704faa9ad..398fa7d0cd 100755 --- a/fabric-ca/README.md +++ b/fabric-ca/README.md @@ -18,23 +18,31 @@ The Hyperledger Fabric CA sample demonstrates the following: ## Running this sample -1. The following images are required to run this sample: -*hyperledger/fabric-ca-orderer*, *hyperledger/fabric-ca-peer*, and *hyperledger/fabric-ca-tools* +1. To run this sample, simply run the *start.sh* script. You may do this +multiple times in a row as needed since the *start.sh* script cleans up before +starting each time. This sample can be run with the latest released version, +an older released version, or from locally built docker images as follows: - #### install the images - Run the *bootstrap.sh* script provided with this sample to download the - required images for fabric-ca sample. For the v1.2.0-rc1 release, you - will need to specify the version as follows: + a. By default, the sample is run with the latest released version of Fabric + and Fabric CA. - ``` - bootstrap.sh 1.2.0-rc1 - ``` + b. Older versions of Fabric and Fabric CA can be used by setting the + `FABRIC_TAG` environment variable. For example, `export FABRIC_TAG=1.2.0` + will run the sample with 1.2.0 version of Fabric and Fabric CA. -2. To run this sample, simply run the *start.sh* script. You may do this -multiple times in a row as needed since the *start.sh* script cleans up before -starting each time. + c. The sample can also be run with locally built Fabric and Fabric CA + docker images. Fabric and Fabric CA repositories must be cloned with following + commands: + + `git clone https://github.com/hyperledger/fabric.git` + `git clone https://github.com/hyperledger/fabric-ca.git` + + Then execute the `make docker-all` command from the fabric-ca repository. This will + build the necessary images based on the local source code. Before executing the + *start.sh* script, set the `FABRIC_TAG` environment variable to 'local' as follows: + `export FABRIC_TAG=local`. -3. To stop the containers which are started by the *start.sh* script, you may run the *stop.sh* script. +2. To stop the containers which are started by the *start.sh* script, you may run the *stop.sh* script. ## Understanding this sample diff --git a/fabric-ca/bootstrap.sh b/fabric-ca/bootstrap.sh deleted file mode 100755 index ad096e2403..0000000000 --- a/fabric-ca/bootstrap.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# -# Copyright IBM Corp. All Rights Reserved. -# -# SPDX-License-Identifier: Apache-2.0 -# - -# current version of fabric-ca released -export CA_TAG=${1:-1.2.0} - -dockerCaPull() { - echo "==> FABRIC CA IMAGE" - echo - for image in "" "-tools" "-orderer" "-peer"; do - docker pull hyperledger/fabric-ca${image}:$CA_TAG - docker tag hyperledger/fabric-ca${image}:$CA_TAG hyperledger/fabric-ca${image} - done -} - -echo "===> Pulling fabric ca Image" -dockerCaPull ${CA_TAG} - -echo "===> List out hyperledger docker images" -docker images | grep hyperledger/fabric-ca diff --git a/fabric-ca/makeDocker.sh b/fabric-ca/makeDocker.sh index f55bbba416..51b744fe5d 100755 --- a/fabric-ca/makeDocker.sh +++ b/fabric-ca/makeDocker.sh @@ -9,11 +9,24 @@ # This script builds the docker compose file needed to run this sample. # +# IMPORTANT: The following default FABRIC_TAG value should be updated for each +# release after the fabric-orderer and fabric-peer images have been published +# for the release. +export FABRIC_TAG=${FABRIC_TAG:-1.2.0} + +export FABRIC_CA_TAG=${FABRIC_CA_TAG:-${FABRIC_TAG}} +export NS=${NS:-hyperledger} + +export ARCH="linux-amd64" # Docker images run on linux +CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${FABRIC_CA_TAG}.tar.gz +URL=https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${FABRIC_CA_TAG}/${CA_BINARY_FILE} + SDIR=$(dirname "$0") source $SDIR/scripts/env.sh function main { { + createDockerFiles writeHeader writeRootFabricCA if $USE_INTERMEDIATE_CA; then @@ -26,6 +39,41 @@ function main { log "Created docker-compose.yml" } +# Create various dockerfiles used by this sample +function createDockerFiles { + if [ "$FABRIC_TAG" = "local" ]; then + ORDERER_BUILD="image: hyperledger/fabric-ca-orderer" + PEER_BUILD="image: hyperledger/fabric-ca-peer" + TOOLS_BUILD="image: hyperledger/fabric-ca-tools" + else + createDockerFile orderer + ORDERER_BUILD="build: + context: . + dockerfile: fabric-ca-orderer.dockerfile" + createDockerFile peer + PEER_BUILD="build: + context: . + dockerfile: fabric-ca-peer.dockerfile" + createDockerFile tools + TOOLS_BUILD="build: + context: . + dockerfile: fabric-ca-tools.dockerfile" + fi +} + +# createDockerFile +function createDockerFile { + { + echo "FROM ${NS}/fabric-${1}:${FABRIC_TAG}" + echo 'RUN apt-get update && apt-get install -y netcat jq && apt-get install -y curl && rm -rf /var/cache/apt' + 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" + echo 'RUN chmod +x /usr/local/bin/fabric-ca-client' + echo 'ARG FABRIC_CA_DYNAMIC_LINK=false' + # libraries needed when image is built dynamically + echo 'RUN if [ "\$FABRIC_CA_DYNAMIC_LINK" = "true" ]; then apt-get install -y libltdl-dev; fi' + } > $SDIR/fabric-ca-${1}.dockerfile +} + # Write services for the root fabric CA servers function writeRootFabricCA { for ORG in $ORGS; do @@ -46,7 +94,7 @@ function writeIntermediateFabricCA { function writeSetupFabric { echo " setup: container_name: setup - image: hyperledger/fabric-ca-tools + $TOOLS_BUILD command: /bin/bash -c '/scripts/setup-fabric.sh 2>&1 | tee /$SETUP_LOGFILE; sleep 99999' volumes: - ./scripts:/scripts @@ -173,7 +221,7 @@ function writeOrderer { MYHOME=/etc/hyperledger/orderer echo " $ORDERER_NAME: container_name: $ORDERER_NAME - image: hyperledger/fabric-ca-orderer + $ORDERER_BUILD environment: - FABRIC_CA_CLIENT_HOME=$MYHOME - FABRIC_CA_CLIENT_TLS_CERTFILES=$CA_CHAINFILE @@ -210,7 +258,7 @@ function writePeer { MYHOME=/opt/gopath/src/github.com/hyperledger/fabric/peer echo " $PEER_NAME: container_name: $PEER_NAME - image: hyperledger/fabric-ca-peer + $PEER_BUILD environment: - FABRIC_CA_CLIENT_HOME=$MYHOME - FABRIC_CA_CLIENT_TLS_CERTFILES=$CA_CHAINFILE diff --git a/fabric-ca/start.sh b/fabric-ca/start.sh index 34dbeb18e6..973dfb2092 100755 --- a/fabric-ca/start.sh +++ b/fabric-ca/start.sh @@ -8,6 +8,13 @@ # # This script does everything required to run the fabric CA sample. # +# By default, this test is run with the latest released docker images. +# +# To run against a specific fabric/fabric-ca version: +# export FABRIC_TAG=1.2.0 +# +# To run with locally built images: +# export FABRIC_TAG=local set -e @@ -54,7 +61,7 @@ tail -f ${SDIR}/${RUN_SUMFILE}& TAIL_PID=$! # Wait for the run container to complete -while true; do +while true; do if [ -f ${SDIR}/${RUN_SUCCESS_FILE} ]; then kill -9 $TAIL_PID exit 0