mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
- Update github.com/luxfi/netrunner v1.15.3 → v1.15.4 - Update github.com/luxfi/node v1.22.77 → v1.22.80 - Remove local replace directive for netrunner - Use published package versions for reproducible builds
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
// Copyright (C) 2022-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
// GenerateDockerHostIPs generates IP addresses for Docker hosts
|
|
func GenerateDockerHostIPs(nodeCount int) ([]string, error) {
|
|
ips := make([]string, nodeCount)
|
|
for i := 0; i < nodeCount; i++ {
|
|
// Generate IPs in the 172.18.0.x range for Docker network
|
|
ips[i] = fmt.Sprintf("172.18.0.%d", i+10)
|
|
}
|
|
return ips, nil
|
|
}
|
|
|
|
// GenerateDockerHostIDs generates unique IDs for Docker hosts
|
|
func GenerateDockerHostIDs(nodeCount int) ([]string, error) {
|
|
ids := make([]string, nodeCount)
|
|
for i := 0; i < nodeCount; i++ {
|
|
ids[i] = fmt.Sprintf("node-%d", i+1)
|
|
}
|
|
return ids, nil
|
|
}
|
|
|
|
// SaveDockerComposeFile saves Docker Compose configuration to a file
|
|
func SaveDockerComposeFile(content []byte, path string) error {
|
|
return os.WriteFile(path, content, 0o644) //nolint:gosec // G306: Docker compose file needs to be readable
|
|
}
|
|
|
|
// StartDockerCompose starts Docker Compose with the given configuration file
|
|
func StartDockerCompose(dockerComposeFile string) error {
|
|
// Execute docker-compose up command
|
|
cmd := exec.Command("docker-compose", "-f", dockerComposeFile, "up", "-d")
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to start docker-compose: %w, output: %s", err, string(output))
|
|
}
|
|
return nil
|
|
}
|