Skip to content

Commit

Permalink
Fix mismatched member configs
Browse files Browse the repository at this point in the history
Resolves #94

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Sep 29, 2021
1 parent c3711f7 commit 2617eb2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 74 deletions.
129 changes: 62 additions & 67 deletions internal/core/firefly_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,81 +138,76 @@ type FireflyConfig struct {
Tokens *TokensConfig `yaml:"tokens,omitempty"`
}

func NewFireflyConfigs(stack *types.Stack) map[string]*FireflyConfig {
configs := make(map[string]*FireflyConfig)

for _, member := range stack.Members {
memberConfig := &FireflyConfig{
Log: &LogConfig{
Level: "debug",
},
Debug: &HttpServerConfig{
Port: 6060,
},
HTTP: &HttpServerConfig{
Port: member.ExposedFireflyPort,
Address: "0.0.0.0",
PublicURL: fmt.Sprintf("http://127.0.0.1:%d", member.ExposedFireflyPort),
},
Admin: &AdminServerConfig{
Enabled: true,
Port: member.ExposedFireflyAdminPort,
Address: "0.0.0.0",
PreInit: true,
PublicURL: fmt.Sprintf("http://127.0.0.1:%d", member.ExposedFireflyAdminPort),
},
UI: &UIConfig{
Path: "./frontend",
},
Node: &NodeConfig{
Name: fmt.Sprintf("node_%s", member.ID),
},
Org: &OrgConfig{
Name: fmt.Sprintf("org_%s", member.ID),
Identity: member.Address,
},
P2PFS: &PublicStorageConfig{
Type: "ipfs",
IPFS: &FireflyIPFSConfig{
API: &HttpEndpointConfig{
URL: getIPFSAPIURL(member),
},
Gateway: &HttpEndpointConfig{
URL: getIPFSGatewayURL(member),
},
func NewFireflyConfig(stack *types.Stack, member *types.Member) *FireflyConfig {
memberConfig := &FireflyConfig{
Log: &LogConfig{
Level: "debug",
},
Debug: &HttpServerConfig{
Port: 6060,
},
HTTP: &HttpServerConfig{
Port: member.ExposedFireflyPort,
Address: "0.0.0.0",
PublicURL: fmt.Sprintf("http://127.0.0.1:%d", member.ExposedFireflyPort),
},
Admin: &AdminServerConfig{
Enabled: true,
Port: member.ExposedFireflyAdminPort,
Address: "0.0.0.0",
PreInit: true,
PublicURL: fmt.Sprintf("http://127.0.0.1:%d", member.ExposedFireflyAdminPort),
},
UI: &UIConfig{
Path: "./frontend",
},
Node: &NodeConfig{
Name: fmt.Sprintf("node_%s", member.ID),
},
Org: &OrgConfig{
Name: fmt.Sprintf("org_%s", member.ID),
Identity: member.Address,
},
P2PFS: &PublicStorageConfig{
Type: "ipfs",
IPFS: &FireflyIPFSConfig{
API: &HttpEndpointConfig{
URL: getIPFSAPIURL(member),
},
Gateway: &HttpEndpointConfig{
URL: getIPFSGatewayURL(member),
},
},
DataExchange: &DataExchangeConfig{
HTTPS: &HttpEndpointConfig{
URL: getDataExchangeURL(member),
},
DataExchange: &DataExchangeConfig{
HTTPS: &HttpEndpointConfig{
URL: getDataExchangeURL(member),
},
},
}
switch stack.Database {
case "postgres":
memberConfig.Database = &DatabaseConfig{
Type: "postgres",
PostgreSQL: &CommonDBConfig{
URL: getPostgresURL(member),
Migrations: &MigrationsConfig{
Auto: true,
},
},
}
switch stack.Database {
case "postgres":
memberConfig.Database = &DatabaseConfig{
Type: "postgres",
PostgreSQL: &CommonDBConfig{
URL: getPostgresURL(member),
Migrations: &MigrationsConfig{
Auto: true,
},
},
}
case "sqlite3":
memberConfig.Database = &DatabaseConfig{
Type: stack.Database,
SQLite3: &CommonDBConfig{
URL: getSQLitePath(member, stack.Name),
Migrations: &MigrationsConfig{
Auto: true,
},
case "sqlite3":
memberConfig.Database = &DatabaseConfig{
Type: stack.Database,
SQLite3: &CommonDBConfig{
URL: getSQLitePath(member, stack.Name),
Migrations: &MigrationsConfig{
Auto: true,
},
}
},
}
configs[member.ID] = memberConfig
}
return configs
return memberConfig
}

func getIPFSAPIURL(member *types.Member) string {
Expand Down
12 changes: 5 additions & 7 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,13 @@ func (s *StackManager) writeDockerCompose(compose *docker.DockerComposeConfig) e
func (s *StackManager) writeConfigs(verbose bool) error {
stackDir := filepath.Join(constants.StacksDir, s.Stack.Name)

fireflyConfigs := core.NewFireflyConfigs(s.Stack)
i := 0
for memberId, config := range fireflyConfigs {
config.Blockchain = s.blockchainProvider.GetFireflyConfig(s.Stack.Members[i])
config.Tokens = s.tokensProvider.GetFireflyConfig(s.Stack.Members[i])
if err := core.WriteFireflyConfig(config, filepath.Join(stackDir, "configs", fmt.Sprintf("firefly_core_%s.yml", memberId))); err != nil {
for _, member := range s.Stack.Members {
config := core.NewFireflyConfig(s.Stack, member)
config.Blockchain = s.blockchainProvider.GetFireflyConfig(member)
config.Tokens = s.tokensProvider.GetFireflyConfig(member)
if err := core.WriteFireflyConfig(config, filepath.Join(stackDir, "configs", fmt.Sprintf("firefly_core_%s.yml", member.ID))); err != nil {
return err
}
i++
}

stackConfigBytes, _ := json.MarshalIndent(s.Stack, "", " ")
Expand Down

0 comments on commit 2617eb2

Please sign in to comment.