Skip to content

Commit 3bb45bb

Browse files
author
Shoaeb Jindani
committed
Initial Commit
Signed-off-by: Shoaeb Jindani <jindani.shoaeb@ibm.com>
1 parent 24721fb commit 3bb45bb

File tree

91 files changed

+13749
-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

+13749
-0
lines changed

.github/workflows/main.yml

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