Skip to content

Commit 6e284a1

Browse files
Initial Commit and Source Code for Chaincode Builder (#1)
* Initial Commit Signed-off-by: Shoaeb Jindani <jindani.shoaeb@ibm.com>
1 parent 24721fb commit 6e284a1

File tree

91 files changed

+13754
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+13754
-0
lines changed

.github/workflows/main.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Temporarily Skipped Workflow
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
dummy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Temporary Pass
14+
run: echo "Workflow skipped for now"
15+
16+
# unit-tests:
17+
# runs-on: ubuntu-latest
18+
# steps:
19+
# - uses: actions/checkout@v2
20+
# - name: Set up Go
21+
# uses: actions/setup-go@v2
22+
# with:
23+
# go-version: 1.23.x
24+
# - name: Run unit tests
25+
# run: make unit-tests
26+
27+
# checks:
28+
# runs-on: ubuntu-latest
29+
# steps:
30+
# - uses: actions/checkout@v2
31+
# - name: Set up Go
32+
# uses: actions/setup-go@v2
33+
# with:
34+
# go-version: 1.23.x
35+
# - name: Run checks
36+
# run: make checks
37+
38+
# gosec:
39+
# runs-on: ubuntu-latest
40+
# steps:
41+
# - uses: actions/checkout@v2
42+
# - name: Set up Go
43+
# uses: actions/setup-go@v2
44+
# with:
45+
# go-version: 1.23.x
46+
# - name: Run gosec
47+
# run: make gosec
48+
49+
# build-image:
50+
# runs-on: ubuntu-latest
51+
# steps:
52+
# - uses: actions/checkout@v2
53+
# - name: Set up Go
54+
# uses: actions/setup-go@v2
55+
# with:
56+
# go-version: 1.23.x
57+
# - name: Build and push image
58+
# run: |
59+
# make image
60+
# make image-push

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vendor/
2+
build/
3+
.env
4+
golang_copyright.txt
5+
shell_copyright.txt
6+
launch.json

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# External Chaincode Builder and Launcher for Kubernetes
2+
3+
This is chaincode builder that uses **Kubernetes bare pods** to build and run [Hyperledger Fabric](https://www.hyperledger.org/use/fabric) chaincode.
4+
5+
The goal is to provide a Kubernetes-native way to handle external builders and launchers for Fabric chaincode deployments.
6+
7+
---
8+
9+
## Features
10+
11+
- Uses Kubernetes bare pods for chaincode build and execution.
12+
- Integrates with the [Fabric Operator](https://github.com/hyperledger-labs/fabric-operator) and the [Fabric Operations Console](https://github.com/hyperledger-labs/fabric-operations-console).
13+
- Simplifies development workflows on Kubernetes without relying on Docker-in-Docker or privileged containers.
14+
15+
---
16+
17+
## Getting Started
18+
19+
20+
21+
### Run the Tests
22+
23+
Once Kubernetes is enabled on Docker Desktop:
24+
25+
```bash
26+
go test ./...
27+
```
28+
29+
---
30+
31+
## Usage with Fabric Operator & Fabric Operations Console
32+
33+
This external builder is compatible with both:
34+
35+
- [Fabric Operator](https://github.com/hyperledger-labs/fabric-operator): Automates lifecycle management of Fabric networks on Kubernetes.
36+
- [Fabric Operations Console](https://github.com/hyperledger-labs/fabric-operations-console): A GUI-based tool to interact with and manage Hyperledger Fabric networks.
37+
38+
You can configure this external chaincode builder within your operator or console deployment for custom chaincode packaging and deployment flows.
39+
40+
---
41+
42+
## License
43+
44+
[Apache 2.0](LICENSE)

cmd/ibp-builder-client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ibp-builder-client

cmd/ibp-builder-client/main.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package main
17+
18+
import (
19+
"context"
20+
"fmt"
21+
"io"
22+
"os"
23+
"path/filepath"
24+
"time"
25+
26+
"github.com/hyperledger-labs/fabric-chaincode-builder/pkg/command"
27+
"github.com/hyperledger-labs/fabric-chaincode-builder/pkg/logger"
28+
29+
"google.golang.org/grpc"
30+
)
31+
32+
// A Command represents an object that executes an external builder
33+
// command.
34+
type Command interface {
35+
Run(stderr io.Writer, args ...string) (rc int, err error)
36+
}
37+
38+
func main() {
39+
logLevel := os.Getenv("LOGLEVEL")
40+
logger.SetupLogging(logLevel)
41+
42+
log := logger.Logger.Sugar()
43+
log.Info("Log level set to: ", logger.GetLogLevel(logLevel).CapitalString())
44+
45+
var cmd Command
46+
47+
sharedDir := os.Getenv("IBP_BUILDER_SHARED_DIR")
48+
builderEndpoint := os.Getenv("IBP_BUILDER_ENDPOINT")
49+
50+
grpcConn, err := newGRPCClientConn(builderEndpoint)
51+
if err != nil {
52+
fmt.Fprintf(os.Stderr, "Failed to create connection to %s: %s", builderEndpoint, err)
53+
os.Exit(10)
54+
}
55+
defer grpcConn.Close()
56+
57+
switch filepath.Base(os.Args[0]) {
58+
case "detect":
59+
cmd = &command.Detect{}
60+
61+
case "build":
62+
cmd = &command.Build{
63+
SharedDir: sharedDir,
64+
GRPCClient: grpcConn,
65+
Logger: log,
66+
}
67+
68+
case "release":
69+
cmd = &command.Release{}
70+
71+
case "run":
72+
cmd = &command.Run{
73+
SharedDir: sharedDir,
74+
GRPCClient: grpcConn,
75+
}
76+
77+
default:
78+
fmt.Fprintf(os.Stderr, "Unexpected command: %s", filepath.Base(os.Args[0]))
79+
os.Exit(99)
80+
}
81+
82+
rc, err := cmd.Run(os.Stderr, os.Args[1:]...)
83+
if err != nil {
84+
fmt.Fprintf(os.Stderr, "External builder failed: %s\n", err)
85+
os.Exit(3)
86+
}
87+
88+
os.Exit(rc)
89+
}
90+
91+
func newGRPCClientConn(endpoint string) (*grpc.ClientConn, error) {
92+
timeoutContext, cancel := context.WithTimeout(context.Background(), 5*time.Second)
93+
defer cancel()
94+
95+
return grpc.DialContext(timeoutContext, endpoint, grpc.WithInsecure(), grpc.WithBlock())
96+
}

cmd/ibp-builder/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ibp-builder

0 commit comments

Comments
 (0)