Add GetSecretNamesForStack, tidy up GetConfigNamesForStack

This commit is contained in:
3wc
2025-09-02 11:32:37 -04:00
parent db92b3920a
commit 17ff200f13
3 changed files with 38 additions and 8 deletions

View File

@ -216,7 +216,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
// Gather configs // Gather configs
// Get current configs from existing deployment // Get current configs from existing deployment
currentConfigNames, err := client.GetConfigNamesForStack(cl, context.Background(), app.StackName()) currentConfigNames, err := client.GetConfigNamesForStack(cl, app)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -237,7 +237,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
var configInfo []string var configInfo []string
for configName := range newConfigs { for configName := range newConfigs {
log.Debugf("Searching for abra.sh version for %s", configName) log.Debugf("Searching abra.sh for version for %s", configName)
versionKey := strings.ToUpper(configName) + "_VERSION" versionKey := strings.ToUpper(configName) + "_VERSION"
newVersion, exists := abraShEnv[versionKey] newVersion, exists := abraShEnv[versionKey]
if !exists { if !exists {
@ -257,11 +257,15 @@ checkout as-is. Recipe commit hashes are also supported as values for
} }
} }
// Gather images
var imageInfo []string var imageInfo []string
for _, service := range compose.Services { for _, service := range compose.Services {
imageInfo = append(imageInfo, fmt.Sprintf("%s: %s", service.Name, service.Image)) imageInfo = append(imageInfo, fmt.Sprintf("%s: %s", service.Name, service.Image))
} }
// Show deploy overview
if err := internal.DeployOverview( if err := internal.DeployOverview(
app, app,
deployedVersion, deployedVersion,

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"coopcloud.tech/abra/pkg/i18n" "coopcloud.tech/abra/pkg/i18n"
appPkg "coopcloud.tech/abra/pkg/app"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
@ -49,14 +50,15 @@ func GetConfigNameAndVersion(fullName string, stackName string) (string, string)
} }
// GetConfigNamesForStack retrieves all Docker configs attached to services in a given stack. // GetConfigNamesForStack retrieves all Docker configs attached to services in a given stack.
func GetConfigNamesForStack(cl *client.Client, ctx context.Context, stackName string) ([]string, error) { func GetConfigNamesForStack(cl *client.Client, app appPkg.App) ([]string, error) {
// Create filter to get services for the specific stack filters, err := app.Filters(false, false)
filter := filters.NewArgs() if err != nil {
filter.Add("label", "com.docker.stack.namespace="+stackName) return nil, err
}
// List all services in the stack // List all services in the stack
services, err := cl.ServiceList(ctx, types.ServiceListOptions{ services, err := cl.ServiceList(context.Background(), types.ServiceListOptions{
Filters: filter, Filters: filters,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -3,6 +3,8 @@ package client
import ( import (
"context" "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/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
) )
@ -17,3 +19,25 @@ func StoreSecret(cl *client.Client, secretName, secretValue string) error {
return nil 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 {
secretNames = append(secretNames, secret.Spec.Name)
}
return secretNames
}