From f5a9f2c7b6d525f7448b7bab03f10561440136b7 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Tue, 2 Sep 2025 12:00:47 -0400 Subject: [PATCH] Resolve circular import --- cli/app/deploy.go | 7 ++--- pkg/client/configs.go | 38 --------------------------- pkg/client/secret.go | 16 ------------ pkg/deploy/utils.go | 61 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 57 deletions(-) create mode 100644 pkg/deploy/utils.go diff --git a/cli/app/deploy.go b/cli/app/deploy.go index d8f71119..42b62cd5 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -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 diff --git a/pkg/client/configs.go b/pkg/client/configs.go index 1b8732c0..591327b2 100644 --- a/pkg/client/configs.go +++ b/pkg/client/configs.go @@ -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 -} diff --git a/pkg/client/secret.go b/pkg/client/secret.go index e2c82298..f0a19f54 100644 --- a/pkg/client/secret.go +++ b/pkg/client/secret.go @@ -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 { diff --git a/pkg/deploy/utils.go b/pkg/deploy/utils.go new file mode 100644 index 00000000..1491f680 --- /dev/null +++ b/pkg/deploy/utils.go @@ -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 +}