Skip to content

Commit

Permalink
Merge pull request #208 from depot/fix/onboard-loading
Browse files Browse the repository at this point in the history
fix(load): use selected project during onboarding for fast load
  • Loading branch information
goller authored Oct 21, 2023
2 parents 0e77e33 + 3b9d9c9 commit ae91490
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 308 deletions.
10 changes: 10 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ type Build struct {
Response *connect.Response[cliv1.CreateBuildResponse]
}

// BuildProject returns the project ID to be used for the build.
// This is important as the API may use a different project ID than the one
// initially requested (e.g. onboarding)
func (b *Build) BuildProject() string {
if b.Response == nil || b.Response.Msg == nil {
return ""
}
return b.Response.Msg.ProjectId
}

func NewBuild(ctx context.Context, req *cliv1.CreateBuildRequest, token string) (Build, error) {
client := depotapi.NewBuildClient()
res, err := client.CreateBuild(ctx, depotapi.WithAuthentication(connect.NewRequest(req), token))
Expand Down
4 changes: 4 additions & 0 deletions pkg/buildx/commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func BakeCmd(dockerCli command.Cli) *cobra.Command {

options.builderOptions = []builder.Option{builder.WithDepotOptions(buildPlatform, build)}

buildProject := build.BuildProject()
if buildProject != "" {
options.project = buildProject
}
options.buildID = build.ID
options.buildURL = build.BuildURL
options.token = build.Token
Expand Down
4 changes: 4 additions & 0 deletions pkg/buildx/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ func BuildCmd(dockerCli command.Cli) *cobra.Command {
}()

options.builderOptions = []builder.Option{builder.WithDepotOptions(buildPlatform, build)}
buildProject := build.BuildProject()
if buildProject != "" {
options.project = buildProject
}
options.buildID = build.ID
options.buildURL = build.BuildURL
options.token = build.Token
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/buildctl/dial-stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func run() error {
acquireState := func() ProxyState {
once.Do(func() {
req := &cliv1.CreateBuildRequest{
ProjectId: projectID,
ProjectId: &projectID,
Options: []*cliv1.BuildOptions{{Command: cliv1.Command_COMMAND_BUILDX}},
}
build, err := helpers.BeginBuild(ctx, req, token)
Expand Down
8 changes: 4 additions & 4 deletions pkg/helpers/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func BeginBuild(ctx context.Context, req *cliv1.CreateBuildRequest, token string
}

// Ok, now try from the top again!
req.ProjectId = selectedProject.ID
req.ProjectId = &selectedProject.ID
return BeginBuild(ctx, req, token)
}
return depotbuild.Build{}, err
Expand Down Expand Up @@ -77,7 +77,7 @@ func NewBuildRequest(project string, opts map[string]buildx.Options, features Us
}

return &cliv1.CreateBuildRequest{
ProjectId: project,
ProjectId: &project,
Options: []*cliv1.BuildOptions{
{
Command: cliv1.Command_COMMAND_BUILD,
Expand All @@ -93,7 +93,7 @@ func NewBuildRequest(project string, opts map[string]buildx.Options, features Us
}

// Should never be reached.
return &cliv1.CreateBuildRequest{ProjectId: project}
return &cliv1.CreateBuildRequest{ProjectId: &project}
}

func NewBakeRequest(project string, opts map[string]buildx.Options, features UsingDepotFeatures) *cliv1.CreateBuildRequest {
Expand Down Expand Up @@ -121,7 +121,7 @@ func NewBakeRequest(project string, opts map[string]buildx.Options, features Usi
}

return &cliv1.CreateBuildRequest{
ProjectId: project,
ProjectId: &project,
Options: targets,
}
}
616 changes: 314 additions & 302 deletions pkg/proto/depot/cli/v1/build.pb.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion proto/depot/cli/v1/build.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ service BuildService {
}

message CreateBuildRequest {
string project_id = 1;
optional string project_id = 1;
// This is an option per build target; in other words many for bake and one for build.
repeated BuildOptions options = 2;
}
Expand Down Expand Up @@ -63,6 +63,8 @@ message CreateBuildResponse {

// Build URL is the URL to the build output.
string build_url = 5;

string project_id = 6;
}

message Registry {
Expand Down

0 comments on commit ae91490

Please sign in to comment.