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
16 changes: 15 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,8 +108,13 @@ func GenerateLetsEncryptCert(ctx context.Context, project *compose.Project, clie
}
}
}
// Handle different scenarios based on domain presence and cert processing
if cnt == 0 {
term.Infof("No `domainname` found in compose file; no HTTPS cert generation needed")
if !hasDomains {
term.Infof("No `domainname` found in compose file; no HTTPS cert generation needed")
} else {
term.Infof("Deployment may not be finished yet; please wait and try again")
}
}

return nil
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)
}
})
}
}