Merge "[FABC-131] Change fabric-ca sample to build images"

This commit is contained in:
Jonathan Levi (HACERA) 2018-09-21 22:08:11 +00:00 committed by Gerrit Code Review
commit 634203d26f
5 changed files with 85 additions and 43 deletions

View file

@ -1,2 +1,5 @@
docker-compose.yml
fabric-ca-orderer.dockerfile
fabric-ca-peer.dockerfile
fabric-ca-tools.dockerfile
data

View file

@ -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*
#### 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:
```
bootstrap.sh 1.2.0-rc1
```
2. To run this sample, simply run the *start.sh* script. You may do this
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.
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:
3. To stop the containers which are started by the *start.sh* script, you may run the *stop.sh* script.
a. By default, the sample is run with the latest released version of Fabric
and Fabric CA.
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.
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`.
2. To stop the containers which are started by the *start.sh* script, you may run the *stop.sh* script.
## Understanding this sample

View file

@ -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

View file

@ -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

View file

@ -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