Skip to content

Commit

Permalink
[FAB-3933] Use docker hub fabric images in test suite
Browse files Browse the repository at this point in the history
This patch enables the test suite to use fabric images
from docker hub, by default.

Change-Id: I85378650276fcedf20de9ff5c35155d0ecc57805
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed May 18, 2017
1 parent 84f596f commit 1b4f9fd
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 18 deletions.
57 changes: 46 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,54 @@ repository, where active development is ongoing. Issue tracking is handled in [J

## Build and Test

### Full Test Suite Using Default Configuration and Versions
```
# Before running the test suite, make sure you don't have stale invalid certificates from previous runs
rm -rf /tmp/keystore/
rm -rf /tmp/enroll_user/
# Runs test suite
make
```
### Running Unit Tests Manually
```
# In a package directory
go test
```

### Running Integration Tests Manually
You need:
- A working fabric, and fabric-ca set up. It is recommended that you use the docker-compose file provided in `test/fixtures`. See steps below.
- Customized settings in the `test/fixtures/config/config_test.yaml` in case your Hyperledger Fabric network is not running on `localhost` or is using different ports.

*Testing with Fabric Images at Docker Hub*

The test suite defaults to the latest compatible tag of fabric images at Docker Hub.
The following commands starts Fabric:

```
# Start fabric
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-sdk-go
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
docker-compose up --force-recreate
```

*Running Integration Tests*

Fabric should now be running. In a diferent shell, run integration tests
```
# Before running the test, make sure you don't have stale invalid certificates from previous runs
rm -rf /tmp/keystore/
rm -rf /tmp/enroll_user/
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
go test
```

*Testing with Local Build of Fabric (Advanced)*

Alternatively you can build and run Fabric on your own box using the following commands:
```
# Build fabric:
cd $GOPATH/src/github.com/hyperledger/
Expand All @@ -30,21 +75,11 @@ cd $GOPATH/src/github.com/hyperledger/fabric-ca/
git checkout v1.0.0-alpha
make docker
# Before running the test, make sure you don't have stale invalid certificates from previous runs
rm -rf /tmp/keystore/
rm -rf /tmp/enroll_user/
# Start fabric
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-sdk-go
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
docker-compose -f docker-compose.yaml up --force-recreate
```

Fabric should now be running. In a diferent shell, run integration tests
```
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
go test
(source latest-env.sh && docker-compose up --force-recreate)
```

## Compatibility
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This file contains the default images and tags used in the docker-based
# Fabric fixtures. The images and tags can be overriden using environment
# variables. See docker compose documentation.

FABRIC_CA_FIXTURE_TAG=x86_64-1.0.0-alpha
FABRIC_ORDERER_FIXTURE_TAG=x86_64-1.0.0-alpha
FABRIC_PEER_FIXTURE_TAG=x86_64-1.0.0-alpha
FABRIC_BUILDER_FIXTURE_TAG=x86_64-1.0.0-alpha

FABRIC_CA_FIXTURE_IMAGE=hyperledger/fabric-ca
FABRIC_ORDERER_FIXTURE_IMAGE=hyperledger/fabric-orderer
FABRIC_PEER_FIXTURE_IMAGE=hyperledger/fabric-peer
FABRIC_BUILDER_FIXTURE_IMAGE=hyperledger/fabric-ccenv
25 changes: 18 additions & 7 deletions test/fixtures/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'

services:
ca0:
image: hyperledger/fabric-ca
image: ${FABRIC_CA_FIXTURE_IMAGE}:${FABRIC_CA_FIXTURE_TAG}
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
ports:
Expand All @@ -14,7 +14,7 @@ services:
container_name: ca_peerOrg1

ca1:
image: hyperledger/fabric-ca
image: ${FABRIC_CA_FIXTURE_IMAGE}:${FABRIC_CA_FIXTURE_TAG}
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
ports:
Expand All @@ -27,7 +27,7 @@ services:

orderer0:
container_name: orderer0
image: hyperledger/fabric-orderer
image: ${FABRIC_ORDERER_FIXTURE_IMAGE}:${FABRIC_ORDERER_FIXTURE_TAG}
environment:
- GRPC_TRACE=all
- GRPC_VERBOSITY=debug
Expand All @@ -53,7 +53,7 @@ services:

peer0:
container_name: peer0
image: hyperledger/fabric-peer
image: ${FABRIC_PEER_FIXTURE_IMAGE}:${FABRIC_PEER_FIXTURE_TAG}
environment:
- CORE_LOGGING_LEVEL=DEBUG
- CORE_NEXT=true
Expand All @@ -62,6 +62,7 @@ services:
- CORE_PEER_ENDORSER_ENABLED=true
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_CHAINCODE_BUILDER=${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_BUILDER_FIXTURE_TAG}
- CORE_PEER_GOSSIP_ORGLEADER=true
- CORE_PEER_ADDRESS=peer0:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0:7051
Expand All @@ -85,17 +86,19 @@ services:
- ./tls/peers/peer0:/etc/hyperledger/tls
depends_on:
- orderer0
- builder

peer1:
container_name: peer1
image: hyperledger/fabric-peer
image: ${FABRIC_PEER_FIXTURE_IMAGE}:${FABRIC_PEER_FIXTURE_TAG}
environment:
- CORE_NEXT=true
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer1
- CORE_PEER_ENDORSER_ENABLED=true
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_CHAINCODE_BUILDER=${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_BUILDER_FIXTURE_TAG}
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_ADDRESS=peer1:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1:7051
Expand All @@ -120,17 +123,19 @@ services:
depends_on:
- orderer0
- peer0
- builder

peer2:
container_name: peer2
image: hyperledger/fabric-peer
image: ${FABRIC_PEER_FIXTURE_IMAGE}:${FABRIC_PEER_FIXTURE_TAG}
environment:
- CORE_NEXT=true
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer2
- CORE_PEER_ENDORSER_ENABLED=true
- CORE_PEER_LOCALMSPID=Org2MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_CHAINCODE_BUILDER=${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_BUILDER_FIXTURE_TAG}
- CORE_PEER_GOSSIP_ORGLEADER=true
- CORE_PEER_ADDRESS=peer2:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2:7051
Expand All @@ -154,17 +159,19 @@ services:
- ./tls/peers/peer2:/etc/hyperledger/tls
depends_on:
- orderer0
- builder

peer3:
container_name: peer3
image: hyperledger/fabric-peer
image: ${FABRIC_PEER_FIXTURE_IMAGE}:${FABRIC_PEER_FIXTURE_TAG}
environment:
- CORE_NEXT=true
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer3
- CORE_PEER_ENDORSER_ENABLED=true
- CORE_PEER_LOCALMSPID=Org2MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_CHAINCODE_BUILDER=${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_BUILDER_FIXTURE_TAG}
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_ADDRESS=peer3:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer3:7051
Expand All @@ -189,3 +196,7 @@ services:
depends_on:
- orderer0
- peer2
- builder
# builder is only here to create a dependency on the image (not used as part of compose)
builder:
image: ${FABRIC_BUILDER_FIXTURE_IMAGE}:${FABRIC_BUILDER_FIXTURE_TAG}
24 changes: 24 additions & 0 deletions test/fixtures/latest-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

export FABRIC_CA_FIXTURE_TAG="latest"
export FABRIC_ORDERER_FIXTURE_TAG="latest"
export FABRIC_PEER_FIXTURE_TAG="latest"
export FABRIC_BUILDER_FIXTURE_TAG="latest"
25 changes: 25 additions & 0 deletions test/scripts/integration.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Packages to exclude
PKGS=`go list github.com/hyperledger/fabric-sdk-go/test/... 2> /dev/null | \
grep -v /vendor/`

# Detect Hyperledger CI environment
if [ "$JENKINS_URL" == "https://jenkins.hyperledger.org/" ]
then
echo "In Hyperledger CI - Setting docker integration fixture tags to latest..."
source ./test/fixtures/latest-env.sh
fi

echo "Starting fabric and fabric-ca docker images..."
cd ./test/fixtures && docker-compose up --force-recreate -d

Expand Down

0 comments on commit 1b4f9fd

Please sign in to comment.