forked from toolshed/abra
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:
36
client/stack.go
Normal file
36
client/stack.go
Normal 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}
|
||||
}
|
Reference in New Issue
Block a user