Skip to content
Open
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: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,6 @@ func init() {
initCmd.PersistentFlags().StringArrayVar(&initOptions.NodeNames, "node-name", []string{}, "Node name")
initCmd.PersistentFlags().BoolVar(&initOptions.RemoteNodeDeploy, "remote-node-deploy", false, "Enable or disable deployment of FireFly contracts on remote nodes")
initCmd.PersistentFlags().StringToStringVar(&initOptions.EnvironmentVars, "environment-vars", map[string]string{}, "Common environment variables to set on all containers in FireFly stack")
initCmd.Flags().BoolVar(&initOptions.EnableAutoReload, "auto-reload", true, "Enable config auto reload in FireFly core")
rootCmd.AddCommand(initCmd)
}
7 changes: 7 additions & 0 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ func (s *StackManager) writeConfig(options *types.InitOptions) error {
for _, member := range s.Stack.Members {
config := core.NewFireflyConfig(s.Stack, member)

if options.EnableAutoReload {
if config.Config == nil {
config.Config = &types.CoreConfig{}
}
config.Config.AutoReload = true
}

// TODO: This code assumes that there is only one plugin instance per type. When we add support for
// multiple namespaces, this code will likely have to change a lot
blockchainConfig := s.blockchainProvider.GetBlockchainPluginConfig(s.Stack, member)
Expand Down
45 changes: 45 additions & 0 deletions internal/stacks/stack_manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package stacks

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"

"github.com/hyperledger/firefly-cli/pkg/types"
)

func TestMockConfigWithAutoReload(t *testing.T) {
tmpDir := os.TempDir()
configDir := filepath.Join(tmpDir, "config")

err := os.MkdirAll(configDir, 0755)
assert.NoError(t, err)

configPath := filepath.Join(configDir, "firefly_core_member1.yml")

// Correct FireflyConfig YAML structure
configYAML := []byte(`
config:
autoReload: true
`)

err = os.WriteFile(configPath, configYAML, 0644)
assert.NoError(t, err)

content, err := os.ReadFile(configPath)
assert.NoError(t, err)

var config types.FireflyConfig
err = yaml.Unmarshal(content, &config)
assert.NoError(t, err)

if config.Config == nil {
t.Fatalf("Config block was not unmarshaled properly (config.Config is nil)")
}

assert.True(t, config.Config.AutoReload)
}

6 changes: 6 additions & 0 deletions pkg/types/firefly_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ type NamespacesConfig struct {
Predefined []*Namespace `json:"predefined"`
}

type CoreConfig struct {
AutoReload bool `yaml:"autoReload,omitempty"`
}

type FireflyConfig struct {
Log *LogConfig `yaml:"log,omitempty"`
Debug *HTTPServerConfig `yaml:"debug,omitempty"`
Expand All @@ -184,4 +188,6 @@ type FireflyConfig struct {
Event *EventConfig `yaml:"event,omitempty"`
Plugins *Plugins `yaml:"plugins"`
Namespaces *NamespacesConfig `yaml:"namespaces"`
Config *CoreConfig `yaml:"config,omitempty"`

}
1 change: 1 addition & 0 deletions pkg/types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type InitOptions struct {
CustomPinSupport bool
RemoteNodeDeploy bool
EnvironmentVars map[string]string
EnableAutoReload bool
}

const IPFSMode = "ipfs_mode"
Expand Down
Loading