Skip to content

Commit

Permalink
Merge pull request #1 from tr1sm0s1n/main
Browse files Browse the repository at this point in the history
🚑️ | fixed workflow, error-handlers
  • Loading branch information
vineshtk authored Mar 25, 2024
2 parents 013733d + 8366666 commit 9d6c75e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ on:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'

- name: Format
run: gofmt -s -w .

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Clone the repo
cd KbaFabriX
go run main.go
give domain name (eg: auto.com)
give number of organisations
give name of organisation
give number of peers
# FabriX

FabriX is a tool that helps chaincode developers easily set up a Hyperledger Fabric network.

## 🛠 Built With

[![Go](https://img.shields.io/badge/go-dodgerblue?style=for-the-badge&logo=go&logoColor=white)](https://go.dev/)
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var rootCmd = &cobra.Command{
menu.ShowMainMenu()
var userInput string
fmt.Scan(&userInput)
if userInput == "N"{
if userInput == "N" {
menu.GetInputsFromUser()
}
},
Expand Down
68 changes: 31 additions & 37 deletions pkg/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"golang.org/x/text/language"
)

func CreateConfigs(domainName string,orgPeers map[string]int) {
func CreateConfigs(domainName string, orgPeers map[string]int) {

CreateDockerComposeCA(orgPeers)
CreateDockerComposeMembers(domainName,orgPeers)
CreateDockerComposeMembers(domainName, orgPeers)

}

Expand Down Expand Up @@ -66,7 +66,7 @@ func CreateDockerComposeCA(orgPeers map[string]int) {
"test",
}
viper.Set("services.ca_orderer.networks", networkSlice)

// create configs for all the organisations
for org := range orgPeers {
org := strings.ToLower(org)
Expand Down Expand Up @@ -106,11 +106,9 @@ func CreateDockerComposeCA(orgPeers map[string]int) {

viper.Set(fmt.Sprintf("services.ca_%v.networks", org), networkSlice)

err := viper.SafeWriteConfig()
if err != nil {
if err := viper.SafeWriteConfig(); err != nil {
if _, ok := err.(viper.ConfigFileAlreadyExistsError); ok {
err = viper.WriteConfig()
if err != nil {
if err = viper.WriteConfig(); err != nil {
log.Fatalf("Error while updating config file %s", err)
}
} else {
Expand All @@ -129,7 +127,7 @@ func CreateRegisterEnroll(orgPeers map[string]int) {
// how to impliment since viper dont support script file
}

func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {
func CreateDockerComposeMembers(domainName string, orgPeers map[string]int) {

//viper.KeyDelimiter(":") to adjest the key delimiter from "." to ":"
// for adding keys like "orderer.example.com"
Expand All @@ -140,14 +138,14 @@ func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {
custom_viper.AddConfigPath("pkg/configs/generated/docker")
custom_viper.Set("version", "3.7")
custom_viper.Set("networks:test:name", "fabric_test")
// volumes will be added when the peers are created
// volumes will be added when the peers are created

// creating configs for ordering service
custom_viper.Set(fmt.Sprintf("volumes:orderer.%v",domainName), "")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:container_name",domainName ) ,fmt.Sprintf("orderer.%v", domainName) )
custom_viper.Set(fmt.Sprintf("services:orderer.%v:image", domainName) , "hyperledger/fabric-orderer:2.5.4")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:labels:service",domainName ) , "hyperledger-fabric")

custom_viper.Set(fmt.Sprintf("volumes:orderer.%v", domainName), "")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:container_name", domainName), fmt.Sprintf("orderer.%v", domainName))
custom_viper.Set(fmt.Sprintf("services:orderer.%v:image", domainName), "hyperledger/fabric-orderer:2.5.4")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:labels:service", domainName), "hyperledger-fabric")

ordererEnv := []string{
"FABRIC_LOGGING_SPEC=INFO",
Expand All @@ -171,11 +169,11 @@ func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {
"ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]",
"ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]",
"ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:7053",
fmt.Sprintf("ORDERER_OPERATIONS_LISTENADDRESS=orderer.%v:9443",domainName),
fmt.Sprintf("ORDERER_OPERATIONS_LISTENADDRESS=orderer.%v:9443", domainName),
"ORDERER_METRICS_PROVIDER=prometheus",
}
custom_viper.Set(fmt.Sprintf("services:orderer.%v:environment",domainName), ordererEnv)
custom_viper.Set(fmt.Sprintf("services:orderer.%v:working_dir", domainName) , "/root")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:environment", domainName), ordererEnv)
custom_viper.Set(fmt.Sprintf("services:orderer.%v:working_dir", domainName), "/root")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:command", domainName), "orderer")

// correct the domain name or keep the example.com
Expand All @@ -196,7 +194,7 @@ func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {
networkSlice := []string{
"test",
}
custom_viper.Set(fmt.Sprintf("services:orderer.%v:networks", domainName) , networkSlice)
custom_viper.Set(fmt.Sprintf("services:orderer.%v:networks", domainName), networkSlice)

// configs for CLI
custom_viper.Set("services:cli:container_name", "cli")
Expand Down Expand Up @@ -224,7 +222,7 @@ func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {

// CLI depends will be added from the for loop
CLIDepends := []string{}

// for creating port numbers dynamically as well keeping the peer count
i := 0
ports := []int{
Expand Down Expand Up @@ -278,35 +276,35 @@ func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {
fmt.Sprintf("CORE_PEER_ID=peer%v.%v.%v", peer, org, domainName),
fmt.Sprintf("CORE_PEER_ADDRESS=peer%v.%v.%v:%v", peer, org, domainName, ports[1]+i*2000),
fmt.Sprintf("CORE_PEER_LISTENADDRESS=0.0.0.0:%v", ports[1]+i*2000),
fmt.Sprintf("CORE_PEER_CHAINCODEADDRESS=peer%v.%v.%v:%v", peer, org, domainName,ports[1]+i*2000+1),
fmt.Sprintf("CORE_PEER_CHAINCODEADDRESS=peer%v.%v.%v:%v", peer, org, domainName, ports[1]+i*2000+1),
fmt.Sprintf("CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:%v", ports[1]+i*2000+1),
fmt.Sprintf("CORE_PEER_GOSSIP_BOOTSTRAP=peer%v.%v.%v:%v", peer, org, domainName, ports[1]+i*2000),
fmt.Sprintf("CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer%v.%v.%v:%v", peer, org, domainName,ports[1]+i*2000),
fmt.Sprintf("CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer%v.%v.%v:%v", peer, org, domainName, ports[1]+i*2000),
fmt.Sprintf("CORE_PEER_LOCALMSPID=%v", orgMSP),
"CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp",
fmt.Sprintf("CORE_OPERATIONS_LISTENADDRESS=peer%v.%v.%v:%v", peer, org, domainName,ports[2]+i*1),
fmt.Sprintf("CORE_OPERATIONS_LISTENADDRESS=peer%v.%v.%v:%v", peer, org, domainName, ports[2]+i*1),
"CORE_METRICS_PROVIDER=prometheus",
fmt.Sprintf("CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={'peername':'peer%v%v'}", peer, org),
"CORE_CHAINCODE_EXECUTETIMEOUT=300s",
"CORE_LEDGER_STATE_STATEDATABASE=CouchDB",
fmt.Sprintf("CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=%v:5984", fmt.Sprintf("%vpeer%vdb", org, peer)),
fmt.Sprintf("CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=%v:5984", fmt.Sprintf("%vpeer%vdb", org, peer)),
"CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin",
"CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=adminpw",
}
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:environment", peer, org, domainName), peerEnv)

peerVolumes := []string{
"/var/run/docker.sock:/host/var/run/docker.sock",
fmt.Sprintf("../organizations/peerOrganizations/%v.%v/peers/peer%v.%v.%v:/etc/hyperledger/fabric",org,domainName,peer,org, domainName),
fmt.Sprintf("peer%v.%v.%v:/var/hyperledger/production",peer,org, domainName ),
fmt.Sprintf("../organizations/peerOrganizations/%v.%v/peers/peer%v.%v.%v:/etc/hyperledger/fabric", org, domainName, peer, org, domainName),
fmt.Sprintf("peer%v.%v.%v:/var/hyperledger/production", peer, org, domainName),
}
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:volumes", peer, org, domainName), peerVolumes)

custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:working_dir", peer, org, domainName), "/root")
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:command", peer, org, domainName), "peer node start")
peerPorts := []string{
fmt.Sprintf("%v:%v", ports[1]+i*2000, ports[1]+i*2000),
fmt.Sprintf("%v:%v",ports[2]+i*1, ports[2]+i*1),
fmt.Sprintf("%v:%v", ports[2]+i*1, ports[2]+i*1),
}
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:ports", peer, org, domainName), peerPorts)

Expand All @@ -324,12 +322,9 @@ func CreateDockerComposeMembers(domainName string,orgPeers map[string]int) {
CLIDepends = append(CLIDepends, fmt.Sprintf("peer%v.%v.%v", peer, org, domainName))
custom_viper.Set("services:cli:depends_on", CLIDepends)


err := custom_viper.SafeWriteConfig()
if err != nil {
if err := custom_viper.SafeWriteConfig(); err != nil {
if _, ok := err.(viper.ConfigFileAlreadyExistsError); ok {
err = custom_viper.WriteConfig()
if err != nil {
if err = custom_viper.WriteConfig(); err != nil {
log.Fatalf("Error while updating config file %s", err)
}
} else {
Expand Down Expand Up @@ -418,9 +413,8 @@ func CreateConfigTx() {
// fmt.Println("Configuration file created/updated successfully!")
// }


// volumeMap := map[string]string{
// "orderer.example.com": "",
// "peer0.manufacturer.example.com": "",
// "peer0.dealer.example.com": "",
// }
// volumeMap := map[string]string{
// "orderer.example.com": "",
// "peer0.manufacturer.example.com": "",
// "peer0.dealer.example.com": "",
// }

0 comments on commit 9d6c75e

Please sign in to comment.