mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:37:46 +08:00
allow builder flag to switch to default instance
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
d2bf42f8b4
commit
4f7517115c
@ -93,7 +93,7 @@ func stop(ctx context.Context, dockerCli command.Cli, ng *store.NodeGroup, rm bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stopCurrent(ctx context.Context, dockerCli command.Cli, rm bool) error {
|
func stopCurrent(ctx context.Context, dockerCli command.Cli, rm bool) error {
|
||||||
dis, err := getDefaultDrivers(ctx, dockerCli, "")
|
dis, err := getDefaultDrivers(ctx, dockerCli, false, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -281,10 +281,29 @@ func clientForEndpoint(dockerCli command.Cli, name string) (dockerclient.APIClie
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getInstanceOrDefault(ctx context.Context, dockerCli command.Cli, instance, contextPathHash string) ([]build.DriverInfo, error) {
|
func getInstanceOrDefault(ctx context.Context, dockerCli command.Cli, instance, contextPathHash string) ([]build.DriverInfo, error) {
|
||||||
|
var defaultOnly bool
|
||||||
|
|
||||||
|
if instance == "default" && instance != dockerCli.CurrentContext() {
|
||||||
|
return nil, errors.Errorf("use `docker --context=default buildx` to switch to default context")
|
||||||
|
}
|
||||||
|
if instance == "default" || instance == dockerCli.CurrentContext() {
|
||||||
|
instance = ""
|
||||||
|
defaultOnly = true
|
||||||
|
}
|
||||||
|
list, err := dockerCli.ContextStore().List()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, l := range list {
|
||||||
|
if l.Name == instance {
|
||||||
|
return nil, errors.Errorf("use `docker --context=%s buildx` to switch to context %s", instance, instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if instance != "" {
|
if instance != "" {
|
||||||
return getInstanceByName(ctx, dockerCli, instance, contextPathHash)
|
return getInstanceByName(ctx, dockerCli, instance, contextPathHash)
|
||||||
}
|
}
|
||||||
return getDefaultDrivers(ctx, dockerCli, contextPathHash)
|
return getDefaultDrivers(ctx, dockerCli, defaultOnly, contextPathHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInstanceByName(ctx context.Context, dockerCli command.Cli, instance, contextPathHash string) ([]build.DriverInfo, error) {
|
func getInstanceByName(ctx context.Context, dockerCli command.Cli, instance, contextPathHash string) ([]build.DriverInfo, error) {
|
||||||
@ -302,13 +321,14 @@ func getInstanceByName(ctx context.Context, dockerCli command.Cli, instance, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getDefaultDrivers returns drivers based on current cli config
|
// getDefaultDrivers returns drivers based on current cli config
|
||||||
func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, contextPathHash string) ([]build.DriverInfo, error) {
|
func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, defaultOnly bool, contextPathHash string) ([]build.DriverInfo, error) {
|
||||||
txn, release, err := getStore(dockerCli)
|
txn, release, err := getStore(dockerCli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer release()
|
defer release()
|
||||||
|
|
||||||
|
if !defaultOnly {
|
||||||
ng, err := getCurrentInstance(txn, dockerCli)
|
ng, err := getCurrentInstance(txn, dockerCli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -317,6 +337,7 @@ func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, contextPathHa
|
|||||||
if ng != nil {
|
if ng != nil {
|
||||||
return driversForNodeGroup(ctx, dockerCli, ng, contextPathHash)
|
return driversForNodeGroup(ctx, dockerCli, ng, contextPathHash)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
d, err := driver.GetDriver(ctx, "buildx_buildkit_default", nil, dockerCli.Client(), nil, nil, "", nil, contextPathHash)
|
d, err := driver.GetDriver(ctx, "buildx_buildkit_default", nil, dockerCli.Client(), nil, nil, "", nil, contextPathHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user