refactor: making app version command async
This commit is contained in:
parent
ed11634abf
commit
c5bb680fed
@ -14,6 +14,12 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// parseVersionLabel parses a $STACK_NAME_$SERVICE_NAME service label
|
||||||
|
func parseServiceName(label string) string {
|
||||||
|
idx := strings.LastIndex(label, "_")
|
||||||
|
return label[idx+1:]
|
||||||
|
}
|
||||||
|
|
||||||
// parseVersionLabel parses a $VERSION-$DIGEST service label
|
// parseVersionLabel parses a $VERSION-$DIGEST service label
|
||||||
func parseVersionLabel(label string) (string, string) {
|
func parseVersionLabel(label string) (string, string) {
|
||||||
// versions may look like v4.2-abcd or v4.2-alpine-abcd
|
// versions may look like v4.2-abcd or v4.2-alpine-abcd
|
||||||
@ -46,15 +52,24 @@ var appVersionCommand = &cli.Command{
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ch := make(chan stack.StackStatus, len(compose.Services))
|
||||||
|
for _, service := range compose.Services {
|
||||||
|
label := fmt.Sprintf("coop-cloud.%s.%s.version", appEnv.StackName(), service.Name)
|
||||||
|
go func(s string, l string) {
|
||||||
|
ch <- stack.GetDeployedServicesByLabel(s, l)
|
||||||
|
}(app.Server, label)
|
||||||
|
}
|
||||||
|
|
||||||
tableCol := []string{"Name", "Image", "Version", "Digest"}
|
tableCol := []string{"Name", "Image", "Version", "Digest"}
|
||||||
table := abraFormatter.CreateTable(tableCol)
|
table := abraFormatter.CreateTable(tableCol)
|
||||||
|
|
||||||
for _, service := range compose.Services {
|
for range compose.Services {
|
||||||
label := fmt.Sprintf("coop-cloud.%s.%s.version", appEnv.StackName(), service.Name)
|
status := <-ch
|
||||||
status := stack.GetDeployedServicesByLabel(app.Server, label)
|
for _, service := range status.Services {
|
||||||
for _, serviceStatus := range status.Services {
|
serviceName := parseServiceName(service.Spec.Name)
|
||||||
version, digest := parseVersionLabel(serviceStatus.Spec.Labels[label])
|
label := fmt.Sprintf("coop-cloud.%s.%s.version", appEnv.StackName(), serviceName)
|
||||||
img, err := reference.ParseNormalizedNamed(service.Image)
|
version, digest := parseVersionLabel(service.Spec.Labels[label])
|
||||||
|
img, err := reference.ParseNormalizedNamed(service.Spec.Labels["com.docker.stack.image"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -62,7 +77,6 @@ var appVersionCommand = &cli.Command{
|
|||||||
if strings.Contains(image, "library") {
|
if strings.Contains(image, "library") {
|
||||||
image = strings.Split(image, "/")[1]
|
image = strings.Split(image, "/")[1]
|
||||||
}
|
}
|
||||||
serviceName := fmt.Sprintf("%s_%s", appEnv.StackName(), service.Name)
|
|
||||||
table.Append([]string{serviceName, image, version, digest})
|
table.Append([]string{serviceName, image, version, digest})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user