refactor: stack func to client, mv app to new file

Stack interaction is now under client.

App types and functions moved from env to app under config
This commit is contained in:
2021-08-02 05:51:58 +01:00
parent d777eb2af1
commit bb1eb372ef
6 changed files with 281 additions and 259 deletions

36
client/stack.go Normal file
View File

@ -0,0 +1,36 @@
package client
import (
"context"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
)
const StackNamespace = "com.docker.stack.namespace"
type StackStatus struct {
Services []swarm.Service
Err error
}
func QueryStackStatus(contextName string) StackStatus {
cl, err := NewClientWithContext(contextName)
if err != nil {
if strings.Contains(err.Error(), "does not exist") {
// No local context found, bail out gracefully
return StackStatus{[]swarm.Service{}, nil}
}
return StackStatus{[]swarm.Service{}, err}
}
ctx := context.Background()
filter := filters.NewArgs()
filter.Add("label", StackNamespace)
services, err := cl.ServiceList(ctx, types.ServiceListOptions{Filters: filter})
if err != nil {
return StackStatus{[]swarm.Service{}, err}
}
return StackStatus{services, nil}
}