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
2 changes: 1 addition & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var StacksDir = checkHome()
var FireFlyCoreImageName = "ghcr.io/hyperledger-firefly/firefly"
var IPFSImageName = "ipfs/go-ipfs:v0.10.0"
var IPFSImageName = "ipfs/kubo:v0.42.0"
var PostgresImageName = "postgres"
var PrometheusImageName = "prom/prometheus"
var SandboxImageName = "ghcr.io/hyperledger-firefly/sandbox:latest"
Expand Down
5 changes: 5 additions & 0 deletions internal/docker/docker_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ func CreateDockerCompose(s *types.Stack) *DockerComposeConfig {
"LIBP2P_FORCE_PNET": "1",
},
)
// Kubo's AutoConf/public-network defaults are incompatible with a
// private swarm and prevent peering with other members unless
// disabled via a container-init.d script - see ipfs_config.go.
sharedStorage.Volumes = append(sharedStorage.Volumes, fmt.Sprintf("ipfs_init_%s:/container-init.d", member.ID))
compose.Volumes[fmt.Sprintf("ipfs_init_%s", member.ID)] = struct{}{}
} else {
sharedStorage.Environment = s.EnvironmentVars
}
Expand Down
17 changes: 17 additions & 0 deletions internal/stacks/ipfs_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ func GenerateSwarmKey() (string, error) {
hexKey := hex.EncodeToString(key)
return "/key/swarm/psk/1.0.0/\n/base16/\n" + hexKey, nil
}

// GenerateIPFSPrivateNetInitScript returns a container-init.d script that
// disables Kubo's AutoConf/public-network defaults, which are incompatible
// with a private swarm (swarm.key / LIBP2P_FORCE_PNET) and otherwise prevent
// the daemon from starting or from ever peering with other members.
func GenerateIPFSPrivateNetInitScript() string {
return `#!/bin/sh
ipfs config --json AutoConf.Enabled false
ipfs config --json Bootstrap '[]'
ipfs config --json DNS.Resolvers '{}'
ipfs config --json Routing.DelegatedRouters '[]'
ipfs config --json Ipns.DelegatedPublishers '[]'
ipfs config Routing.Type dht
ipfs config --json AutoTLS.Enabled false
ipfs config --json Swarm.Transports.Network.Websocket false
`
}
26 changes: 26 additions & 0 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ func (s *StackManager) writeConfig(options *types.InitOptions) error {
}
}

if s.Stack.IPFSMode.Equals(types.IPFSModePrivate) {
initScript := GenerateIPFSPrivateNetInitScript()
if err := os.WriteFile(path.Join(s.Stack.InitDir, "config", "ipfs_privatenet_init.sh"), []byte(initScript), 0755); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -566,6 +573,21 @@ func (s *StackManager) copyDataExchangeConfigToVolumes() error {
return nil
}

func (s *StackManager) copyIPFSInitScriptToVolumes() error {
if !s.Stack.IPFSMode.Equals(types.IPFSModePrivate) {
return nil
}
configDir := filepath.Join(s.Stack.RuntimeDir, "config")
scriptPath := path.Join(configDir, "ipfs_privatenet_init.sh")
for _, member := range s.Stack.Members {
volumeName := fmt.Sprintf("%s_ipfs_init_%s", s.Stack.Name, member.ID)
if err := docker.CopyFileToVolume(s.ctx, volumeName, scriptPath, "/privatenet-init.sh"); err != nil {
return err
}
}
return nil
}

func (s *StackManager) createMember(id string, index int, options *types.InitOptions, external bool) (*types.Organization, error) {
serviceBase := options.ServicesBasePort + (index * 100)
ptmBase := options.PtmBasePort + (index * 10)
Expand Down Expand Up @@ -908,6 +930,10 @@ func (s *StackManager) runFirstTimeSetup(options *types.StartOptions) (messages
return messages, err
}

if err := s.copyIPFSInitScriptToVolumes(); err != nil {
return messages, err
}

pullOptions := &types.PullOptions{
Retries: 2,
}
Expand Down
Loading