Skip to content

Commit

Permalink
Merge "[FABC-131] Change fabric-ca sample to build images"
Browse files Browse the repository at this point in the history
  • Loading branch information
hacera-jonathan authored and Gerrit Code Review committed Sep 21, 2018
2 parents 9ee57c6 + f62952f commit 634203d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 41 deletions.
3 changes: 3 additions & 0 deletions fabric-ca/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
docker-compose.yml
fabric-ca-orderer.dockerfile
fabric-ca-peer.dockerfile
fabric-ca-tools.dockerfile
data
34 changes: 21 additions & 13 deletions fabric-ca/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 0 additions & 24 deletions fabric-ca/bootstrap.sh

This file was deleted.

54 changes: 51 additions & 3 deletions fabric-ca/makeDocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion fabric-ca/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 634203d

Please sign in to comment.