forked from hyperledger-labs/fabric-builder-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use github.com/rogpeppe/go-internal/testscript and github.com/kubernetes-sigs/e2e-framework to test the builder run command with a kind kubernetes cluster New integration tests should now be easier to add, e.g. for hyperledger-labs#228 Signed-off-by: James Taylor <[email protected]>
- Loading branch information
Showing
21 changed files
with
819 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.