Skip to content

Commit

Permalink
Default to server-side buildx proxy if the server says so (#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavolmarko authored Nov 8, 2024
1 parent bade37e commit 2f615b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
31 changes: 21 additions & 10 deletions internal/cli/cmd/cluster/buildx.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func newSetupBuildxCmd() *cobra.Command {
return err
}

available, err := determineAvailable(ctx)
available, serverSideProxyDefault, err := determineAvailable(ctx)
if err != nil {
return err
}
Expand All @@ -117,8 +117,14 @@ func newSetupBuildxCmd() *cobra.Command {

// NSL-3935 use remote-side buildx proxy
// This will be soon the default
if *useServerSideProxy {
return setupServerSideBuildxProxy(ctx, state, *name, *use, *defaultLoad, dockerCli, available, *createAtStartup)
if serverSideProxyDefault || *useServerSideProxy {
if err := setupServerSideBuildxProxy(ctx, state, *name, *use, *defaultLoad, dockerCli, available, *createAtStartup); err != nil {
return err
}

// Print info message.
console.SetStickyContent(ctx, "build", banner(ctx, *name, *use, available, true, true))
return nil
}

fmt.Fprintf(console.Debug(ctx), "Using state path %q\n", state)
Expand Down Expand Up @@ -258,7 +264,7 @@ func newSetupBuildxCmd() *cobra.Command {
}

// Print info message even if proxy goes in background
console.SetStickyContent(ctx, "build", banner(ctx, *name, *use, available, *background))
console.SetStickyContent(ctx, "build", banner(ctx, *name, *use, available, *background, false))

if *background {
return nil
Expand Down Expand Up @@ -561,21 +567,21 @@ func newWireBuildxCommand(hidden bool) *cobra.Command {
return cmd
}

func determineAvailable(ctx context.Context) ([]api.BuildPlatform, error) {
func determineAvailable(ctx context.Context) ([]api.BuildPlatform, bool, error) {
profile, err := api.GetProfile(ctx, api.Methods)
if err != nil {
return nil, err
return nil, false, err
}

avail := make([]api.BuildPlatform, len(profile.ClusterPlatform))
for k, x := range profile.ClusterPlatform {
avail[k] = api.BuildPlatform(x)
}

return avail, nil
return avail, profile.BuildxServerSideProxyDefaultHint, nil
}

func banner(ctx context.Context, name string, use bool, native []api.BuildPlatform, background bool) string {
func banner(ctx context.Context, name string, use bool, native []api.BuildPlatform, background, serverSideProxy bool) string {
w := wordwrap.NewWriter(80)
style := colors.Ctx(ctx)

Expand All @@ -600,8 +606,13 @@ func banner(ctx context.Context, name string, use bool, native []api.BuildPlatfo
fmt.Fprintf(w, "\nStart building:\n")
fmt.Fprintf(w, "\n docker buildx build ...\n")

fmt.Fprintf(w, "\nYour remote builder context is running in the background. You can always clean it up with:\n")
fmt.Fprintf(w, "\n nsc docker buildx cleanup \n")
if serverSideProxy {
fmt.Fprintf(w, "\nYou can remove the configuration with:\n")
fmt.Fprintf(w, "\n nsc docker buildx cleanup \n")
} else {
fmt.Fprintf(w, "\nYour remote builder context is running in the background. You can always clean it up with:\n")
fmt.Fprintf(w, "\n nsc docker buildx cleanup \n")
}
}

_ = w.Close()
Expand Down
3 changes: 2 additions & 1 deletion internal/providers/nscloud/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ type EnsureBazelCacheResponse struct {
}

type GetProfileResponse struct {
ClusterPlatform []string `json:"cluster_platform,omitempty"`
ClusterPlatform []string `json:"cluster_platform,omitempty"`
BuildxServerSideProxyDefaultHint bool `json:"buildx_server_side_proxy_default_hint,omitempty"`
}

type RegisterIngressRequest struct {
Expand Down

0 comments on commit 2f615b2

Please sign in to comment.