diff --git a/cmd/init.go b/cmd/init.go index 159faff5..065b19ce 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -193,6 +193,7 @@ func init() { initCmd.Flags().StringVarP(&initOptions.ManifestPath, "manifest", "m", "", "Path to a manifest.json file containing the versions of each FireFly microservice to use. Overrides the --release flag.") initCmd.Flags().BoolVar(&promptNames, "prompt-names", false, "Prompt for org and node names instead of using the defaults") initCmd.Flags().BoolVar(&initOptions.PrometheusEnabled, "prometheus-enabled", false, "Enables Prometheus metrics exposition and aggregation to a shared Prometheus server") + initCmd.Flags().BoolVar(&initOptions.SandboxEnabled, "sandbox-enabled", true, "Enables the FireFly Sandbox to be started with your FireFly stack") initCmd.Flags().IntVar(&initOptions.PrometheusPort, "prometheus-port", 9090, "Port for the shared Prometheus server") initCmd.Flags().StringVarP(&initOptions.ExtraCoreConfigPath, "core-config", "", "", "The path to a yaml file containing extra config for FireFly Core") initCmd.Flags().StringVarP(&initOptions.ExtraEthconnectConfigPath, "ethconnect-config", "", "", "The path to a yaml file containing extra config for Ethconnect") diff --git a/cmd/start.go b/cmd/start.go index 357a247a..222edf2c 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -80,6 +80,9 @@ This command will start a stack and run it in the background. fmt.Print("\n\n") for _, member := range stackManager.Stack.Members { fmt.Printf("Web UI for member '%v': http://127.0.0.1:%v/ui\n", member.ID, member.ExposedFireflyPort) + if stackManager.Stack.SandboxEnabled { + fmt.Printf("Sandbox UI for member '%v': http://127.0.0.1:%v\n\n", member.ID, member.ExposedSandboxPort) + } } if stackManager.Stack.PrometheusEnabled { diff --git a/internal/docker/docker_config.go b/internal/docker/docker_config.go index 8bdfe0f3..67c54f27 100644 --- a/internal/docker/docker_config.go +++ b/internal/docker/docker_config.go @@ -152,6 +152,16 @@ func CreateDockerCompose(s *types.Stack) *DockerComposeConfig { Logging: StandardLogOptions, } compose.Volumes[fmt.Sprintf("dataexchange_%s", member.ID)] = struct{}{} + if s.SandboxEnabled { + compose.Services["sandbox_"+member.ID] = &Service{ + Image: "ghcr.io/hyperledger/firefly-sandbox:latest", + ContainerName: fmt.Sprintf("%s_sandbox_%s", s.Name, member.ID), + Ports: []string{fmt.Sprintf("%d:3001", member.ExposedSandboxPort)}, + Environment: map[string]string{ + "FF_ENDPOINT": fmt.Sprintf("http://firefly_core_%d:%d", *member.Index, member.ExposedFireflyPort), + }, + } + } } if s.PrometheusEnabled { diff --git a/internal/stacks/stack_manager.go b/internal/stacks/stack_manager.go index 1798eeb0..32c23069 100644 --- a/internal/stacks/stack_manager.go +++ b/internal/stacks/stack_manager.go @@ -101,6 +101,7 @@ func (s *StackManager) InitStack(stackName string, memberCount int, options *typ DeployedContracts: make([]*types.DeployedContract, 0), Accounts: make([]interface{}, memberCount), }, + SandboxEnabled: options.SandboxEnabled, } if options.PrometheusEnabled { @@ -479,6 +480,10 @@ func createMember(id string, index int, options *types.InitOptions, external boo case types.HyperledgerFabric: // This will be filled in by the Fabric blockchain provider } + if options.SandboxEnabled { + member.ExposedSandboxPort = nextPort + nextPort++ + } return member } @@ -646,6 +651,10 @@ func (s *StackManager) checkPortsAvailable() error { ports = append(ports, member.ExposedDatabasePort) ports = append(ports, member.ExposedUIPort) ports = append(ports, member.ExposedTokensPorts...) + + if s.Stack.SandboxEnabled { + ports = append(ports, member.ExposedSandboxPort) + } } if s.Stack.PrometheusEnabled { diff --git a/pkg/types/options.go b/pkg/types/options.go index 321aa3c2..0ca466b6 100644 --- a/pkg/types/options.go +++ b/pkg/types/options.go @@ -42,6 +42,7 @@ type InitOptions struct { ManifestPath string PrometheusEnabled bool PrometheusPort int + SandboxEnabled bool ExtraCoreConfigPath string ExtraEthconnectConfigPath string BlockPeriod int diff --git a/pkg/types/stack.go b/pkg/types/stack.go index 30b32e77..35a65a5b 100644 --- a/pkg/types/stack.go +++ b/pkg/types/stack.go @@ -26,6 +26,7 @@ type Stack struct { TokenProviders TokenProviders `json:"tokenProviders"` VersionManifest *VersionManifest `json:"versionManifest,omitempty"` PrometheusEnabled bool `json:"prometheusEnabled,omitempty"` + SandboxEnabled bool `json:"sandboxEnabled,omitempty"` ExposedPrometheusPort int `json:"exposedPrometheusPort,omitempty"` ContractAddress string `json:"contractAddress,omitempty"` InitDir string `json:"-"` @@ -42,11 +43,12 @@ type Member struct { ExposedFireflyAdminPort int `json:"exposedFireflyAdminPort,omitempty"` ExposedFireflyMetricsPort int `json:"exposedFireflyMetricsPort,omitempty"` ExposedConnectorPort int `json:"exposedConnectorPort,omitempty"` - ExposedDatabasePort int `json:"exposedDatabasePort,omitempty"` + ExposedDatabasePort int `json:"exposedPostgresPort,omitempty"` ExposedDataexchangePort int `json:"exposedDataexchangePort,omitempty"` ExposedIPFSApiPort int `json:"exposedIPFSApiPort,omitempty"` ExposedIPFSGWPort int `json:"exposedIPFSGWPort,omitempty"` ExposedUIPort int `json:"exposedUiPort,omitempty"` + ExposedSandboxPort int `json:"exposedSandboxPort,omitempty"` ExposedTokensPorts []int `json:"exposedTokensPorts,omitempty"` External bool `json:"external,omitempty"` OrgName string `json:"orgName,omitempty"`