diff --git a/dist/go-compose-exporter_darwin_amd64 b/dist/go-compose-exporter_darwin_amd64 index 27a4fd7..69add98 100755 Binary files a/dist/go-compose-exporter_darwin_amd64 and b/dist/go-compose-exporter_darwin_amd64 differ diff --git a/dist/go-compose-exporter_darwin_arm64 b/dist/go-compose-exporter_darwin_arm64 index ab7219e..5e93039 100755 Binary files a/dist/go-compose-exporter_darwin_arm64 and b/dist/go-compose-exporter_darwin_arm64 differ diff --git a/dist/go-compose-exporter_linux_amd64 b/dist/go-compose-exporter_linux_amd64 index 469dd12..6178532 100755 Binary files a/dist/go-compose-exporter_linux_amd64 and b/dist/go-compose-exporter_linux_amd64 differ diff --git a/dist/go-compose-exporter_linux_amd64_static b/dist/go-compose-exporter_linux_amd64_static index 9b086e6..4d0923e 100755 Binary files a/dist/go-compose-exporter_linux_amd64_static and b/dist/go-compose-exporter_linux_amd64_static differ diff --git a/dist/go-compose-exporter_linux_arm64 b/dist/go-compose-exporter_linux_arm64 index 7ec77a3..5f4e509 100755 Binary files a/dist/go-compose-exporter_linux_arm64 and b/dist/go-compose-exporter_linux_arm64 differ diff --git a/dist/go-compose-exporter_linux_arm64_static b/dist/go-compose-exporter_linux_arm64_static index 9f04728..b1a285a 100755 Binary files a/dist/go-compose-exporter_linux_arm64_static and b/dist/go-compose-exporter_linux_arm64_static differ diff --git a/dist/go-compose-exporter_windows_amd64 b/dist/go-compose-exporter_windows_amd64 index fa87d1c..bf82ecb 100755 Binary files a/dist/go-compose-exporter_windows_amd64 and b/dist/go-compose-exporter_windows_amd64 differ diff --git a/main.go b/main.go index a517f8c..e8d62e8 100644 --- a/main.go +++ b/main.go @@ -67,12 +67,10 @@ func main() { isSwarm := isDockerSwarmStack(*stackName, containers) if isSwarm { - // Handle Docker Swarm stack export - err = exportSwarmStackToComposeFile(*stackName, *outputFile) - if err != nil { - log.Fatalf("Error exporting Docker Swarm stack %s: %v", *stackName, err) - } - fmt.Printf("docker-compose.yml generated successfully for Docker Swarm stack '%s' in %s\n", *stackName, *outputFile) + // Notify the user that exporting Swarm stacks isn't fully supported + fmt.Printf("Warning: The stack '%s' appears to be a Docker Swarm stack. Export functionality for Swarm stacks may not provide complete configurations.\n", *stackName) + fmt.Println("Skipping export for Docker Swarm stacks. Please use `docker stack` commands directly for managing Swarm stacks.") + return } else { // Handle Docker Compose project export err = exportComposeProjectToComposeFile(*stackName, containers, *outputFile) @@ -186,65 +184,6 @@ func isDockerSwarmStack(stackName string, containers []Container) bool { return false } -// exportSwarmStackToComposeFile exports a Docker Swarm stack to a docker-compose.yml file. -func exportSwarmStackToComposeFile(stackName string, outputFile string) error { - // Fetch stack details using `docker stack services` and construct the docker-compose.yml - cmd := exec.Command("docker", "stack", "services", stackName, "--format", "{{.Name}} {{.Image}} {{.Ports}} {{.Replicas}}") - var out bytes.Buffer - cmd.Stdout = &out - err := cmd.Run() - if err != nil { - return fmt.Errorf("error fetching Docker Swarm stack services: %v", err) - } - - composeConfig := make(map[string]interface{}) - composeConfig["services"] = make(map[string]interface{}) - - scanner := bufio.NewScanner(&out) - for scanner.Scan() { - fields := strings.Fields(scanner.Text()) - if len(fields) < 2 { - continue - } - - serviceName := fields[0] - image := fields[1] - - serviceConfig := map[string]interface{}{ - "image": image, - } - - // Handle additional fields like ports and replicas - if len(fields) > 2 { - // Parse ports and replicas if available - ports := fields[2] - replicas := fields[3] - serviceConfig["deploy"] = map[string]interface{}{ - "replicas": replicas, - } - if ports != "" { - serviceConfig["ports"] = []string{ports} - } - } - - composeConfig["services"].(map[string]interface{})[serviceName] = serviceConfig - } - - // Convert to YAML - yamlData, err := yaml.Marshal(&composeConfig) - if err != nil { - return fmt.Errorf("error generating YAML for Docker Swarm stack %s: %v", stackName, err) - } - - // Write YAML to a file - err = os.WriteFile(outputFile, yamlData, 0644) - if err != nil { - return fmt.Errorf("error writing to file %s: %v", outputFile, err) - } - - return nil -} - // exportComposeProjectToComposeFile exports a Docker Compose project to a docker-compose.yml file. func exportComposeProjectToComposeFile(stack string, containers []Container, outputFile string) error { // Map to hold docker-compose configuration