Skip to content

Commit

Permalink
Merge pull request #141 from s7techlab/ccpackage
Browse files Browse the repository at this point in the history
ccpackage for chaincode packaging
  • Loading branch information
vitiko committed Dec 4, 2023
2 parents 3cbe1ea + 6f5118d commit f544158
Show file tree
Hide file tree
Showing 38 changed files with 5,458 additions and 469 deletions.
22 changes: 22 additions & 0 deletions cmd/ccpackage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# CCPackage CLI example

```
go run main.go \
--repo=https://github.com/hyperledger-labs/cckit \
--version=main --name=cars \
--chaincodePath=github.com/hyperledger-labs/cckit \
--binaryPath=examples/cars/bin/cars \
--fabricVersion=FABRIC_V2_LIFECYCLE
```

```
go run main.go \
--repo=https://github.com/hyperledger/fabric-samples \
--version=main \
--name=asset-transfer-abac \
--chaincodePath=github.com/hyperledger/fabric-samples \
--binaryPath=asset-transfer-abac/chaincode-go \
--fabricVersion=FABRIC_V2_LIFECYCLE
```


61 changes: 61 additions & 0 deletions cmd/ccpackage/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"flag"
"fmt"
"os"

"go.uber.org/zap"

"github.com/s7techlab/hlf-sdk-go/service/ccpackage"
"github.com/s7techlab/hlf-sdk-go/service/ccpackage/fetcher"
dockerpacker "github.com/s7techlab/hlf-sdk-go/service/ccpackage/packer/docker"
)

func main() {
spec := &ccpackage.PackageSpec{
Id: &ccpackage.PackageID{},
}
flag.StringVar(&spec.Id.Name, `name`, ``, `chaincode name`)
flag.StringVar(&spec.Repository, `repo`, ``, `chaincode repo`)
fabricVersion := flag.String(`fabricVersion`, ``,
`fabric version (FABRIC_V1, FABRIC_V2, fFABRIC_V2_LIFECYCLE`)
flag.StringVar(&spec.ChaincodePath, `chaincodePath`, ``, `chaincode path`)
flag.StringVar(&spec.Id.Version, `version`, ``, `chaincode version`)
flag.StringVar(&spec.BinaryPath, `binaryPath`, ``, `binaryPath`)

flag.Parse()
if *fabricVersion != `` {
if enumVersion, ok := ccpackage.FabricVersion_value[*fabricVersion]; ok {
spec.Id.FabricVersion = ccpackage.FabricVersion(enumVersion)
} else {
fmt.Println(`unknown fabric version: `, *fabricVersion)
os.Exit(1)
}
}

if err := spec.Validate(); err != nil {
fmt.Println(err)
os.Exit(1)
}
var (
logger, _ = zap.NewDevelopment()
ctx = context.Background()
)

tar, err := fetcher.Fetch(ctx, spec.Repository, spec.Id.Version, logger)
if err != nil {
logger.Fatal(err.Error())
}

logger.Info(`package repository source code`, zap.Int(`size`, len(tar)))

packer := dockerpacker.New(logger)
pkg, err := packer.PackFromTar(ctx, spec, tar)
if err != nil {
logger.Fatal(err.Error())
}

fmt.Println(pkg)
}
61 changes: 37 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/onsi/gomega v1.27.10
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.1-0.20210116013205-6990a05d54c2
go.opencensus.io v0.22.0
go.uber.org/zap v1.14.1
golang.org/x/crypto v0.10.0
golang.org/x/crypto v0.14.0
golang.org/x/sync v0.4.0
google.golang.org/genproto v0.0.0-20210122163508-8081c04a3579
google.golang.org/grpc v1.33.1
Expand All @@ -30,37 +30,48 @@ require (
)

require (
github.com/docker/docker v17.12.0-ce-rc1.0.20190628135806-70f67c6240bb+incompatible
github.com/fsouza/go-dockerclient v1.4.1
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.9.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/DataDog/zstd v1.4.0 // indirect
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect
github.com/OpenPeeDeeP/depguard v1.0.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/Shopify/sarama v1.22.1 // indirect
github.com/VictoriaMetrics/fastcache v1.5.7 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v17.12.0-ce-rc1.0.20190628135806-70f67c6240bb+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fsouza/go-dockerclient v1.4.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-lintpack/lintpack v0.5.2 // indirect
github.com/go-toolsmith/astcast v1.0.0 // indirect
Expand All @@ -74,7 +85,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.3.1 // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect
Expand All @@ -95,8 +106,9 @@ require (
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0 // indirect
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/monologue v0.0.0-20190606152607-4b11a32b5934 // indirect
github.com/google/uuid v1.0.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
Expand All @@ -113,14 +125,13 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20200128223036-d1aa2665426a // indirect
github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kisielk/gotool v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lyft/protoc-gen-star/v2 v2.0.3 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
Expand All @@ -129,7 +140,7 @@ require (
github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20171102151520-eafdab6b0663 // indirect
github.com/nxadm/tail v1.4.4 // indirect
github.com/olekukonko/tablewriter v0.0.1 // indirect
Expand All @@ -138,14 +149,17 @@ require (
github.com/opencontainers/runc v1.0.0-rc8 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/pierrec/lz4 v2.5.0+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.1.0 // indirect
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect
github.com/prometheus/common v0.6.0 // indirect
github.com/prometheus/procfs v0.0.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/sourcegraph/go-diff v0.5.1 // indirect
github.com/spf13/afero v1.3.3 // indirect
Expand All @@ -163,23 +177,22 @@ require (
github.com/ultraware/funlen v0.0.1 // indirect
github.com/urfave/cli v1.20.0 // indirect
github.com/willf/bitset v1.1.10 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.3 // indirect
go.etcd.io/etcd v3.3.13+incompatible // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
golang.org/x/tools v0.10.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34 // indirect
Expand Down
Loading

0 comments on commit f544158

Please sign in to comment.