hyperledger / hyperledger/fabric-samples

Bug: packageCC.sh fails to calculate Package ID when CC_PACKAGE_ONLY is true

Open
#1,404 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3k
Forks
3.5k
Avg merge
3d 20h
Merged PRs (30d)
6

Description

## **Bug Report: `packageCC.sh` fails to calculate Package ID when using the "package only" flag**

## **Context**
The `test-network/scripts/packageCC.sh` script is used to automate the packaging of Hyperledger Fabric chaincode. It supports a `-cco` (Chaincode Package Only) flag, which is intended to package the chaincode without proceeding to the full deployment.

## **The Problem**
There is a path discrepancy in the script between where the package is created and where the script later looks for it to calculate the `Package ID`.

1. **Creation Path:** When `CC_PACKAGE_ONLY` is set to `true`, the package is saved in a subdirectory called `packagedChaincode/` and includes the version in the filename:
* **Filename:** `packagedChaincode/${CC_NAME}_${CC_VERSION}.tar.gz` (See [Line 90](https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/packageCC.sh#L90)).
2. **Verification Path:** After creation, the script immediately attempts to calculate the Package ID, but it looks in the root directory and uses a filename that **does not include the version**:
* **Faulty Command:** `peer lifecycle chaincode calculatepackageid ${CC_NAME}.tar.gz` (See [Line 97](https://github.com/hyperledger/fabric-samples/blob/main/test-network/scripts/packageCC.sh#L97)).

## **Expected Behavior**
When the `package only` flag is enabled, the script should look for the package at `packagedChaincode/${CC_NAME}_${CC_VERSION}.tar.gz` to successfully calculate the Package ID.

## **Actual Behavior**
The script errors out with a `file not found` message (or calculates the ID of an old, stale package in the root directory), causing automation scripts and CI/CD pipelines to fail.

## **Proposed Solution**
Update the `packageChaincode` function to use conditional logic when calculating the Package ID, ensuring it always points to the correct filepath.

**Recommended Code Change:**
```bash
# Inside packageChaincode() function

if [ ${CC_PACKAGE_ONLY} = true ] ; then
# Point to the versioned package in the subdirectory
PACKAGE_ID=$(peer lifecycle chaincode calculatepackageid packagedChaincode/${CC_NAME}_${CC_VERSION}.tar.gz)
else
# Point to the standard package in the root
PACKAGE_ID=$(peer lifecycle chaincode calculatepackageid ${CC_NAME}.tar.gz)
fi
```

## **Environment**
* **Repository:** `hyperledger/fabric-samples`
* **Version:** `main` branch
* **Platform:** All (Bash script issue)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.