forked from toolshed/abra
.gitea
cli
cmd
pkg
app
autocomplete
client
compose
config
container
context
context.go
dns
formatter
git
integration
limit
lint
recipe
secret
server
service
ssh
test
upstream
web
scripts
tests
.drone.yml
.e2e.env.sample
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package context
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
dConfig "github.com/docker/cli/cli/config"
|
|
"github.com/docker/cli/cli/context"
|
|
contextStore "github.com/docker/cli/cli/context/store"
|
|
cliflags "github.com/docker/cli/cli/flags"
|
|
"github.com/moby/term"
|
|
)
|
|
|
|
func NewDefaultDockerContextStore() *command.ContextStoreWithDefault {
|
|
_, _, stderr := term.StdStreams()
|
|
dockerConfig := dConfig.LoadDefaultConfigFile(stderr)
|
|
contextDir := dConfig.ContextStoreDir()
|
|
storeConfig := command.DefaultContextStoreConfig()
|
|
store := newContextStore(contextDir, storeConfig)
|
|
|
|
opts := &cliflags.CommonOptions{Context: "default"}
|
|
|
|
dockerContextStore := &command.ContextStoreWithDefault{
|
|
Store: store,
|
|
Resolver: func() (*command.DefaultContext, error) {
|
|
return command.ResolveDefaultContext(opts, dockerConfig, storeConfig, stderr)
|
|
},
|
|
}
|
|
|
|
return dockerContextStore
|
|
}
|
|
|
|
func GetContextEndpoint(ctx contextStore.Metadata) (string, error) {
|
|
endpointmeta, ok := ctx.Endpoints["docker"].(context.EndpointMetaBase)
|
|
if !ok {
|
|
err := errors.New("context lacks Docker endpoint")
|
|
return "", err
|
|
}
|
|
return endpointmeta.Host, nil
|
|
}
|
|
|
|
func newContextStore(dir string, config contextStore.Config) contextStore.Store {
|
|
return contextStore.New(dir, config)
|
|
}
|