fix: more robust docker context problem handling
See coop-cloud/organising#325 See coop-cloud/organising#340
This commit is contained in:
@ -2,6 +2,7 @@ package context
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/cli/cli/command"
|
||||
dConfig "github.com/docker/cli/cli/config"
|
||||
@ -42,3 +43,34 @@ func GetContextEndpoint(ctx contextStore.Metadata) (string, error) {
|
||||
func newContextStore(dir string, config contextStore.Config) contextStore.Store {
|
||||
return contextStore.New(dir, config)
|
||||
}
|
||||
|
||||
// MissingContextMsg helps end-uers debug missing docker context issues.
|
||||
var missingContextMsg = `unable to find Docker context for %s?
|
||||
|
||||
Please run "abra server ls" to confirm. If you see "unknown" in the table
|
||||
output then you need to run the following command:
|
||||
|
||||
abra server add %s <args>
|
||||
|
||||
See "abra server add --help" for more.
|
||||
`
|
||||
|
||||
// HasDockerContext figures out if a local setup has a working docker context
|
||||
// configuration or not. This usually tells us if they'll be able to make a SSH
|
||||
// connection to a server or not and can be a useful way to signal to end-users
|
||||
// that they need to fix something up if missing.
|
||||
func HasDockerContext(serverName string) error {
|
||||
dockerContextStore := NewDefaultDockerContextStore()
|
||||
contexts, err := dockerContextStore.Store.List()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, ctx := range contexts {
|
||||
if ctx.Name == serverName {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf(missingContextMsg, serverName, serverName)
|
||||
}
|
||||
|
Reference in New Issue
Block a user