mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-22 04:46:40 +00:00
docker-compose vs docker compose; Resolves #83
This commit is contained in:
@@ -438,29 +438,53 @@ func isDockerInstalled() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCommandString(useNewStyle bool) string {
|
||||||
|
if useNewStyle {
|
||||||
|
return "'docker compose'"
|
||||||
|
}
|
||||||
|
return "'docker-compose'"
|
||||||
|
}
|
||||||
|
|
||||||
func pullAndStartContainers() error {
|
func pullAndStartContainers() error {
|
||||||
fmt.Println("Starting containers...")
|
fmt.Println("Starting containers...")
|
||||||
|
|
||||||
// First try docker compose (new style)
|
// Check which docker compose command is available
|
||||||
cmd := exec.Command("docker", "compose", "-f", "docker-compose.yml", "pull")
|
var useNewStyle bool
|
||||||
cmd.Stdout = os.Stdout
|
checkCmd := exec.Command("docker", "compose", "version")
|
||||||
cmd.Stderr = os.Stderr
|
if err := checkCmd.Run(); err == nil {
|
||||||
err := cmd.Run()
|
useNewStyle = true
|
||||||
|
} else {
|
||||||
if err != nil {
|
// Check if docker-compose (old style) is available
|
||||||
fmt.Println("Failed to start containers using docker compose, falling back to docker-compose command")
|
checkCmd = exec.Command("docker-compose", "version")
|
||||||
os.Exit(1)
|
if err := checkCmd.Run(); err != nil {
|
||||||
|
return fmt.Errorf("neither 'docker compose' nor 'docker-compose' command is available: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = exec.Command("docker", "compose", "-f", "docker-compose.yml", "up", "-d")
|
// Helper function to execute docker compose commands
|
||||||
cmd.Stdout = os.Stdout
|
executeCommand := func(args ...string) error {
|
||||||
cmd.Stderr = os.Stderr
|
var cmd *exec.Cmd
|
||||||
err = cmd.Run()
|
if useNewStyle {
|
||||||
|
cmd = exec.Command("docker", append([]string{"compose"}, args...)...)
|
||||||
if err != nil {
|
} else {
|
||||||
fmt.Println("Failed to start containers using docker-compose command")
|
cmd = exec.Command("docker-compose", args...)
|
||||||
os.Exit(1)
|
}
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
// Pull containers
|
||||||
}
|
fmt.Printf("Using %s command to pull containers...\n", getCommandString(useNewStyle))
|
||||||
|
if err := executeCommand("-f", "docker-compose.yml", "pull"); err != nil {
|
||||||
|
return fmt.Errorf("failed to pull containers: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start containers
|
||||||
|
fmt.Printf("Using %s command to start containers...\n", getCommandString(useNewStyle))
|
||||||
|
if err := executeCommand("-f", "docker-compose.yml", "up", "-d"); err != nil {
|
||||||
|
return fmt.Errorf("failed to start containers: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user