Skip to content

Commit

Permalink
[FAB-6184] Improve Fabric vendoring (scripts)
Browse files Browse the repository at this point in the history
This patch adds pinning capability for Hyperledger
Fabric dependencies. The packages are split between
internal and external paths.

Change-Id: Ia56ff0977ea567c16a068eec712ac1248fcbf101
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Sep 18, 2017
1 parent 591cea8 commit 4bfb47e
Show file tree
Hide file tree
Showing 11 changed files with 700 additions and 114 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export DOCKER_NS=hyperledger
export DOCKER_TAG=$(ARCH)-0.3.1
export GO_DEP_COMMIT=v0.3.0 # the version of dep that will be installed by depend-install (or in the CI)

export FABRIC_CA_COMMIT=v1.0.1
# Upstream fabric patching
THIRDPARTY_FABRIC_CA_BRANCH=release
THIRDPARTY_FABRIC_CA_COMMIT=v1.0.1
THIRDPARTY_FABRIC_BRANCH=master
THIRDPARTY_FABRIC_COMMIT=a657db28a0ff53ed512bd6f4ac4786a0f4ca709c

# Detect CI
ifdef JENKINS_URL
Expand Down Expand Up @@ -94,7 +98,8 @@ mock-gen:
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api/apifabca FabricCAClient | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/apifabca/mocks/mockfabriccaclient.gen.go

thirdparty-pin:
UPSTREAM_COMMIT=$(FABRIC_CA_COMMIT) scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh
UPSTREAM_COMMIT=$(THIRDPARTY_FABRIC_COMMIT) UPSTREAM_BRANCH=$(THIRDPARTY_FABRIC_BRANCH) scripts/third_party_pins/fabric/apply_upstream.sh
UPSTREAM_COMMIT=$(THIRDPARTY_FABRIC_CA_COMMIT) UPSTREAM_BRANCH=$(THIRDPARTY_FABRIC_CA_BRANCH) scripts/third_party_pins/fabric-ca/apply_upstream.sh

populate: populate-vendor

Expand Down
111 changes: 0 additions & 111 deletions scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh

This file was deleted.

78 changes: 78 additions & 0 deletions scripts/third_party_pins/fabric-ca/apply_fabric_ca_client_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# This script pins the BCCSP package family from Hyperledger Fabric into the SDK
# These files are checked into internal paths.
# Note: This script must be adjusted as upstream makes adjustments

IMPORT_SUBSTS=($IMPORT_SUBSTS)

declare -a PKGS=(
"api"
"lib"
"lib/tls"
"lib/tcert"
"lib/spi"
"util"
)

declare -a FILES=(
"api/client.go"
"api/net.go"

"lib/client.go"
"lib/identity.go"
"lib/signer.go"
"lib/clientconfig.go"
"lib/util.go"
"lib/serverstruct.go"

"lib/tls/tls.go"

"lib/tcert/api.go"
"lib/tcert/util.go"
"lib/tcert/tcert.go"
"lib/tcert/keytree.go"

"lib/spi/affiliation.go"
"lib/spi/userregistry.go"

"util/util.go"
"util/args.go"
"util/csp.go"
"util/struct.go"
"util/flag.go"
)

echo 'Removing current upstream project from working directory ...'
rm -Rf "${INTERNAL_PATH}"
mkdir -p "${INTERNAL_PATH}"

# Create directory structure for packages
for i in "${PKGS[@]}"
do
mkdir -p $INTERNAL_PATH/${i}
done

# Apply global import patching
echo "Patching import paths on upstream project ..."
for i in "${FILES[@]}"
do
for subst in "${IMPORT_SUBSTS[@]}"
do
sed -i '' -e $subst $TMP_PROJECT_PATH/${i}
done
goimports -w $TMP_PROJECT_PATH/${i}
done

# Copy patched project into internal paths
echo "Copying patched upstream project into working directory ..."
for i in "${FILES[@]}"
do
TARGET_PATH=`dirname $INTERNAL_PATH/${i}`
cp $TMP_PROJECT_PATH/${i} $TARGET_PATH
done
51 changes: 51 additions & 0 deletions scripts/third_party_pins/fabric-ca/apply_upstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# This script fetches code used in the SDK originating from other Hyperledger Fabric projects
# These files are checked into internal paths.
# Note: This script must be adjusted as upstream makes adjustments

UPSTREAM_PROJECT="github.com/hyperledger/fabric-ca"
UPSTREAM_BRANCH="release"
SCRIPTS_PATH="scripts/third_party_pins/fabric-ca"
PATCHES_PATH="scripts/third_party_pins/fabric-ca/patches"

THIRDPARTY_INTERNAL_FABRIC_CA_PATH='internal/github.com/hyperledger/fabric-ca'

####
# Clone and patch packages into repo

# Clone original project into temporary directory
echo "Fetching upstream project ($UPSTREAM_PROJECT:$UPSTREAM_COMMIT) ..."
CWD=`pwd`
TMP=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`

TMP_PROJECT_PATH=$TMP/src/$UPSTREAM_PROJECT
mkdir -p $TMP_PROJECT_PATH
cd ${TMP_PROJECT_PATH}/..

git clone https://${UPSTREAM_PROJECT}.git
cd $TMP_PROJECT_PATH
git checkout $UPSTREAM_BRANCH
git reset --hard $UPSTREAM_COMMIT

echo "Patching upstream project ..."
git am ${CWD}/${PATCHES_PATH}/*

cd $CWD

# fabric-ca client utils
echo "Pinning and patching fabric-ca client utils..."
declare -a CLIENT_UTILS_IMPORT_SUBSTS=(
's/\"github.com\/hyperledger\/fabric-ca/\"github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric-ca/g'
's/\"github.com\/hyperledger\/fabric\/bccsp/\"github.com\/hyperledger\/fabric-sdk-go\/pkg\/third_party\/bccsp/g'
)
eval "INTERNAL_PATH=$THIRDPARTY_INTERNAL_FABRIC_CA_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS=\"${CLIENT_UTILS_IMPORT_SUBSTS[*]}\" $SCRIPTS_PATH/apply_fabric_ca_client_utils.sh"

# Cleanup temporary files from patch application
echo "Removing temporary files ..."
rm -Rf $TMP
99 changes: 99 additions & 0 deletions scripts/third_party_pins/fabric/apply_fabric_bccsp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# This script pins the BCCSP package family from Hyperledger Fabric into the SDK
# These files are checked into internal paths.
# Note: This script must be adjusted as upstream makes adjustments

IMPORT_SUBSTS=($IMPORT_SUBSTS)

declare -a PKGS=(
"bccsp"
"bccsp/factory"
"bccsp/pkcs11"
"bccsp/signer"
"bccsp/sw"
"bccsp/utils"
)

declare -a FILES=(
"bccsp/aesopts.go"
"bccsp/bccsp.go"
"bccsp/ecdsaopts.go"
"bccsp/hashopts.go"
"bccsp/keystore.go"
"bccsp/opts.go"
"bccsp/rsaopts.go"
"bccsp/rsaopts.go"
"bccsp/rsaopts.go"

"bccsp/factory/factory.go"
"bccsp/factory/nopkcs11.go"
"bccsp/factory/opts.go"
"bccsp/factory/pkcs11.go"
"bccsp/factory/pkcs11factory.go"
"bccsp/factory/swfactory.go"

"bccsp/pkcs11/conf.go"
"bccsp/pkcs11/ecdsa.go"
"bccsp/pkcs11/ecdsakey.go"
"bccsp/pkcs11/impl.go"
"bccsp/pkcs11/pkcs11.go"

"bccsp/signer/signer.go"

"bccsp/sw/aes.go"
"bccsp/sw/aeskey.go"
"bccsp/sw/conf.go"
"bccsp/sw/dummyks.go"
"bccsp/sw/ecdsa.go"
"bccsp/sw/ecdsakey.go"
"bccsp/sw/fileks.go"
"bccsp/sw/hash.go"
"bccsp/sw/impl.go"
"bccsp/sw/internals.go"
"bccsp/sw/keyderiv.go"
"bccsp/sw/keygen.go"
"bccsp/sw/keyimport.go"
"bccsp/sw/rsa.go"
"bccsp/sw/rsakey.go"

"bccsp/utils/errs.go"
"bccsp/utils/io.go"
"bccsp/utils/keys.go"
"bccsp/utils/slice.go"
"bccsp/utils/x509.go"
)

echo 'Removing current upstream project from working directory ...'
rm -Rf "${INTERNAL_PATH}/bccsp"
mkdir -p "${INTERNAL_PATH}/bccsp"

# Create directory structure for packages
for i in "${PKGS[@]}"
do
mkdir -p $INTERNAL_PATH/${i}
done

# Apply global import patching
echo "Patching import paths on upstream project ..."
for i in "${FILES[@]}"
do
for subst in "${IMPORT_SUBSTS[@]}"
do
sed -i '' -e $subst $TMP_PROJECT_PATH/${i}
done
goimports -w $TMP_PROJECT_PATH/${i}
done

# Copy patched project into internal paths
echo "Copying patched upstream project into working directory ..."
for i in "${FILES[@]}"
do
TARGET_PATH=`dirname $INTERNAL_PATH/${i}`
cp $TMP_PROJECT_PATH/${i} $TARGET_PATH
done
Loading

0 comments on commit 4bfb47e

Please sign in to comment.