From 71237b73b07bfee72b355dea83af9cd874b2a2de Mon Sep 17 00:00:00 2001 From: dwertent Date: Tue, 13 Aug 2024 14:25:58 -0400 Subject: [PATCH 1/2] chore: Remove --platform flag from Docker commands in fabric_provider.go Signed-off-by: dwertent --- internal/blockchain/fabric/fabric_provider.go | 13 ------------- internal/blockchain/fabric/fabric_provider_test.go | 7 ------- 2 files changed, 20 deletions(-) diff --git a/internal/blockchain/fabric/fabric_provider.go b/internal/blockchain/fabric/fabric_provider.go index e5828ae1..076f1c66 100644 --- a/internal/blockchain/fabric/fabric_provider.go +++ b/internal/blockchain/fabric/fabric_provider.go @@ -109,7 +109,6 @@ func (p *FabricProvider) FirstTimeSetup() error { // Run cryptogen to generate MSP if err := docker.RunDockerCommand(p.ctx, blockchainDirectory, "run", - "--platform", getDockerPlatform(), "--rm", "-v", fmt.Sprintf("%s:/etc/template.yml", cryptogenYamlPath), "-v", fmt.Sprintf("%s:/etc/firefly", volumeName), @@ -124,7 +123,6 @@ func (p *FabricProvider) FirstTimeSetup() error { // Generate genesis block if err := docker.RunDockerCommand(p.ctx, blockchainDirectory, "run", - "--platform", getDockerPlatform(), "--rm", "-v", fmt.Sprintf("%s:/etc/firefly", volumeName), "-v", fmt.Sprintf("%s:/etc/hyperledger/fabric/configtx.yaml", path.Join(blockchainDirectory, "configtx.yaml")), @@ -335,7 +333,6 @@ func (p *FabricProvider) createChannel() error { volumeName := fmt.Sprintf("%s_firefly_fabric", p.stack.Name) return docker.RunDockerCommand(p.ctx, stackDir, "run", - "--platform", getDockerPlatform(), "--rm", fmt.Sprintf("--network=%s_default", p.stack.Name), "-v", fmt.Sprintf("%s:/etc/firefly", volumeName), @@ -356,7 +353,6 @@ func (p *FabricProvider) joinChannel() error { volumeName := fmt.Sprintf("%s_firefly_fabric", p.stack.Name) return docker.RunDockerCommand(p.ctx, stackDir, "run", - "--platform", getDockerPlatform(), "--rm", fmt.Sprintf("--network=%s_default", p.stack.Name), "-v", fmt.Sprintf("%s:/etc/firefly", volumeName), @@ -405,7 +401,6 @@ func (p *FabricProvider) installChaincode(packageFilename string) error { volumeName := fmt.Sprintf("%s_firefly_fabric", p.stack.Name) return docker.RunDockerCommand(p.ctx, contractsDir, "run", - "--platform", getDockerPlatform(), "--rm", fmt.Sprintf("--network=%s_default", p.stack.Name), "-e", "CORE_PEER_ADDRESS=fabric_peer:7051", @@ -425,7 +420,6 @@ func (p *FabricProvider) queryInstalled() (*QueryInstalledResponse, error) { volumeName := fmt.Sprintf("%s_firefly_fabric", p.stack.Name) str, err := docker.RunDockerCommandBuffered(p.ctx, p.stack.RuntimeDir, "run", - "--platform", getDockerPlatform(), "--rm", fmt.Sprintf("--network=%s_default", p.stack.Name), "-e", "CORE_PEER_ADDRESS=fabric_peer:7051", @@ -454,7 +448,6 @@ func (p *FabricProvider) approveChaincode(channel, chaincode, version, packageID volumeName := fmt.Sprintf("%s_firefly_fabric", p.stack.Name) return docker.RunDockerCommand(p.ctx, p.stack.RuntimeDir, "run", - "--platform", getDockerPlatform(), "--rm", fmt.Sprintf("--network=%s_default", p.stack.Name), "-e", "CORE_PEER_ADDRESS=fabric_peer:7051", @@ -482,7 +475,6 @@ func (p *FabricProvider) commitChaincode(channel, chaincode, version string) err volumeName := fmt.Sprintf("%s_firefly_fabric", p.stack.Name) return docker.RunDockerCommand(p.ctx, p.stack.RuntimeDir, "run", - "--platform", getDockerPlatform(), "--rm", fmt.Sprintf("--network=%s_default", p.stack.Name), "-e", "CORE_PEER_ADDRESS=fabric_peer:7051", @@ -617,11 +609,6 @@ func (p *FabricProvider) CreateAccount(args []string) (interface{}, error) { }, nil } -// As of release 2.4, Hyperledger Fabric only publishes amd64 images, but no arm64 specific images -func getDockerPlatform() string { - return "linux/amd64" -} - func (p *FabricProvider) ParseAccount(account interface{}) interface{} { accountMap := account.(map[string]interface{}) return &Account{ diff --git a/internal/blockchain/fabric/fabric_provider_test.go b/internal/blockchain/fabric/fabric_provider_test.go index 241202c7..9d7c17e5 100644 --- a/internal/blockchain/fabric/fabric_provider_test.go +++ b/internal/blockchain/fabric/fabric_provider_test.go @@ -259,12 +259,6 @@ func TestGetConnectorURL(t *testing.T) { } -func TestGetDockerPlatform(t *testing.T) { - expectedString := "linux/amd64" - String := getDockerPlatform() - assert.Equal(t, expectedString, String) -} - func TestGetContracts(t *testing.T) { FilePath := t.TempDir() testContractFile := filepath.Join(FilePath, "/test_contracts.json") @@ -410,4 +404,3 @@ func TestRegisterIdentity(t *testing.T) { }) } - From a86294e7a3e6edbde94f8b68914a496550b25494 Mon Sep 17 00:00:00 2001 From: dwertent Date: Wed, 14 Aug 2024 10:41:47 -0400 Subject: [PATCH 2/2] format go code Signed-off-by: dwertent --- Makefile | 4 +++- cmd/accounts_list_test.go | 4 ++-- internal/blockchain/ethereum/connector/ethconnect/client.go | 2 +- .../blockchain/ethereum/connector/ethconnect/config_test.go | 4 ++-- internal/blockchain/ethereum/geth/client.go | 2 +- internal/blockchain/ethereum/quorum/client.go | 2 +- internal/blockchain/fabric/constants.go | 3 +++ .../blockchain/tezos/remoterpc/remoterpc_provider_test.go | 2 +- internal/docker/docker.go | 2 +- 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c2ad18b1..e2144dc9 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,9 @@ GITREF := $(shell git rev-parse --short HEAD) DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") LINT := $(GOBIN)/golangci-lint -all: build lint test tidy +all: format build lint test tidy +format: ## Formats all go code + gofmt -s -w . test: deps $(VGO) test ./internal/... ./pkg/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s ${TEST_ARGS} build: ## Builds all go code diff --git a/cmd/accounts_list_test.go b/cmd/accounts_list_test.go index c7a5db9c..29379a8f 100644 --- a/cmd/accounts_list_test.go +++ b/cmd/accounts_list_test.go @@ -8,7 +8,7 @@ import ( ) func TestAccountListCmd(t *testing.T) { - testNames := []string{"stack-1", "stack-2", "stack-3","stack-4", "stack-5"} + testNames := []string{"stack-1", "stack-2", "stack-3", "stack-4", "stack-5"} for _, stackNames := range testNames { createCmd := accountsCreateCmd createCmd.SetArgs([]string{"ff", "create", stackNames}) @@ -16,7 +16,7 @@ func TestAccountListCmd(t *testing.T) { if err != nil { t.Fatalf("Failed to create account for testing: %v", err) } - Args := []string{ "ls"} + Args := []string{"ls"} t.Run("Test-Account-List", func(t *testing.T) { cmd := accountsListCmd cmd.SetArgs(Args) diff --git a/internal/blockchain/ethereum/connector/ethconnect/client.go b/internal/blockchain/ethereum/connector/ethconnect/client.go index 7b7f9793..e0d70fc5 100644 --- a/internal/blockchain/ethereum/connector/ethconnect/client.go +++ b/internal/blockchain/ethereum/connector/ethconnect/client.go @@ -136,7 +136,7 @@ func (e *Ethconnect) DeployContract(contract *ethtypes.CompiledContract, contrac return nil, err } if reply.Headers.Type != "TransactionSuccess" { - return nil, fmt.Errorf(reply.ErrorMessage) + return nil, fmt.Errorf("%s", reply.ErrorMessage) } result := &types.ContractDeploymentResult{ diff --git a/internal/blockchain/ethereum/connector/ethconnect/config_test.go b/internal/blockchain/ethereum/connector/ethconnect/config_test.go index 41893355..e53ced59 100644 --- a/internal/blockchain/ethereum/connector/ethconnect/config_test.go +++ b/internal/blockchain/ethereum/connector/ethconnect/config_test.go @@ -8,8 +8,8 @@ import ( func TestWriteConfig(t *testing.T) { dir := t.TempDir() // Construct the paths for config files within the temporary directory - configFilename := filepath.Join(dir, "config.yaml") - extraEvmConfigPath := filepath.Join(dir, "conflate", "extra.yaml") + configFilename := filepath.Join(dir, "config.yaml") + extraEvmConfigPath := filepath.Join(dir, "conflate", "extra.yaml") p := Config{} t.Run("TestWriteConfig", func(t *testing.T) { err := p.WriteConfig(configFilename, extraEvmConfigPath) diff --git a/internal/blockchain/ethereum/geth/client.go b/internal/blockchain/ethereum/geth/client.go index 5f39cecd..abbf089a 100644 --- a/internal/blockchain/ethereum/geth/client.go +++ b/internal/blockchain/ethereum/geth/client.go @@ -87,7 +87,7 @@ func (g *GethClient) UnlockAccount(address string, password string) error { return err } if rpcResponse.Error != nil { - return fmt.Errorf(rpcResponse.Error.Message) + return fmt.Errorf("%s", rpcResponse.Error.Message) } return nil } diff --git a/internal/blockchain/ethereum/quorum/client.go b/internal/blockchain/ethereum/quorum/client.go index 27d9dc69..04a64608 100644 --- a/internal/blockchain/ethereum/quorum/client.go +++ b/internal/blockchain/ethereum/quorum/client.go @@ -87,7 +87,7 @@ func (g *QuorumClient) UnlockAccount(address string, password string) error { return err } if rpcResponse.Error != nil { - return fmt.Errorf(rpcResponse.Error.Message) + return fmt.Errorf("%s", rpcResponse.Error.Message) } return nil } diff --git a/internal/blockchain/fabric/constants.go b/internal/blockchain/fabric/constants.go index c08200d4..3c86622b 100644 --- a/internal/blockchain/fabric/constants.go +++ b/internal/blockchain/fabric/constants.go @@ -16,6 +16,9 @@ package fabric +// Note: Any change of image tag should be checked if it is published in arm64 format. +// Refer to this commit for when arm64 support was added and the code workaround was removed: +// https://github.com/hyperledger/firefly-cli/pull/323/commits/71237b73b07bfee72b355dea83af9cd874b2a2de var FabricToolsImageName = "hyperledger/fabric-tools:2.5.6" var FabricCAImageName = "hyperledger/fabric-ca:1.5" var FabricOrdererImageName = "hyperledger/fabric-orderer:2.5" diff --git a/internal/blockchain/tezos/remoterpc/remoterpc_provider_test.go b/internal/blockchain/tezos/remoterpc/remoterpc_provider_test.go index 5d66a8c1..3c52f5ca 100644 --- a/internal/blockchain/tezos/remoterpc/remoterpc_provider_test.go +++ b/internal/blockchain/tezos/remoterpc/remoterpc_provider_test.go @@ -239,4 +239,4 @@ func TestGetConnectorExternalURL(t *testing.T) { assert.Equal(t, tc.ExpectedURL, ExternalURL) }) } -} \ No newline at end of file +} diff --git a/internal/docker/docker.go b/internal/docker/docker.go index e86c2211..6b81df3b 100644 --- a/internal/docker/docker.go +++ b/internal/docker/docker.go @@ -93,7 +93,7 @@ func RunDockerCommand(ctx context.Context, workingDir string, command ...string) dockerCmd.Dir = workingDir output, err := runCommand(ctx, dockerCmd) if err != nil && output != "" { - return fmt.Errorf(output) + return fmt.Errorf("%s", output) } return err }