-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external builders for golang and node chaincode to test-network-n…
…ano-bash The external builders will build and launch binary chaincode instead of docker containers. Signed-off-by: Chris Elder <[email protected]>
- Loading branch information
Chris Elder
authored and
Chris Elder
committed
Jun 6, 2024
1 parent
e4af8fe
commit 75258db
Showing
16 changed files
with
264 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env sh | ||
|
||
mkdir -p config | ||
|
||
sed -e '/externalBuilders:/r ./external_builders/core_yaml_change.yaml' ../config/core.yaml | sed -e "s|_working_dir_|$PWD|g" > ./config/core.yaml | ||
|
12 changes: 12 additions & 0 deletions
12
test-network-nano-bash/external_builders/core_yaml_change.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- name: golang | ||
path: _working_dir_/external_builders/golang | ||
propagateEnvironment: | ||
- GOCACHE | ||
- GOENV | ||
- HOME | ||
- GOPROXY | ||
- name: node | ||
path: _working_dir_/external_builders/node | ||
propagateEnvironment: | ||
- HOME | ||
- npm_config_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -euo pipefail | ||
exec 1>&2 | ||
CHAINCODE_SOURCE_DIR="$1" | ||
CHAINCODE_METADATA_DIR="$2" | ||
BUILD_OUTPUT_DIR="$3" | ||
GO_PACKAGE_PATH="$(jq -r .path "${CHAINCODE_METADATA_DIR}/metadata.json")" | ||
if [ -f "${CHAINCODE_SOURCE_DIR}/src/go.mod" ]; then | ||
cd "${CHAINCODE_SOURCE_DIR}/src" | ||
CGO_ENABLED=0 go build -v -o "${BUILD_OUTPUT_DIR}/chaincode" "${GO_PACKAGE_PATH}" | ||
else | ||
CGO_ENABLED=0 GOPATH="${CHAINCODE_SOURCE_DIR}" GO111MODULE=off go build -v -o "${BUILD_OUTPUT_DIR}/chaincode" "${GO_PACKAGE_PATH}" | ||
fi |
11 changes: 11 additions & 0 deletions
11
test-network-nano-bash/external_builders/golang/bin/detect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -euo pipefail | ||
exec 1>&2 | ||
CHAINCODE_METADATA_DIR="$2" | ||
if [ "$(jq -r .type "${CHAINCODE_METADATA_DIR}/metadata.json" | tr '[:upper:]' '[:lower:]')" = "golang" ]; then | ||
exit 0 | ||
fi | ||
exit 1 |
12 changes: 12 additions & 0 deletions
12
test-network-nano-bash/external_builders/golang/bin/release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -xeuo pipefail | ||
exec 1>&2 | ||
|
||
BUILD_OUTPUT_DIR="$1" | ||
RELEASE_OUTPUT_DIR="$2" | ||
if [ -d "${BUILD_OUTPUT_DIR}/META-INF" ] ; then | ||
cp -a "${BUILD_OUTPUT_DIR}/META-INF/"* "${RELEASE_OUTPUT_DIR}/" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -xeuo pipefail | ||
exec 1>&2 | ||
BUILD_OUTPUT_DIR="$1" | ||
RUN_METADATA_DIR="$2" | ||
|
||
####################################### | ||
# Export environment variables and extract certificate files from chaincode.json | ||
# Globals: | ||
# None | ||
# Arguments: | ||
# METADATA_DIR: Location of the chaincode.json file | ||
# Returns: | ||
# None | ||
####################################### | ||
function process_chaincode_metadata_json { | ||
local METADATA_DIR=${RUN_METADATA_DIR} | ||
|
||
CORE_CHAINCODE_ID_NAME="$(jq -r .chaincode_id "$METADATA_DIR/chaincode.json")" | ||
CORE_PEER_ADDRESS="$(jq -r .peer_address "$METADATA_DIR/chaincode.json")" | ||
CORE_PEER_LOCALMSPID="$(jq -r .mspid "$METADATA_DIR/chaincode.json")" | ||
export CORE_CHAINCODE_ID_NAME | ||
export CORE_PEER_ADDRESS | ||
export CORE_PEER_LOCALMSPID | ||
|
||
if [ -z "$(jq -r .client_cert "$METADATA_DIR/chaincode.json")" ]; then | ||
CORE_PEER_TLS_ENABLED="false" | ||
export CORE_PEER_TLS_ENABLED | ||
else | ||
CORE_PEER_TLS_ENABLED="true" | ||
CORE_TLS_CLIENT_CERT_FILE="$BUILD_OUTPUT_DIR/client.crt" | ||
CORE_TLS_CLIENT_KEY_FILE="$BUILD_OUTPUT_DIR/client.key" | ||
CORE_PEER_TLS_ROOTCERT_FILE="$BUILD_OUTPUT_DIR/root.crt" | ||
export CORE_PEER_TLS_ENABLED | ||
export CORE_TLS_CLIENT_CERT_FILE | ||
export CORE_TLS_CLIENT_KEY_FILE | ||
export CORE_PEER_TLS_ROOTCERT_FILE | ||
|
||
jq -r .client_cert "$METADATA_DIR/chaincode.json" >"$CORE_TLS_CLIENT_CERT_FILE" | ||
jq -r .client_key "$METADATA_DIR/chaincode.json" >"$CORE_TLS_CLIENT_KEY_FILE" | ||
jq -r .root_cert "$METADATA_DIR/chaincode.json" >"$CORE_PEER_TLS_ROOTCERT_FILE" | ||
fi | ||
} | ||
|
||
# extract the required environment variables | ||
process_chaincode_metadata_json | ||
|
||
# output for debug purposes | ||
env | grep CORE | sort | ||
|
||
|
||
exec "${BUILD_OUTPUT_DIR}/chaincode" -peer.address="${CORE_PEER_ADDRESS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -euo pipefail | ||
exec 1>&2 | ||
CHAINCODE_SOURCE_DIR="$1" | ||
# CHAINCODE_METADATA_DIR="$2" | ||
BUILD_OUTPUT_DIR="$3" | ||
cd "${CHAINCODE_SOURCE_DIR}/src" | ||
tar cf - . | (cd "${BUILD_OUTPUT_DIR}" && tar xf -) | ||
cd "${BUILD_OUTPUT_DIR}" | ||
if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then | ||
npm ci --only=production | ||
else | ||
npm install --production | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -euo pipefail | ||
exec 1>&2 | ||
CHAINCODE_METADATA_DIR="$2" | ||
if [ "$(jq -r .type "${CHAINCODE_METADATA_DIR}/metadata.json" | tr '[:upper:]' '[:lower:]')" = "node" ]; then | ||
exit 0 | ||
fi | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -euo pipefail | ||
exec 1>&2 | ||
BUILD_OUTPUT_DIR="$1" | ||
RELEASE_OUTPUT_DIR="$2" | ||
if [ -d "${BUILD_OUTPUT_DIR}/META-INF" ] ; then | ||
cp -a "${BUILD_OUTPUT_DIR}/META-INF/"* "${RELEASE_OUTPUT_DIR}/" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -xeuo pipefail | ||
exec 1>&2 | ||
|
||
BUILD_OUTPUT_DIR="$1" | ||
RUN_METADATA_DIR="$2" | ||
|
||
cd "${BUILD_OUTPUT_DIR}" | ||
ls -lart | ||
|
||
# extract the id, mspid, and peer address | ||
CORE_CHAINCODE_ID_NAME="$(jq -r .chaincode_id "${RUN_METADATA_DIR}/chaincode.json")" | ||
CORE_PEER_LOCALMSPID="$(jq -r .mspid "${RUN_METADATA_DIR}/chaincode.json")" | ||
CORE_PEER_ADDRESS="$(jq -r .peer_address "${RUN_METADATA_DIR}/chaincode.json")" | ||
export CORE_CHAINCODE_ID_NAME CORE_PEER_LOCALMSPID CORE_PEER_ADDRESS | ||
|
||
# process the TLS options if needed | ||
if [ -z "$(jq -r .client_cert "$RUN_METADATA_DIR/chaincode.json")" ]; then | ||
CORE_PEER_TLS_ENABLED="false" | ||
export CORE_PEER_TLS_ENABLED | ||
else | ||
|
||
export CORE_PEER_TLS_ENABLED="true" | ||
export CORE_TLS_CLIENT_CERT_FILE="$BUILD_OUTPUT_DIR/client-pem.crt" | ||
export CORE_TLS_CLIENT_KEY_FILE="$BUILD_OUTPUT_DIR/client-pem.key" | ||
export CORE_TLS_CLIENT_CERT_PATH="$BUILD_OUTPUT_DIR/client.crt" | ||
export CORE_TLS_CLIENT_KEY_PATH="$BUILD_OUTPUT_DIR/client.key" | ||
|
||
export CORE_PEER_TLS_ROOTCERT_FILE="$BUILD_OUTPUT_DIR/root.crt" | ||
|
||
jq -r .client_cert "$RUN_METADATA_DIR/chaincode.json" > "$CORE_TLS_CLIENT_CERT_FILE" | ||
jq -r .client_key "$RUN_METADATA_DIR/chaincode.json" > "$CORE_TLS_CLIENT_KEY_FILE" | ||
jq -r .root_cert "$RUN_METADATA_DIR/chaincode.json" > "$CORE_PEER_TLS_ROOTCERT_FILE" | ||
|
||
base64 -i "${CORE_TLS_CLIENT_CERT_FILE}" > "${CORE_TLS_CLIENT_CERT_PATH}" | ||
base64 -i "${CORE_TLS_CLIENT_KEY_FILE}" > "${CORE_TLS_CLIENT_KEY_PATH}" | ||
|
||
#base64 -w 0 "${CORE_TLS_CLIENT_CERT_FILE}" > "${CORE_TLS_CLIENT_CERT_PATH}" | ||
#base64 -w 0 "${CORE_TLS_CLIENT_KEY_FILE}" > "${CORE_TLS_CLIENT_KEY_PATH}" | ||
|
||
ls -lart "$BUILD_OUTPUT_DIR" | ||
fi | ||
|
||
# output for debug purposes | ||
env | grep CORE | sort | ||
|
||
# run the chaincode | ||
exec npm start -- --peer.address="${CORE_PEER_ADDRESS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters