WIP: Working secret and config versions during deploy overview
This commit is contained in:
@ -3,6 +3,8 @@ package app
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
@ -22,7 +24,6 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
dockerClient "github.com/docker/docker/client"
|
dockerClient "github.com/docker/docker/client"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// translators: `abra app deploy` aliases. use a comma separated list of aliases with
|
// 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
|
deployedVersion = deployMeta.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
filters, err := app.Filters(false, false)
|
secStats, err := secret.PollSecretsStatus(cl, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
configNames := client.GetConfigNames(configs)
|
||||||
|
|
||||||
var secretStrings []string
|
var configInfo []string
|
||||||
for _, cont := range secretList {
|
for _, config := range configNames {
|
||||||
secretStrings = append(secretStrings, cont.Spec.Name)
|
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})
|
var imageInfo []string
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var configStrings []string
|
|
||||||
for _, config := range configList {
|
|
||||||
configStrings = append(configStrings, config.Spec.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
var imageStrings []string
|
|
||||||
for _, service := range compose.Services {
|
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(
|
if err := internal.DeployOverview(
|
||||||
@ -231,9 +239,9 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
|||||||
toDeployVersion,
|
toDeployVersion,
|
||||||
"",
|
"",
|
||||||
deployWarnMessages,
|
deployWarnMessages,
|
||||||
strings.Join(secretStrings, "\n"),
|
strings.Join(secretInfo, "\n"),
|
||||||
strings.Join(configStrings, "\n"),
|
strings.Join(configInfo, "\n"),
|
||||||
strings.Join(imageStrings, "\n"),
|
strings.Join(imageInfo, "\n"),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -370,6 +378,16 @@ func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App
|
|||||||
return v, nil
|
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() {
|
func init() {
|
||||||
AppDeployCommand.Flags().BoolVarP(
|
AppDeployCommand.Flags().BoolVarP(
|
||||||
&internal.Chaos,
|
&internal.Chaos,
|
||||||
|
Reference in New Issue
Block a user