mirror of https://github.com/docker/buildx.git
builder: fix default docker context behavior
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
fe8d5627e0
commit
ebdd8834a9
|
@ -97,9 +97,6 @@ func New(dockerCli command.Cli, opts ...Option) (_ *Builder, err error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if b.NodeGroup.Name == "default" && len(b.NodeGroup.Nodes) == 1 {
|
|
||||||
b.NodeGroup.Name = b.NodeGroup.Nodes[0].Endpoint
|
|
||||||
}
|
|
||||||
if b.opts.validate {
|
if b.opts.validate {
|
||||||
if err = b.Validate(); err != nil {
|
if err = b.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -111,16 +108,16 @@ func New(dockerCli command.Cli, opts ...Option) (_ *Builder, err error) {
|
||||||
|
|
||||||
// Validate validates builder context
|
// Validate validates builder context
|
||||||
func (b *Builder) Validate() error {
|
func (b *Builder) Validate() error {
|
||||||
if b.NodeGroup.Name == "default" && b.NodeGroup.Name != b.opts.dockerCli.CurrentContext() {
|
if b.NodeGroup.DockerContext {
|
||||||
return errors.Errorf("use `docker --context=default buildx` to switch to default context")
|
list, err := b.opts.dockerCli.ContextStore().List()
|
||||||
}
|
if err != nil {
|
||||||
list, err := b.opts.dockerCli.ContextStore().List()
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
currentContext := b.opts.dockerCli.CurrentContext()
|
||||||
}
|
for _, l := range list {
|
||||||
for _, l := range list {
|
if l.Name == b.Name && l.Name != currentContext {
|
||||||
if l.Name == b.NodeGroup.Name && b.NodeGroup.Name != "default" {
|
return errors.Errorf("use `docker --context=%s buildx` to switch to context %q", l.Name, l.Name)
|
||||||
return errors.Errorf("use `docker --context=%s buildx` to switch to context %q", b.NodeGroup.Name, b.NodeGroup.Name)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -12,10 +12,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeGroup struct {
|
type NodeGroup struct {
|
||||||
Name string
|
Name string
|
||||||
Driver string
|
Driver string
|
||||||
Nodes []Node
|
Nodes []Node
|
||||||
Dynamic bool
|
Dynamic bool
|
||||||
|
DockerContext bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
|
|
|
@ -79,10 +79,6 @@ func GetNodeGroup(txn *store.Txn, dockerCli command.Cli, name string) (*store.No
|
||||||
return ng, nil
|
return ng, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if name == "default" {
|
|
||||||
name = dockerCli.CurrentContext()
|
|
||||||
}
|
|
||||||
|
|
||||||
list, err := dockerCli.ContextStore().List()
|
list, err := dockerCli.ContextStore().List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -90,13 +86,14 @@ func GetNodeGroup(txn *store.Txn, dockerCli command.Cli, name string) (*store.No
|
||||||
for _, l := range list {
|
for _, l := range list {
|
||||||
if l.Name == name {
|
if l.Name == name {
|
||||||
return &store.NodeGroup{
|
return &store.NodeGroup{
|
||||||
Name: "default",
|
Name: name,
|
||||||
Nodes: []store.Node{
|
Nodes: []store.Node{
|
||||||
{
|
{
|
||||||
Name: "default",
|
Name: name,
|
||||||
Endpoint: name,
|
Endpoint: name,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
DockerContext: true,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue