Creating a chaincode package¶
To create a k8s chaincode package file, start by creating an image.json
file.
For example,
cat << IMAGEJSON-EOF > image.json
{
"name": "ghcr.io/hyperledger-labs/go-contract",
"digest": "sha256:802c336235cc1e7347e2da36c73fa2e4b6437cfc6f52872674d1e23f23bba63b"
}
IMAGEJSON-EOF
The k8s builder uses digests because these are immutable, unlike tags. The docker inspect command can be used to find the digest if required.
docker pull ghcr.io/hyperledger-labs/go-contract:v0.7.2
docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/hyperledger-labs/go-contract:v0.7.2 | cut -d'@' -f2
Create a code.tar.gz
archive containing the image.json
file.
Create a metadata.json
file for the chaincode package.
For example,
Create the final chaincode package archive.
Ideally the chaincode package should be created in the same CI/CD pipeline which builds the docker image. There is an example package-k8s-chaincode-action GitHub Action which can create the required k8s chaincode package.
The GitHub Action repository includes a basic shell script which can also be used for automating the process above outside GitHub workflows.
For example, to create a basic k8s chaincode package using the pkgk8scc.sh
helper script.