diff --git a/src/pkg/cli/cert.go b/src/pkg/cli/cert.go index b21848582..31bba6417 100644 --- a/src/pkg/cli/cert.go +++ b/src/pkg/cli/cert.go @@ -84,6 +84,15 @@ func GenerateLetsEncryptCert(ctx context.Context, project *compose.Project, clie return err } + // First, check if there are any domain names in the compose file at all + hasDomains := false + for _, service := range project.Services { + if service.DomainName != "" { + hasDomains = true + break + } + } + cnt := 0 for _, serviceInfo := range services.Services { if service, ok := project.Services[serviceInfo.Service.Name]; ok && service.DomainName != "" && serviceInfo.ZoneId == "" { @@ -99,7 +108,8 @@ func GenerateLetsEncryptCert(ctx context.Context, project *compose.Project, clie } } } - if cnt == 0 { + // Only show the "no domainname found" message if there truly are no domains in the compose file + if cnt == 0 && !hasDomains { term.Infof("No `domainname` found in compose file; no HTTPS cert generation needed") } diff --git a/src/pkg/cli/cert_test.go b/src/pkg/cli/cert_test.go index be22564b6..8ab049c71 100644 --- a/src/pkg/cli/cert_test.go +++ b/src/pkg/cli/cert_test.go @@ -311,3 +311,51 @@ func TestGetDomainTargets(t *testing.T) { }) } } + +// Test helper function to check if domains exist in compose project +func TestHasDomains(t *testing.T) { + tests := []struct { + name string + services map[string]compose.ServiceConfig + expected bool + }{ + { + name: "no services", + services: map[string]compose.ServiceConfig{}, + expected: false, + }, + { + name: "services without domains", + services: map[string]compose.ServiceConfig{ + "web": {Name: "web", DomainName: ""}, + "api": {Name: "api", DomainName: ""}, + }, + expected: false, + }, + { + name: "services with domains", + services: map[string]compose.ServiceConfig{ + "web": {Name: "web", DomainName: "example.com"}, + "api": {Name: "api", DomainName: ""}, + }, + expected: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Simulate the logic from GenerateLetsEncryptCert + hasDomains := false + for _, service := range tt.services { + if service.DomainName != "" { + hasDomains = true + break + } + } + + if hasDomains != tt.expected { + t.Errorf("expected hasDomains=%v, got %v", tt.expected, hasDomains) + } + }) + } +}