refactor: resolve circular import
This commit is contained in:
61
pkg/deploy/utils.go
Normal file
61
pkg/deploy/utils.go
Normal file
@ -0,0 +1,61 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
)
|
||||
|
||||
// GetConfigNamesForStack retrieves all Docker configs attached to services in a given stack.
|
||||
func GetConfigNamesForStack(cl *client.Client, app appPkg.App) ([]string, error) {
|
||||
filters, err := app.Filters(false, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// List all services in the stack
|
||||
services, err := cl.ServiceList(context.Background(), types.ServiceListOptions{
|
||||
Filters: filters,
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
func GetSecretNamesForStack(cl *client.Client, app appPkg.App) ([]swarm.Secret, error) {
|
||||
filters, err := app.Filters(false, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secretList, err := cl.SecretList(context.Background(), swarm.SecretListOptions{Filters: filters})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return secretList, nil
|
||||
}
|
Reference in New Issue
Block a user