Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/pkg/cli/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to handle both cases: if cnt == 0 && hasDomains then the deployment is probably not finished.

term.Infof("No `domainname` found in compose file; no HTTPS cert generation needed")
}

Expand Down
48 changes: 48 additions & 0 deletions src/pkg/cli/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
Loading