Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
run: go test -v ./...
env:
FABRIC_K8S_BUILDER_DEBUG: 'true'
INCLUDE_KIND_TESTS: ${{ matrix.os == 'ubuntu-latest' && 'true' || 'false' }}

- name: Package
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
go-version: 1.22
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: golangci-lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
with:
version: v1.56.2
version: v1.62
5 changes: 2 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- cyclop
- decorder
- dogsled
Expand All @@ -17,9 +18,7 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
Expand All @@ -35,7 +34,6 @@ linters:
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
Expand All @@ -49,6 +47,7 @@ linters:
- maintidx
- makezero
- misspell
- mnd
- nakedret
- nestif
- nilerr
Expand Down
56 changes: 56 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"context"
"os"
"strconv"

"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
)

func Build() int {
const (
expectedArgsLength = 4
chaincodeSourceDirectoryArg = 1
chaincodeMetadataDirectoryArg = 2
buildOutputDirectoryArg = 3
)

debug, _ := strconv.ParseBool(util.GetOptionalEnv(util.DebugVariable, "false"))
ctx := log.NewCmdContext(context.Background(), debug)
logger := log.New(ctx)

if len(os.Args) != expectedArgsLength {
logger.Println(
"Expected CHAINCODE_SOURCE_DIR, CHAINCODE_METADATA_DIR and BUILD_OUTPUT_DIR arguments",
)

return 1
}

chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]
buildOutputDirectory := os.Args[buildOutputDirectoryArg]

logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)
logger.Debugf("Build output directory: %s", buildOutputDirectory)

build := &builder.Build{
ChaincodeSourceDirectory: chaincodeSourceDirectory,
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
BuildOutputDirectory: buildOutputDirectory,
}

if err := build.Run(ctx); err != nil {
logger.Printf("Error building chaincode: %+v", err)

return 1
}

return 0
}
42 changes: 2 additions & 40 deletions cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,11 @@
package main

import (
"context"
"os"

"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
)

const (
expectedArgsLength = 4
chaincodeSourceDirectoryArg = 1
chaincodeMetadataDirectoryArg = 2
buildOutputDirectoryArg = 3
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
)

func main() {
debug := util.GetOptionalEnv(util.DebugVariable, "false")
ctx := log.NewCmdContext(context.Background(), debug == "true")
logger := log.New(ctx)

if len(os.Args) != expectedArgsLength {
logger.Println(
"Expected CHAINCODE_SOURCE_DIR, CHAINCODE_METADATA_DIR and BUILD_OUTPUT_DIR arguments",
)
os.Exit(1)
}

chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]
buildOutputDirectory := os.Args[buildOutputDirectoryArg]

logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)
logger.Debugf("Build output directory: %s", buildOutputDirectory)

build := &builder.Build{
ChaincodeSourceDirectory: chaincodeSourceDirectory,
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
BuildOutputDirectory: buildOutputDirectory,
}

if err := build.Run(ctx); err != nil {
logger.Printf("Error building chaincode: %+v", err)
os.Exit(1)
}
os.Exit(cmd.Build())
}
54 changes: 54 additions & 0 deletions cmd/detect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"context"
"errors"
"os"
"strconv"

"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
)

func Detect() int {
const (
expectedArgsLength = 3
chaincodeSourceDirectoryArg = 1
chaincodeMetadataDirectoryArg = 2
)

debug, _ := strconv.ParseBool(util.GetOptionalEnv(util.DebugVariable, "false"))
ctx := log.NewCmdContext(context.Background(), debug)
logger := log.New(ctx)

if len(os.Args) != expectedArgsLength {
logger.Println("Expected CHAINCODE_SOURCE_DIR and CHAINCODE_METADATA_DIR arguments")

return 1
}

chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]

logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)

detect := &builder.Detect{
ChaincodeSourceDirectory: chaincodeSourceDirectory,
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
}

if err := detect.Run(ctx); err != nil {
if !errors.Is(err, builder.ErrUnsupportedChaincodeType) {
// don't spam the peer log if it's just chaincode we don't recognise
logger.Printf("Error detecting chaincode: %+v", err)
}

return 1
}

return 0
}
41 changes: 2 additions & 39 deletions cmd/detect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,11 @@
package main

import (
"context"
"errors"
"os"

"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
)

const (
expectedArgsLength = 3
chaincodeSourceDirectoryArg = 1
chaincodeMetadataDirectoryArg = 2
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
)

func main() {
debug := util.GetOptionalEnv(util.DebugVariable, "false")
ctx := log.NewCmdContext(context.Background(), debug == "true")
logger := log.New(ctx)

if len(os.Args) != expectedArgsLength {
logger.Println("Expected CHAINCODE_SOURCE_DIR and CHAINCODE_METADATA_DIR arguments")
os.Exit(1)
}

chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]

logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)

detect := &builder.Detect{
ChaincodeSourceDirectory: chaincodeSourceDirectory,
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
}

if err := detect.Run(ctx); err != nil {
if !errors.Is(err, builder.ErrUnsupportedChaincodeType) {
// don't spam the peer log if it's just chaincode we don't recognise
logger.Printf("Error detecting chaincode: %+v", err)
}

os.Exit(1)
}
os.Exit(cmd.Detect())
}
50 changes: 50 additions & 0 deletions cmd/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"context"
"os"
"strconv"

"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
)

func Release() int {
const (
expectedArgsLength = 3
buildOutputDirectoryArg = 1
releaseOutputDirectoryArg = 2
)

debug, _ := strconv.ParseBool(util.GetOptionalEnv(util.DebugVariable, "false"))
ctx := log.NewCmdContext(context.Background(), debug)
logger := log.New(ctx)

if len(os.Args) != expectedArgsLength {
logger.Println("Expected BUILD_OUTPUT_DIR and RELEASE_OUTPUT_DIR arguments")

return 1
}

buildOutputDirectory := os.Args[buildOutputDirectoryArg]
releaseOutputDirectory := os.Args[releaseOutputDirectoryArg]

logger.Debugf("Build output directory: %s", buildOutputDirectory)
logger.Debugf("Release output directory: %s", releaseOutputDirectory)

release := &builder.Release{
BuildOutputDirectory: buildOutputDirectory,
ReleaseOutputDirectory: releaseOutputDirectory,
}

if err := release.Run(ctx); err != nil {
logger.Printf("Error releasing chaincode: %+v", err)

return 1
}

return 0
}
36 changes: 2 additions & 34 deletions cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,11 @@
package main

import (
"context"
"os"

"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
)

const (
expectedArgsLength = 3
buildOutputDirectoryArg = 1
releaseOutputDirectoryArg = 2
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
)

func main() {
debug := util.GetOptionalEnv(util.DebugVariable, "false")
ctx := log.NewCmdContext(context.Background(), debug == "true")
logger := log.New(ctx)

if len(os.Args) != expectedArgsLength {
logger.Println("Expected BUILD_OUTPUT_DIR and RELEASE_OUTPUT_DIR arguments")
os.Exit(1)
}

buildOutputDirectory := os.Args[buildOutputDirectoryArg]
releaseOutputDirectory := os.Args[releaseOutputDirectoryArg]

logger.Debugf("Build output directory: %s", buildOutputDirectory)
logger.Debugf("Release output directory: %s", releaseOutputDirectory)

release := &builder.Release{
BuildOutputDirectory: buildOutputDirectory,
ReleaseOutputDirectory: releaseOutputDirectory,
}

if err := release.Run(ctx); err != nil {
logger.Printf("Error releasing chaincode: %+v", err)
os.Exit(1)
}
os.Exit(cmd.Release())
}
Loading
Loading