From 488cc8d123f4d505265c1c25580a3b30a26b3add Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 May 2025 20:48:22 +0000 Subject: [PATCH 1/3] fix(deps): update module github.com/compose-spec/compose-go to v2 --- go.mod | 1 + go.sum | 1 + 2 files changed, 2 insertions(+) diff --git a/go.mod b/go.mod index f38fd58e5..b88c0fcd2 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/aws/smithy-go v1.22.3 github.com/briandowns/spinner v1.23.2 github.com/compose-spec/compose-go v1.20.2 + github.com/compose-spec/compose-go/v2 v2.6.4 github.com/fluxcd/kustomize-controller/api v1.5.1 github.com/fluxcd/pkg/apis/kustomize v1.9.0 github.com/fluxcd/pkg/apis/meta v1.10.0 diff --git a/go.sum b/go.sum index 88e751276..dde286bfc 100644 --- a/go.sum +++ b/go.sum @@ -125,6 +125,7 @@ github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 h1:aQ3y1lwWyqYPiWZThqv github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= github.com/compose-spec/compose-go v1.20.2 h1:u/yfZHn4EaHGdidrZycWpxXgFffjYULlTbRfJ51ykjQ= github.com/compose-spec/compose-go v1.20.2/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM= +github.com/compose-spec/compose-go/v2 v2.6.4/go.mod h1:vPlkN0i+0LjLf9rv52lodNMUTJF5YHVfHVGLLIP67NA= github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4= github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE= github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= From 1b72f8d5b22da53210ebbdbc02dc8bee8994ee16 Mon Sep 17 00:00:00 2001 From: rmvangun <85766511+rmvangun@users.noreply.github.com> Date: Mon, 26 May 2025 17:42:20 -0400 Subject: [PATCH 2/3] fix: simplify Renovate config to use default Go module handling (#1239) Allow upgrading go in go.mod file --- .github/renovate.json | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/renovate.json b/.github/renovate.json index eb43ea6db..1674729a1 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -46,7 +46,6 @@ "matchManagers": [ "gomod" ], - "enabled": true, "automerge": true, "automergeType": "pr", "automergeStrategy": "squash", @@ -55,6 +54,13 @@ "dependencies" ] }, + { + "description": "Enable Go version updates", + "matchManagers": ["gomod"], + "matchDepNames": ["go"], + "matchDepTypes": ["golang"], + "rangeStrategy": "bump" + }, { "description": "Update Taskfile dependencies", "matchFileNames": [ @@ -67,16 +73,6 @@ "labels": [ "dependencies" ] - }, - { - "description": "Pin Go to version 1.23.4", - "matchManagers": [ - "gomod" - ], - "matchPackageNames": [ - "golang.org/x" - ], - "allowedVersions": "1.23.4" } ], "platformAutomerge": true, @@ -117,5 +113,8 @@ ], "labels": [ "dependencies" + ], + "postUpdateOptions": [ + "gomodTidy" ] } From 351d9f7f62f472a32fd3a6fd07b2539b409cb3d3 Mon Sep 17 00:00:00 2001 From: Ryan VanGundy Date: Mon, 26 May 2025 18:23:17 -0400 Subject: [PATCH 3/3] feat: migrate to compose-go v2 - Update imports, fix Services map structure, update tests --- go.mod | 4 +- go.sum | 7 +-- pkg/services/dns_service.go | 6 +- pkg/services/dns_service_test.go | 47 +++++++++------ pkg/services/git_livereload_service.go | 20 ++++--- pkg/services/localstack_service.go | 42 ++++++------- pkg/services/localstack_service_test.go | 10 +++- pkg/services/mock_service.go | 2 +- pkg/services/mock_service_test.go | 2 +- pkg/services/registry_service.go | 5 +- pkg/services/registry_service_test.go | 2 +- pkg/services/service.go | 2 +- pkg/services/talos_service.go | 10 +++- pkg/services/talos_service_test.go | 78 +++++++++++++++++++------ pkg/virt/docker_virt.go | 9 +-- pkg/virt/docker_virt_test.go | 8 +-- 16 files changed, 163 insertions(+), 91 deletions(-) diff --git a/go.mod b/go.mod index b88c0fcd2..2cf78c60c 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/abiosoft/colima v0.8.1 github.com/aws/smithy-go v1.22.3 github.com/briandowns/spinner v1.23.2 - github.com/compose-spec/compose-go v1.20.2 github.com/compose-spec/compose-go/v2 v2.6.4 github.com/fluxcd/kustomize-controller/api v1.5.1 github.com/fluxcd/pkg/apis/kustomize v1.9.0 @@ -100,6 +99,7 @@ require ( github.com/go-openapi/jsonpointer v0.21.1 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/swag v0.23.1 // indirect + github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.2 // indirect @@ -152,6 +152,7 @@ require ( github.com/tetratelabs/wazero v1.9.0 // indirect github.com/urfave/cli v1.22.16 // indirect github.com/x448/float16 v0.8.4 // indirect + github.com/xhit/go-str2duration/v2 v2.1.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect github.com/zeebo/errs v1.4.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect @@ -164,7 +165,6 @@ require ( go.opentelemetry.io/otel/sdk/metric v1.36.0 // indirect go.opentelemetry.io/otel/trace v1.36.0 // indirect go.opentelemetry.io/proto/otlp v1.6.0 // indirect - golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect golang.org/x/mod v0.24.0 // indirect golang.org/x/net v0.40.0 // indirect golang.org/x/oauth2 v0.30.0 // indirect diff --git a/go.sum b/go.sum index dde286bfc..f1207ee8c 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,7 @@ github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 h1:aQ3y1lwWyqYPiWZThqv1aFbZMiM9vblcSArJRf2Irls= github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= -github.com/compose-spec/compose-go v1.20.2 h1:u/yfZHn4EaHGdidrZycWpxXgFffjYULlTbRfJ51ykjQ= -github.com/compose-spec/compose-go v1.20.2/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM= +github.com/compose-spec/compose-go/v2 v2.6.4 h1:Gjv6x8eAhqwwWvoXIo0oZ4bDQBh0OMwdU7LUL9PDLiM= github.com/compose-spec/compose-go/v2 v2.6.4/go.mod h1:vPlkN0i+0LjLf9rv52lodNMUTJF5YHVfHVGLLIP67NA= github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4= github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE= @@ -381,6 +380,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= +github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= @@ -418,8 +419,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= -golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI= -golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= diff --git a/pkg/services/dns_service.go b/pkg/services/dns_service.go index 769a9746d..6cda0ae64 100644 --- a/pkg/services/dns_service.go +++ b/pkg/services/dns_service.go @@ -5,7 +5,7 @@ import ( "path/filepath" "strings" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/constants" "github.com/windsorcli/cli/pkg/di" ) @@ -102,7 +102,9 @@ func (s *DNSService) GetComposeConfig() (*types.Config, error) { } } - services := []types.ServiceConfig{corednsConfig} + services := types.Services{ + serviceName: corednsConfig, + } return &types.Config{Services: services}, nil } diff --git a/pkg/services/dns_service_test.go b/pkg/services/dns_service_test.go index f86248550..7912deb94 100644 --- a/pkg/services/dns_service_test.go +++ b/pkg/services/dns_service_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/config" "github.com/windsorcli/cli/pkg/di" ) @@ -222,8 +222,8 @@ func TestDNSService_GetComposeConfig(t *testing.T) { if len(cfg.Services) != 1 { t.Errorf("Expected 1 service, got %d", len(cfg.Services)) } - if cfg.Services[0].Name != "dns" { - t.Errorf("Expected service name to be 'dns', got %s", cfg.Services[0].Name) + if service, exists := cfg.Services["dns"]; !exists || service.Name != "dns" { + t.Errorf("Expected service with name 'dns', got %+v", cfg.Services) } }) @@ -249,14 +249,27 @@ func TestDNSService_GetComposeConfig(t *testing.T) { if len(cfg.Services) != 1 { t.Errorf("Expected 1 service, got %d", len(cfg.Services)) } - if len(cfg.Services[0].Ports) != 2 { - t.Errorf("Expected 2 ports, got %d", len(cfg.Services[0].Ports)) + + // Get the DNS service from the map + var dnsService types.ServiceConfig + var found bool + for _, svc := range cfg.Services { + dnsService = svc + found = true + break + } + if !found { + t.Fatalf("No service found in Services map") + } + + if len(dnsService.Ports) != 2 { + t.Errorf("Expected 2 ports, got %d", len(dnsService.Ports)) } - if cfg.Services[0].Ports[0].Published != "53" || cfg.Services[0].Ports[0].Protocol != "tcp" { - t.Errorf("Expected port 53 with protocol tcp, got port %s with protocol %s", cfg.Services[0].Ports[0].Published, cfg.Services[0].Ports[0].Protocol) + if dnsService.Ports[0].Published != "53" || dnsService.Ports[0].Protocol != "tcp" { + t.Errorf("Expected port 53 with protocol tcp, got port %s with protocol %s", dnsService.Ports[0].Published, dnsService.Ports[0].Protocol) } - if cfg.Services[0].Ports[1].Published != "53" || cfg.Services[0].Ports[1].Protocol != "udp" { - t.Errorf("Expected port 53 with protocol udp, got port %s with protocol %s", cfg.Services[0].Ports[1].Published, cfg.Services[0].Ports[1].Protocol) + if dnsService.Ports[1].Published != "53" || dnsService.Ports[1].Protocol != "udp" { + t.Errorf("Expected port 53 with protocol udp, got port %s with protocol %s", dnsService.Ports[1].Published, dnsService.Ports[1].Protocol) } }) } @@ -401,8 +414,8 @@ func TestDNSService_WriteConfig(t *testing.T) { } mockService.GetComposeConfigFunc = func() (*types.Config, error) { return &types.Config{ - Services: []types.ServiceConfig{ - {Name: "test-service"}, + Services: types.Services{ + "test-service": {Name: "test-service"}, }, }, nil } @@ -454,8 +467,8 @@ func TestDNSService_WriteConfig(t *testing.T) { } mockService.GetComposeConfigFunc = func() (*types.Config, error) { return &types.Config{ - Services: []types.ServiceConfig{ - {Name: "test-service"}, + Services: types.Services{ + "test-service": {Name: "test-service"}, }, }, nil } @@ -519,8 +532,8 @@ func TestDNSService_WriteConfig(t *testing.T) { } mockServiceNoName.GetComposeConfigFunc = func() (*types.Config, error) { return &types.Config{ - Services: []types.ServiceConfig{ - {Name: ""}, + Services: types.Services{ + "": {Name: ""}, }, }, nil } @@ -535,8 +548,8 @@ func TestDNSService_WriteConfig(t *testing.T) { } mockServiceNoAddress.GetComposeConfigFunc = func() (*types.Config, error) { return &types.Config{ - Services: []types.ServiceConfig{ - {Name: "test-service"}, + Services: types.Services{ + "test-service": {Name: "test-service"}, }, }, nil } diff --git a/pkg/services/git_livereload_service.go b/pkg/services/git_livereload_service.go index d01be2673..2752f4ae1 100644 --- a/pkg/services/git_livereload_service.go +++ b/pkg/services/git_livereload_service.go @@ -4,7 +4,7 @@ import ( "fmt" "path/filepath" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/constants" "github.com/windsorcli/cli/pkg/di" ) @@ -43,9 +43,6 @@ func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { // Get the context name contextName := s.configHandler.GetContext() - // Prepare the services slice for docker-compose - var services []types.ServiceConfig - // Retrieve environment variables from config with defaults using Get* functions rsyncExclude := s.configHandler.GetString("git.livereload.rsync_exclude", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE) rsyncProtect := s.configHandler.GetString("git.livereload.rsync_protect", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT) @@ -78,9 +75,12 @@ func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { // Get the git folder name gitFolderName := filepath.Base(projectRoot) - // Add the git-livereload service - services = append(services, types.ServiceConfig{ - Name: s.name, + // Get the service name + serviceName := s.name + + // Create the service config + serviceConfig := types.ServiceConfig{ + Name: serviceName, ContainerName: s.GetContainerName(), Image: image, Restart: "always", @@ -97,7 +97,11 @@ func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { Target: fmt.Sprintf("/repos/mount/%s", gitFolderName), }, }, - }) + } + + services := types.Services{ + serviceName: serviceConfig, + } return &types.Config{ Services: services, diff --git a/pkg/services/localstack_service.go b/pkg/services/localstack_service.go index 6e3e7e5aa..42fd2272b 100644 --- a/pkg/services/localstack_service.go +++ b/pkg/services/localstack_service.go @@ -4,7 +4,7 @@ import ( "os" "strings" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/constants" "github.com/windsorcli/cli/pkg/di" ) @@ -63,36 +63,38 @@ func (s *LocalstackService) GetComposeConfig() (*types.Config, error) { containerName := s.GetContainerName() // Create the service config - services := []types.ServiceConfig{ - { - Name: serviceName, - ContainerName: containerName, - Image: image, - Restart: "always", - Environment: map[string]*string{ - "ENFORCE_IAM": ptrString("1"), - "PERSISTENCE": ptrString("1"), - "IAM_SOFT_MODE": ptrString("0"), - "DEBUG": ptrString("0"), - "SERVICES": ptrString(servicesList), - }, - Labels: map[string]string{ - "role": "localstack", - "managed_by": "windsor", - "wildcard": "true", - }, + serviceConfig := types.ServiceConfig{ + Name: serviceName, + ContainerName: containerName, + Image: image, + Restart: "always", + Environment: map[string]*string{ + "ENFORCE_IAM": ptrString("1"), + "PERSISTENCE": ptrString("1"), + "IAM_SOFT_MODE": ptrString("0"), + "DEBUG": ptrString("0"), + "SERVICES": ptrString(servicesList), + }, + Labels: map[string]string{ + "role": "localstack", + "managed_by": "windsor", + "wildcard": "true", }, } // If the localstack auth token is set, add it to the secrets if localstackAuthToken != "" { - services[0].Secrets = []types.ServiceSecretConfig{ + serviceConfig.Secrets = []types.ServiceSecretConfig{ { Source: "LOCALSTACK_AUTH_TOKEN", }, } } + services := types.Services{ + serviceName: serviceConfig, + } + return &types.Config{Services: services}, nil } diff --git a/pkg/services/localstack_service_test.go b/pkg/services/localstack_service_test.go index 9b14263be..5613e8d9a 100644 --- a/pkg/services/localstack_service_test.go +++ b/pkg/services/localstack_service_test.go @@ -51,7 +51,10 @@ func TestLocalstackService_GetComposeConfig(t *testing.T) { t.Fatalf("expected non-nil composeConfig with services, got %v", composeConfig) } - composeService := composeConfig.Services[0] + composeService, exists := composeConfig.Services["aws"] + if !exists { + t.Fatalf("expected service 'aws' to exist in compose config") + } if composeService.Name != "aws" { t.Errorf("expected service name 'aws', got %v", composeService.Name) } @@ -93,7 +96,10 @@ func TestLocalstackService_GetComposeConfig(t *testing.T) { t.Fatalf("expected non-nil composeConfig with services, got %v", composeConfig) } - composeService := composeConfig.Services[0] + composeService, exists := composeConfig.Services["aws"] + if !exists { + t.Fatalf("expected service 'aws' to exist in compose config") + } if len(composeService.Secrets) == 0 || composeService.Secrets[0].Source != "LOCALSTACK_AUTH_TOKEN" { t.Errorf("expected service to have LOCALSTACK_AUTH_TOKEN secret, got %v", composeService.Secrets) } diff --git a/pkg/services/mock_service.go b/pkg/services/mock_service.go index cebea9c12..3960da890 100644 --- a/pkg/services/mock_service.go +++ b/pkg/services/mock_service.go @@ -1,7 +1,7 @@ package services import ( - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" ) // The MockService is a test implementation of the Service interface diff --git a/pkg/services/mock_service_test.go b/pkg/services/mock_service_test.go index 0db677d46..2bd286d22 100644 --- a/pkg/services/mock_service_test.go +++ b/pkg/services/mock_service_test.go @@ -3,7 +3,7 @@ package services import ( "testing" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" ) // The MockServiceTest provides test coverage for the MockService implementation. diff --git a/pkg/services/registry_service.go b/pkg/services/registry_service.go index e48776300..905a24ef8 100644 --- a/pkg/services/registry_service.go +++ b/pkg/services/registry_service.go @@ -6,7 +6,7 @@ import ( "strings" "sync" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/api/v1alpha1/docker" "github.com/windsorcli/cli/pkg/constants" "github.com/windsorcli/cli/pkg/di" @@ -60,7 +60,8 @@ func (s *RegistryService) GetComposeConfig() (*types.Config, error) { if err != nil { return nil, fmt.Errorf("failed to generate registry service: %w", err) } - return &types.Config{Services: []types.ServiceConfig{service}}, nil + serviceName := getBasename(s.GetHostname()) + return &types.Config{Services: types.Services{serviceName: service}}, nil } return nil, fmt.Errorf("no registry found with name: %s", s.name) diff --git a/pkg/services/registry_service_test.go b/pkg/services/registry_service_test.go index 3dbb437b6..f57d63015 100644 --- a/pkg/services/registry_service_test.go +++ b/pkg/services/registry_service_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/api/v1alpha1" "github.com/windsorcli/cli/api/v1alpha1/docker" "github.com/windsorcli/cli/pkg/config" diff --git a/pkg/services/service.go b/pkg/services/service.go index c7a72d250..b864f1b74 100644 --- a/pkg/services/service.go +++ b/pkg/services/service.go @@ -6,7 +6,7 @@ import ( "net" "strings" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/config" "github.com/windsorcli/cli/pkg/di" "github.com/windsorcli/cli/pkg/shell" diff --git a/pkg/services/talos_service.go b/pkg/services/talos_service.go index c71a13f91..e087f0a6f 100644 --- a/pkg/services/talos_service.go +++ b/pkg/services/talos_service.go @@ -8,7 +8,7 @@ import ( "strings" "sync" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/constants" "github.com/windsorcli/cli/pkg/di" ) @@ -148,7 +148,7 @@ func (s *TalosService) GetComposeConfig() (*types.Config, error) { config := s.configHandler.GetConfig() if config.Cluster == nil { return &types.Config{ - Services: []types.ServiceConfig{}, + Services: types.Services{}, Volumes: map[string]types.VolumeConfig{}, }, nil } @@ -300,8 +300,12 @@ func (s *TalosService) GetComposeConfig() (*types.Config, error) { strings.ReplaceAll(nodeName+"_opt", "-", "_"): {}, } + services := types.Services{ + nodeName: serviceConfig, + } + return &types.Config{ - Services: []types.ServiceConfig{serviceConfig}, + Services: services, Volumes: volumesMap, }, nil } diff --git a/pkg/services/talos_service_test.go b/pkg/services/talos_service_test.go index 7a11d8ce1..c3e2c663f 100644 --- a/pkg/services/talos_service_test.go +++ b/pkg/services/talos_service_test.go @@ -965,7 +965,10 @@ func TestTalosService_GetComposeConfig(t *testing.T) { } // And the service should have the correct configuration - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } if serviceConfig.Name != "controlplane1" { t.Errorf("expected service name controlplane1, got %s", serviceConfig.Name) } @@ -1034,7 +1037,10 @@ func TestTalosService_GetComposeConfig(t *testing.T) { } // And the service should have the correct configuration - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["worker1"] + if !exists { + t.Fatalf("expected service 'worker1' to exist in compose config") + } if serviceConfig.Name != "worker1" { t.Errorf("expected service name worker1, got %s", serviceConfig.Name) } @@ -1072,8 +1078,12 @@ func TestTalosService_GetComposeConfig(t *testing.T) { } // And the config should use the custom image - if config.Services[0].Image != customImage { - t.Errorf("expected image %s, got %s", customImage, config.Services[0].Image) + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } + if serviceConfig.Image != customImage { + t.Errorf("expected image %s, got %s", customImage, serviceConfig.Image) } }) @@ -1099,7 +1109,10 @@ func TestTalosService_GetComposeConfig(t *testing.T) { } // And the config should have the custom volumes - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } for _, expectedVolume := range volumes { found := false for _, volume := range serviceConfig.Volumes { @@ -1206,8 +1219,12 @@ contexts: } // And the node-specific image should be used - if config.Services[0].Image != "node-specific:latest" { - t.Errorf("expected node-specific image, got %s", config.Services[0].Image) + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } + if serviceConfig.Image != "node-specific:latest" { + t.Errorf("expected node-specific image, got %s", serviceConfig.Image) } }) @@ -1233,7 +1250,10 @@ contexts: } // And the custom volumes should be included - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } for _, expectedVolume := range customVolumes { found := false for _, volume := range serviceConfig.Volumes { @@ -1308,8 +1328,12 @@ contexts: } // And the service should have the correct name - if cfg.Services[0].Name != "worker1" { - t.Errorf("expected service name 'worker1', got '%s'", cfg.Services[0].Name) + serviceConfig, exists := cfg.Services["worker1"] + if !exists { + t.Fatalf("expected service 'worker1' to exist in compose config") + } + if serviceConfig.Name != "worker1" { + t.Errorf("expected service name 'worker1', got '%s'", serviceConfig.Name) } }) @@ -1340,7 +1364,10 @@ contexts: } // And the ports should be configured correctly - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } if len(serviceConfig.Ports) != 4 { // 2 custom ports + default API port + kubernetes port t.Errorf("expected 4 ports, got %d", len(serviceConfig.Ports)) } @@ -1497,7 +1524,10 @@ contexts: } // And the volume config should use the original paths with variables - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } for _, expectedVolume := range volumes { found := false for _, volume := range serviceConfig.Volumes { @@ -1538,7 +1568,10 @@ contexts: } // And the control plane should have the custom CPU and RAM settings - serviceConfig := config.Services[0] + serviceConfig, exists := config.Services["controlplane1"] + if !exists { + t.Fatalf("expected service 'controlplane1' to exist in compose config") + } expectedSKU := fmt.Sprintf("%dCPU-%dRAM", customCPU, customRAM*1024) if serviceConfig.Environment["TALOSSKU"] == nil { t.Error("expected TALOSSKU environment variable") @@ -1568,7 +1601,10 @@ contexts: } // And the worker should have the custom CPU and RAM settings - serviceConfig = config.Services[0] + serviceConfig, exists = config.Services["worker1"] + if !exists { + t.Fatalf("expected service 'worker1' to exist in compose config") + } expectedSKU = fmt.Sprintf("%dCPU-%dRAM", customWorkerCPU, customWorkerRAM*1024) if serviceConfig.Environment["TALOSSKU"] == nil { t.Error("expected TALOSSKU environment variable") @@ -1622,20 +1658,24 @@ contexts: } // And the service name should fall back to "controlplane" - if config.Services[0].Name != "controlplane" { - t.Errorf("expected service name 'controlplane', got %s", config.Services[0].Name) + serviceConfig, exists := config.Services["controlplane"] + if !exists { + t.Fatalf("expected service 'controlplane' to exist in compose config") + } + if serviceConfig.Name != "controlplane" { + t.Errorf("expected service name 'controlplane', got %s", serviceConfig.Name) } // And the container name should use the fallback name with context prefix expectedContainerName := "controlplane.test" - if config.Services[0].ContainerName != expectedContainerName { - t.Errorf("expected container name %s, got %s", expectedContainerName, config.Services[0].ContainerName) + if serviceConfig.ContainerName != expectedContainerName { + t.Errorf("expected container name %s, got %s", expectedContainerName, serviceConfig.ContainerName) } // And the volumes should use the fallback name expectedVolumeName := "controlplane_system_state" found := false - for _, volume := range config.Services[0].Volumes { + for _, volume := range serviceConfig.Volumes { if volume.Source == expectedVolumeName { found = true break diff --git a/pkg/virt/docker_virt.go b/pkg/virt/docker_virt.go index aa6a6c66c..407e5711f 100644 --- a/pkg/virt/docker_virt.go +++ b/pkg/virt/docker_virt.go @@ -14,7 +14,7 @@ import ( "strings" "time" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/di" "github.com/windsorcli/cli/pkg/services" ) @@ -334,10 +334,11 @@ func (v *DockerVirt) getFullComposeConfig() (*types.Project, error) { return nil, fmt.Errorf("Docker configuration is not defined") } - var combinedServices []types.ServiceConfig + var combinedServices types.Services var combinedVolumes map[string]types.VolumeConfig var combinedNetworks map[string]types.NetworkConfig + combinedServices = make(types.Services) combinedVolumes = make(map[string]types.VolumeConfig) combinedNetworks = make(map[string]types.NetworkConfig) @@ -375,7 +376,7 @@ func (v *DockerVirt) getFullComposeConfig() (*types.Project, error) { } if containerConfigs.Services != nil { - for _, containerConfig := range containerConfigs.Services { + for serviceName, containerConfig := range containerConfigs.Services { ipAddress := serviceInstance.GetAddress() containerConfig.Networks = map[string]*types.ServiceNetworkConfig{ @@ -387,7 +388,7 @@ func (v *DockerVirt) getFullComposeConfig() (*types.Project, error) { containerConfig.Networks[networkName].Ipv4Address = ipAddress } - combinedServices = append(combinedServices, containerConfig) + combinedServices[serviceName] = containerConfig } } diff --git a/pkg/virt/docker_virt_test.go b/pkg/virt/docker_virt_test.go index df5773f99..cbc692ffe 100644 --- a/pkg/virt/docker_virt_test.go +++ b/pkg/virt/docker_virt_test.go @@ -12,7 +12,7 @@ import ( "strings" "testing" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/windsorcli/cli/pkg/di" "github.com/windsorcli/cli/pkg/services" ) @@ -111,8 +111,8 @@ contexts: // Set up mock service config mocks.Service.GetComposeConfigFunc = func() (*types.Config, error) { return &types.Config{ - Services: []types.ServiceConfig{ - { + Services: types.Services{ + "service1": { Name: "service1", Labels: map[string]string{ "role": "test", @@ -124,7 +124,7 @@ contexts: }, }, }, - { + "service2": { Name: "service2", Labels: map[string]string{ "role": "test",