Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to server-side buildx proxy if the server says so #1349

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading