WIP: Working secret and config versions during deploy overview
This commit is contained in:
@ -3,6 +3,8 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
@ -22,7 +24,6 @@ import (
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// translators: `abra app deploy` aliases. use a comma separated list of aliases with
|
||||
@ -195,34 +196,41 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
deployedVersion = deployMeta.Version
|
||||
}
|
||||
|
||||
filters, err := app.Filters(false, false)
|
||||
secStats, err := secret.PollSecretsStatus(cl, app)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
secretList, err := cl.SecretList(context.Background(), types.SecretListOptions{Filters: filters})
|
||||
var secretInfo []string
|
||||
|
||||
// Sort secrets to ensure reproducible output
|
||||
sort.Slice(secStats, func(i, j int) bool {
|
||||
return secStats[i].LocalName < secStats[j].LocalName
|
||||
})
|
||||
for _, secStat := range secStats {
|
||||
secretInfo = append(secretInfo, fmt.Sprintf("%s: %s", secStat.LocalName, secStat.Version))
|
||||
}
|
||||
|
||||
configFilters, err := app.Filters(false, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
}
|
||||
configs, err := client.GetConfigs(cl, context.Background(), app.Server, configFilters)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
configNames := client.GetConfigNames(configs)
|
||||
|
||||
var secretStrings []string
|
||||
for _, cont := range secretList {
|
||||
secretStrings = append(secretStrings, cont.Spec.Name)
|
||||
var configInfo []string
|
||||
for _, config := range configNames {
|
||||
name, version := extractConfigNameMetadata(config, app.StackName())
|
||||
configInfo = append(configInfo, fmt.Sprintf("%s: %s", name, version))
|
||||
}
|
||||
|
||||
configList, err := cl.ConfigList(context.Background(), types.ConfigListOptions{Filters: filters})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var configStrings []string
|
||||
for _, config := range configList {
|
||||
configStrings = append(configStrings, config.Spec.Name)
|
||||
}
|
||||
|
||||
var imageStrings []string
|
||||
var imageInfo []string
|
||||
for _, service := range compose.Services {
|
||||
imageStrings = append(imageStrings, service.Image)
|
||||
imageInfo = append(imageInfo, fmt.Sprintf("%s: %s", service.Name, service.Image))
|
||||
}
|
||||
|
||||
if err := internal.DeployOverview(
|
||||
@ -231,9 +239,9 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
||||
toDeployVersion,
|
||||
"",
|
||||
deployWarnMessages,
|
||||
strings.Join(secretStrings, "\n"),
|
||||
strings.Join(configStrings, "\n"),
|
||||
strings.Join(imageStrings, "\n"),
|
||||
strings.Join(secretInfo, "\n"),
|
||||
strings.Join(configInfo, "\n"),
|
||||
strings.Join(imageInfo, "\n"),
|
||||
); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -370,6 +378,16 @@ func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// extractConfigNameMetadata strips the stack name and returns
|
||||
// Example: "wordpress_db_password_v1" -> "v1"
|
||||
func extractConfigNameMetadata(fullName string, stackName string) (string, string) {
|
||||
name := strings.TrimPrefix(fullName, stackName + "_")
|
||||
if lastUnderscore := strings.LastIndex(name, "_"); lastUnderscore != -1 {
|
||||
return name[0:lastUnderscore], name[lastUnderscore+1:]
|
||||
}
|
||||
return name, ""
|
||||
}
|
||||
|
||||
func init() {
|
||||
AppDeployCommand.Flags().BoolVarP(
|
||||
&internal.Chaos,
|
||||
|
Reference in New Issue
Block a user