Only show remote configs used in deployment

This commit is contained in:
3wc
2025-09-01 15:22:40 -04:00
parent 2f521b8bf0
commit d6bf32caad
2 changed files with 37 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"strings"
"coopcloud.tech/abra/pkg/i18n"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
@ -46,3 +47,38 @@ func GetConfigNameAndVersion(fullName string, stackName string) (string, string)
}
return name, ""
}
// GetConfigNamesForStack retrieves all Docker configs attached to services in a given stack.
func GetConfigNamesForStack(cl *client.Client, ctx context.Context, stackName string) ([]string, error) {
// Create filter to get services for the specific stack
filter := filters.NewArgs()
filter.Add("label", "com.docker.stack.namespace="+stackName)
// List all services in the stack
services, err := cl.ServiceList(ctx, types.ServiceListOptions{
Filters: filter,
})
if err != nil {
return nil, err
}
// Collect unique config names from all services
configNames := make(map[string]bool)
for _, service := range services {
if service.Spec.TaskTemplate.ContainerSpec != nil {
for _, configRef := range service.Spec.TaskTemplate.ContainerSpec.Configs {
if configRef.ConfigName != "" {
configNames[configRef.ConfigName] = true
}
}
}
}
// Convert map to slice
result := make([]string, 0, len(configNames))
for name := range configNames {
result = append(result, name)
}
return result, nil
}