Resolve circular import
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/deploy"
|
||||
"coopcloud.tech/abra/pkg/dns"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
@ -216,7 +217,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
// Gather configs
|
||||
|
||||
// Get current configs from existing deployment
|
||||
currentConfigNames, err := client.GetConfigNamesForStack(cl, app)
|
||||
currentConfigNames, err := deploy.GetConfigNamesForStack(cl, app)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -242,7 +243,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
newVersion, exists := abraShEnv[versionKey]
|
||||
if !exists {
|
||||
log.Warnf("No version found for config %s", configName)
|
||||
configInfo = append(configInfo, fmt.Sprintf("%s: ? (missing)", configName))
|
||||
configInfo = append(configInfo, fmt.Sprintf("%s: ? (missing version)", configName))
|
||||
continue
|
||||
}
|
||||
|
||||
@ -255,7 +256,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
} else {
|
||||
configInfo = append(configInfo, fmt.Sprintf("%s: %s (new)", configName, newVersion))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gather images
|
||||
|
||||
|
@ -6,8 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
"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"
|
||||
@ -48,39 +46,3 @@ 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, 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
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
)
|
||||
@ -20,20 +18,6 @@ func StoreSecret(cl *client.Client, secretName, secretValue string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetSecretNamesForStack(cl *client.Client, app appPkg.App) ([]string, 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 GetSecretNames(secretList), nil
|
||||
}
|
||||
|
||||
func GetSecretNames(secrets []swarm.Secret) []string {
|
||||
var secretNames []string
|
||||
for _, secret := range secrets {
|
||||
|
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