Skip to content

Commit 013d9f6

Browse files
Merge pull request #308 from depot/save-existing-build
2 parents 1c76187 + 37280a1 commit 013d9f6

File tree

4 files changed

+790
-588
lines changed

4 files changed

+790
-588
lines changed

pkg/build/build.go

+23-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"errors"
7+
"fmt"
78
"log"
89
"strings"
910

@@ -25,7 +26,8 @@ type Build struct {
2526
Finish func(error)
2627
Reporter progress.Writer
2728

28-
Response *connect.Response[cliv1.CreateBuildResponse]
29+
Response *connect.Response[cliv1.CreateBuildResponse]
30+
projectID string
2931
}
3032

3133
type Credential struct {
@@ -35,7 +37,7 @@ type Credential struct {
3537

3638
func (b *Build) AdditionalTags() []string {
3739
if b.Response == nil || b.Response.Msg == nil {
38-
return nil
40+
return []string{fmt.Sprintf("registry.depot.dev/%s:%s", b.projectID, b.ID)}
3941
}
4042

4143
tags := make([]string, 0, len(b.Response.Msg.AdditionalTags))
@@ -52,10 +54,8 @@ func (b *Build) AdditionalTags() []string {
5254

5355
func (b *Build) AdditionalCredentials() []Credential {
5456
if b.Response == nil || b.Response.Msg == nil {
55-
return nil
56-
}
57-
if len(b.Response.Msg.AdditionalCredentials) == 0 {
58-
return nil
57+
token := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("x-token:%s", b.Token)))
58+
return []Credential{{Host: "registry.depot.dev", Token: token}}
5959
}
6060

6161
creds := make([]Credential, 0, len(b.Response.Msg.AdditionalCredentials))
@@ -82,6 +82,10 @@ func (b *Build) AuthProvider(dockerAuth driver.Auth) driver.Auth {
8282
// This is important as the API may use a different project ID than the one
8383
// initially requested (e.g. onboarding)
8484
func (b *Build) BuildProject() string {
85+
if b.projectID != "" {
86+
return b.projectID
87+
}
88+
8589
if b.Response == nil || b.Response.Msg == nil {
8690
return ""
8791
}
@@ -107,8 +111,9 @@ func NewBuild(ctx context.Context, req *cliv1.CreateBuildRequest, token string)
107111
}
108112

109113
func FromExistingBuild(ctx context.Context, buildID, token string) (Build, error) {
114+
client := depotapi.NewBuildClient()
115+
110116
finish := func(buildErr error) {
111-
client := depotapi.NewBuildClient()
112117
req := cliv1.FinishBuildRequest{BuildId: buildID}
113118
req.Result = &cliv1.FinishBuildRequest_Success{Success: &cliv1.FinishBuildRequest_BuildSuccess{}}
114119
if buildErr != nil {
@@ -130,10 +135,18 @@ func FromExistingBuild(ctx context.Context, buildID, token string) (Build, error
130135
}
131136
}
132137

138+
req := cliv1.GetBuildRequest{BuildId: buildID}
139+
res, err := client.GetBuild(ctx, depotapi.WithAuthentication(connect.NewRequest(&req), token))
140+
if err != nil {
141+
return Build{}, err
142+
}
143+
133144
return Build{
134-
ID: buildID,
135-
Token: token,
136-
Finish: finish,
145+
ID: buildID,
146+
Token: token,
147+
Finish: finish,
148+
BuildURL: res.Msg.BuildUrl,
149+
projectID: res.Msg.ProjectId,
137150
}, nil
138151
}
139152

0 commit comments

Comments
 (0)