Skip to content

Commit

Permalink
Merge pull request #323 from dwertent/fix-fabric-amd
Browse files Browse the repository at this point in the history
[Fix]: Remove --platform flag from Docker commands in fabric_provider.go
  • Loading branch information
EnriqueL8 authored Aug 15, 2024
2 parents 982a8ad + a86294e commit c05e5ee
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 30 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/accounts_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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})
err := createCmd.Execute()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/blockchain/ethereum/geth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion internal/blockchain/ethereum/quorum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions internal/blockchain/fabric/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 0 additions & 13 deletions internal/blockchain/fabric/fabric_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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")),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down
7 changes: 0 additions & 7 deletions internal/blockchain/fabric/fabric_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -410,4 +404,3 @@ func TestRegisterIdentity(t *testing.T) {
})

}

Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@ func TestGetConnectorExternalURL(t *testing.T) {
assert.Equal(t, tc.ExpectedURL, ExternalURL)
})
}
}
}
2 changes: 1 addition & 1 deletion internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c05e5ee

Please sign in to comment.