mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-26 03:25:09 +00:00
merge Azure test and cert-manager branches
Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>
This commit is contained in:
commit
51b456a9bc
6 changed files with 210 additions and 17 deletions
|
|
@ -11,29 +11,35 @@ import { promises as fs } from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { TextDecoder } from 'util';
|
import { TextDecoder } from 'util';
|
||||||
|
|
||||||
const channelName = 'mychannel';
|
const channelName = envOrDefault('CHANNEL_NAME', 'mychannel');
|
||||||
const chaincodeName = 'basic';
|
const chaincodeName = envOrDefault('CHAINCODE_NAME', 'basic');
|
||||||
const mspId = 'Org1MSP';
|
const mspId = envOrDefault('MSP_ID', 'Org1MSP');
|
||||||
|
|
||||||
// Path to crypto materials.
|
// Path to crypto materials.
|
||||||
const cryptoPath = path.resolve(__dirname, '..', '..', '..', 'test-network', 'organizations', 'peerOrganizations', 'org1.example.com');
|
const cryptoPath = envOrDefault('CRYPTO_PATH', path.resolve(__dirname, '..', '..', '..', 'test-network', 'organizations', 'peerOrganizations', 'org1.example.com'));
|
||||||
|
|
||||||
// Path to user private key directory.
|
// Path to user private key directory.
|
||||||
const keyDirectoryPath = path.resolve(cryptoPath, 'users', 'User1@org1.example.com', 'msp', 'keystore');
|
const keyDirectoryPath = envOrDefault('KEY_DIRECTORY_PATH', path.resolve(cryptoPath, 'users', 'User1@org1.example.com', 'msp', 'keystore'));
|
||||||
|
|
||||||
// Path to user certificate.
|
// Path to user certificate.
|
||||||
const certPath = path.resolve(cryptoPath, 'users', 'User1@org1.example.com', 'msp', 'signcerts', 'cert.pem');
|
const certPath = envOrDefault('CERT_PATH', path.resolve(cryptoPath, 'users', 'User1@org1.example.com', 'msp', 'signcerts', 'cert.pem'));
|
||||||
|
|
||||||
// Path to peer tls certificate.
|
// Path to peer tls certificate.
|
||||||
const tlsCertPath = path.resolve(cryptoPath, 'peers', 'peer0.org1.example.com', 'tls', 'ca.crt');
|
const tlsCertPath = envOrDefault('TLS_CERT_PATH', path.resolve(cryptoPath, 'peers', 'peer0.org1.example.com', 'tls', 'ca.crt'));
|
||||||
|
|
||||||
// Gateway peer endpoint.
|
// Gateway peer endpoint.
|
||||||
const peerEndpoint = 'localhost:7051';
|
const peerEndpoint = envOrDefault('PEER_ENDPOINT', 'localhost:7051');
|
||||||
|
|
||||||
|
// Gateway peer SSL host name override.
|
||||||
|
const peerHostAlias = envOrDefault('PEER_HOST_ALIAS', 'peer0.org1.example.com');
|
||||||
|
|
||||||
const utf8Decoder = new TextDecoder();
|
const utf8Decoder = new TextDecoder();
|
||||||
const assetId = `asset${Date.now()}`;
|
const assetId = `asset${Date.now()}`;
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
|
|
||||||
|
await displayInputParameters();
|
||||||
|
|
||||||
// The gRPC client connection should be shared by all Gateway connections to this endpoint.
|
// The gRPC client connection should be shared by all Gateway connections to this endpoint.
|
||||||
const client = await newGrpcConnection();
|
const client = await newGrpcConnection();
|
||||||
|
|
||||||
|
|
@ -86,13 +92,16 @@ async function main(): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(error => console.error('******** FAILED to run the application:', error));
|
main().catch(error => {
|
||||||
|
console.error('******** FAILED to run the application:', error);
|
||||||
|
process.exitCode = 1;
|
||||||
|
});
|
||||||
|
|
||||||
async function newGrpcConnection(): Promise<grpc.Client> {
|
async function newGrpcConnection(): Promise<grpc.Client> {
|
||||||
const tlsRootCert = await fs.readFile(tlsCertPath);
|
const tlsRootCert = await fs.readFile(tlsCertPath);
|
||||||
const tlsCredentials = grpc.credentials.createSsl(tlsRootCert);
|
const tlsCredentials = grpc.credentials.createSsl(tlsRootCert);
|
||||||
return new grpc.Client(peerEndpoint, tlsCredentials, {
|
return new grpc.Client(peerEndpoint, tlsCredentials, {
|
||||||
'grpc.ssl_target_name_override': 'peer0.org1.example.com',
|
'grpc.ssl_target_name_override': peerHostAlias,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,3 +214,25 @@ async function updateNonExistentAsset(contract: Contract): Promise<void>{
|
||||||
console.log('*** Successfully caught the error: \n', error);
|
console.log('*** Successfully caught the error: \n', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* envOrDefault() will return the value of an environment variable, or a default value if the variable is undefined.
|
||||||
|
*/
|
||||||
|
function envOrDefault(key: string, defaultValue: string): string {
|
||||||
|
return process.env[key] || defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displayInputParameters() will print the global scope parameters used by the main driver routine.
|
||||||
|
*/
|
||||||
|
async function displayInputParameters(): Promise<void> {
|
||||||
|
console.log(`channelName: ${channelName}`);
|
||||||
|
console.log(`chaincodeName: ${chaincodeName}`);
|
||||||
|
console.log(`mspId: ${mspId}`);
|
||||||
|
console.log(`cryptoPath: ${cryptoPath}`);
|
||||||
|
console.log(`keyDirectoryPath: ${keyDirectoryPath}`);
|
||||||
|
console.log(`certPath: ${certPath}`);
|
||||||
|
console.log(`tlsCertPath: ${tlsCertPath}`);
|
||||||
|
console.log(`peerEndpoint: ${peerEndpoint}`);
|
||||||
|
console.log(`peerHostAlias: ${peerHostAlias}`);
|
||||||
|
}
|
||||||
|
|
@ -114,6 +114,27 @@ jobs:
|
||||||
workingDirectory: test-network
|
workingDirectory: test-network
|
||||||
displayName: Run Test Network Basic Chaincode
|
displayName: Run Test Network Basic Chaincode
|
||||||
|
|
||||||
|
- job: KubeTestNetworkBasic
|
||||||
|
displayName: Kube Test Network Basic
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-20.04
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
Docker-Typescript:
|
||||||
|
CONTAINER_CLI: docker
|
||||||
|
CLIENT_LANGUAGE: typescript
|
||||||
|
# Podman-Typescript:
|
||||||
|
# CONTAINER_CLI: podman
|
||||||
|
# CLIENT_LANGUAGE: typescript
|
||||||
|
# Nerdctl-Typescript:
|
||||||
|
# CONTAINER_CLI: nerdctl
|
||||||
|
# CLIENT_LANGUAGE: typescript
|
||||||
|
steps:
|
||||||
|
- template: templates/install-k8s-deps.yml
|
||||||
|
- script: ../ci/scripts/run-k8s-test-network-basic.sh
|
||||||
|
workingDirectory: test-network-k8s
|
||||||
|
displayName: Run Kubernetes Test Network Basic Asset Transfer
|
||||||
|
|
||||||
- job: TestNetworkLedger
|
- job: TestNetworkLedger
|
||||||
displayName: Test Network
|
displayName: Test Network
|
||||||
pool:
|
pool:
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
CONTAINER_CLI=${CONTAINER_CLI:-"docker"}
|
||||||
FABRIC_VERSION=${FABRIC_VERSION:-2.4}
|
FABRIC_VERSION=${FABRIC_VERSION:-2.4}
|
||||||
STABLE_TAG=amd64-${FABRIC_VERSION}-stable
|
STABLE_TAG=amd64-${FABRIC_VERSION}-stable
|
||||||
|
|
||||||
|
echo "Pulling images with $CONTAINER_CLI"
|
||||||
|
|
||||||
for image in baseos peer orderer ca tools orderer ccenv javaenv nodeenv tools; do
|
for image in baseos peer orderer ca tools orderer ccenv javaenv nodeenv tools; do
|
||||||
docker pull -q "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}"
|
$CONTAINER_CLI pull -q "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}"
|
||||||
docker tag "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}" hyperledger/fabric-${image}
|
$CONTAINER_CLI tag "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}" hyperledger/fabric-${image}
|
||||||
docker tag "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}" "hyperledger/fabric-${image}:${FABRIC_VERSION}"
|
$CONTAINER_CLI tag "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}" "hyperledger/fabric-${image}:${FABRIC_VERSION}"
|
||||||
docker rmi -f "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}"
|
$CONTAINER_CLI rmi -f "hyperledger-fabric.jfrog.io/fabric-${image}:${STABLE_TAG}"
|
||||||
done
|
done
|
||||||
|
|
||||||
docker pull -q couchdb:3.1.1
|
$CONTAINER_CLI pull -q couchdb:3.1.1
|
||||||
docker images | grep hyperledger
|
$CONTAINER_CLI images | grep hyperledger
|
||||||
|
|
|
||||||
130
ci/scripts/run-k8s-test-network-basic.sh
Executable file
130
ci/scripts/run-k8s-test-network-basic.sh
Executable file
|
|
@ -0,0 +1,130 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
#
|
||||||
|
# Copyright IBM Corp All Rights Reserved
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Test matrix parameters
|
||||||
|
# todo: compatibility with podman, k3s/rancher, docker, KIND, etc.
|
||||||
|
export CONTAINER_CLI=${CONTAINER_CLI:-docker}
|
||||||
|
export CLIENT_LANGUAGE=${CLIENT_LANGUAGE:-typescript}
|
||||||
|
|
||||||
|
# Fabric version and Docker registry source: use the latest stable tag image from JFrog
|
||||||
|
export FABRIC_VERSION=${FABRIC_VERSION:-2.4}
|
||||||
|
export TEST_NETWORK_FABRIC_CONTAINER_REGISTRY=hyperledger-fabric.jfrog.io
|
||||||
|
export TEST_NETWORK_FABRIC_VERSION=amd64-${FABRIC_VERSION}-stable
|
||||||
|
export TEST_NETWORK_FABRIC_CA_VERSION=amd64-${FABRIC_VERSION}-stable
|
||||||
|
|
||||||
|
# test-network-k8s parameters
|
||||||
|
export TEST_TAG=$(git describe)
|
||||||
|
export TEST_NETWORK_KIND_CLUSTER_NAME=${TEST_NETWORK_KIND_CLUSTER_NAME:-kind}
|
||||||
|
export TEST_NETWORK_CHAINCODE_NAME=${TEST_NETWORK_CHAINCODE_NAME:-asset-transfer-basic}
|
||||||
|
export TEST_NETWORK_CHAINCODE_IMAGE=${TEST_NETWORK_CHAINCODE_NAME}:${TEST_TAG}
|
||||||
|
export TEST_NETWORK_CHAINCODE_PATH=${TEST_NETWORK_CHAINCODE_PATH:-../asset-transfer-basic/chaincode-external}
|
||||||
|
|
||||||
|
# gateway client application parameters
|
||||||
|
export GATEWAY_CLIENT_APPLICATION_PATH=${GATEWAY_CLIENT_APPLICATION_PATH:-../asset-transfer-basic/application-gateway-${CLIENT_LANGUAGE}}
|
||||||
|
export CHANNEL_NAME=${TEST_NETWORK_CHANNEL_NAME:-mychannel}
|
||||||
|
export CHAINCODE_NAME=${TEST_NETWORK_CHAINCODE_NAME:-basic-asset-transfer}
|
||||||
|
export MSP_ID=${MSP_ID:-Org1MSP}
|
||||||
|
export CRYPTO_PATH=${CRYPTO_PATH:-../../test-network-k8s/build/organizations/peerOrganizations/org1.example.com}
|
||||||
|
export KEY_DIRECTORY_PATH=${KEY_DIRECTORY_PATH:-../../test-network-k8s/build/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore}
|
||||||
|
export CERT_PATH=${CERT_PATH:-../../test-network-k8s/build/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/cert.pem}
|
||||||
|
export TLS_CERT_PATH=${TLS_CERT_PATH:-../../test-network-k8s/build/organizations/peerOrganizations/org1.example.com/peers/org1-peer1.org1.example.com/tls/cacerts/org1-tls-ca.pem}
|
||||||
|
export PEER_ENDPOINT=${PEER_ENDPOINT:-localhost:7051}
|
||||||
|
export PEER_HOST_ALIAS=${PEER_HOST_ALIAS:-org1-peer1}
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function touteSuite() {
|
||||||
|
createCluster
|
||||||
|
buildChaincodeImage
|
||||||
|
}
|
||||||
|
|
||||||
|
function quitterLaScene() {
|
||||||
|
destroyCluster
|
||||||
|
scrubCCImages
|
||||||
|
}
|
||||||
|
|
||||||
|
function createCluster() {
|
||||||
|
print "Initializing KIND Kubernetes cluster"
|
||||||
|
./network kind
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroyCluster() {
|
||||||
|
print "Destroying KIND Kubernetes cluster"
|
||||||
|
./network unkind
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildChaincodeImage() {
|
||||||
|
print "Building chaincode image $TEST_NETWORK_CHAINCODE_IMAGE"
|
||||||
|
${CONTAINER_CLI} build -t $TEST_NETWORK_CHAINCODE_IMAGE $TEST_NETWORK_CHAINCODE_PATH
|
||||||
|
|
||||||
|
# todo: work with local reg, or k3s, or KIND, or ...
|
||||||
|
kind load docker-image $TEST_NETWORK_CHAINCODE_IMAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrubCCImages() {
|
||||||
|
print "Scrubbing chaincode images"
|
||||||
|
${CONTAINER_CLI} rmi $TEST_NETWORK_CHAINCODE_IMAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNetwork() {
|
||||||
|
print "Launching network"
|
||||||
|
./network up
|
||||||
|
./network channel create
|
||||||
|
|
||||||
|
print "Opening gateway port-forward to 'localhost:7051'"
|
||||||
|
kubectl -n test-network port-forward svc/org1-peer1 7051:7051 &
|
||||||
|
|
||||||
|
print "Deploying chaincode"
|
||||||
|
./network chaincode deploy
|
||||||
|
|
||||||
|
print "Extracting certificates"
|
||||||
|
kubectl \
|
||||||
|
-n test-network \
|
||||||
|
exec deploy/org1-peer1 \
|
||||||
|
-c main \
|
||||||
|
-- tar zcf - -C /var/hyperledger/fabric organizations/peerOrganizations/org1.example.com \
|
||||||
|
| tar zxvf - -C ../test-network-k8s/build/
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopNetwork() {
|
||||||
|
pkill -f "port-forward"
|
||||||
|
|
||||||
|
print "Stopping network"
|
||||||
|
./network down
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up the suite with a KIND cluster
|
||||||
|
touteSuite
|
||||||
|
trap "quitterLaScene" EXIT
|
||||||
|
|
||||||
|
# invoke / query
|
||||||
|
createNetwork
|
||||||
|
print "Inserting and querying assets"
|
||||||
|
( ./network chaincode invoke '{"Args":["InitLedger"]}' \
|
||||||
|
&& sleep 5 \
|
||||||
|
&& ./network chaincode query '{"Args":["ReadAsset","asset1"]}' )
|
||||||
|
stopNetwork
|
||||||
|
|
||||||
|
# Run the basic-asset-transfer basic application
|
||||||
|
createNetwork
|
||||||
|
print "Running Gateway client application"
|
||||||
|
( pushd ${GATEWAY_CLIENT_APPLICATION_PATH} \
|
||||||
|
&& npm install \
|
||||||
|
&& npm start )
|
||||||
|
stopNetwork
|
||||||
|
|
||||||
|
# Run additional test ...
|
||||||
|
# Run additional test ...
|
||||||
|
# Run additional test ...
|
||||||
|
|
||||||
|
# destroyCluster will be invoked on EXIT trap handler at the end of this suite.
|
||||||
9
ci/templates/install-k8s-deps.yml
Normal file
9
ci/templates/install-k8s-deps.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- task: NodeTool@0
|
||||||
|
inputs:
|
||||||
|
versionSpec: $(NODE_VER)
|
||||||
|
displayName: Install Node.js
|
||||||
|
|
@ -117,7 +117,6 @@ function create_org1_local_MSP() {
|
||||||
cp /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/peers/org1-peer1.org1.example.com/msp/config.yaml /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/peers/org1-peer2.org1.example.com/msp/config.yaml
|
cp /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/peers/org1-peer1.org1.example.com/msp/config.yaml /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/peers/org1-peer2.org1.example.com/msp/config.yaml
|
||||||
cp /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/peers/org1-peer1.org1.example.com/msp/config.yaml /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml
|
cp /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/peers/org1-peer1.org1.example.com/msp/config.yaml /var/hyperledger/fabric/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml
|
||||||
' | exec kubectl -n $NS exec deploy/org1-ca -i -- /bin/sh
|
' | exec kubectl -n $NS exec deploy/org1-ca -i -- /bin/sh
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_org2_local_MSP() {
|
function create_org2_local_MSP() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue