Skip to content

Commit

Permalink
buildx: flag to wait for login
Browse files Browse the repository at this point in the history
Fixes: NSL-2249
  • Loading branch information
gmichelo committed Nov 23, 2023
1 parent 0d82a9d commit 0bfd7d0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions internal/cli/cmd/cluster/buildx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"path/filepath"
"strings"
"syscall"
"time"

"github.com/docker/buildx/store"
"github.com/docker/buildx/store/storeutil"
Expand Down Expand Up @@ -64,6 +65,8 @@ func newSetupBuildxCmd(cmdName string) *cobra.Command {
staticWorkerDefFile := cmd.Flags().String("static_worker_definition_path", "", "Injects the gRPC proxy ListWorkers response JSON payload from file")
_ = cmd.Flags().MarkHidden("static_worker_definition_path")
forceCleanup := cmd.Flags().Bool("force_cleanup", false, "If set, it forces a cleanup of any previous buildx proxy running in background.")
waitForLogin := cmd.Flags().Bool("wait_for_login", false, "If set, it blocks waiting for user to login.")
_ = cmd.Flags().MarkHidden("wait_for_login")

cmd.RunE = fncobra.RunE(func(ctx context.Context, args []string) error {
if *debugDir != "" && !*background {
Expand All @@ -74,6 +77,14 @@ func newSetupBuildxCmd(cmdName string) *cobra.Command {
return fnerrors.New("--inject_worker_info_file requires --use_grpc_proxy")
}

// NSL-2249 for brew service, block here until user logs in.
if *waitForLogin {
err := blockWaitForLogin(ctx)
if err != nil {
return err
}
}

dockerCli, err := command.NewDockerCli()
if err != nil {
return err
Expand Down Expand Up @@ -279,6 +290,27 @@ If you want to create a new remote builder context configuration, cleanup the ol
}
}

func blockWaitForLogin(ctx context.Context) error {
// Check immediately if token is valid by calling Namespace
_, err := api.GetProfile(ctx, api.Methods)
if err == nil {
return err
}

// Else, block
for {
select {
case <-time.After(time.Second * 5):
_, err := api.GetProfile(ctx, api.Methods)
if err == nil {
return err
}
case <-ctx.Done():
return ctx.Err()
}
}
}

func ensureStateDir(specified, dir string) (string, error) {
if specified == "" {
// Change state dir from cache, which can be removed at any time,
Expand Down

0 comments on commit 0bfd7d0

Please sign in to comment.