4
4
"context"
5
5
"encoding/base64"
6
6
"errors"
7
+ "fmt"
7
8
"log"
8
9
"strings"
9
10
@@ -25,7 +26,8 @@ type Build struct {
25
26
Finish func (error )
26
27
Reporter progress.Writer
27
28
28
- Response * connect.Response [cliv1.CreateBuildResponse ]
29
+ Response * connect.Response [cliv1.CreateBuildResponse ]
30
+ projectID string
29
31
}
30
32
31
33
type Credential struct {
@@ -35,7 +37,7 @@ type Credential struct {
35
37
36
38
func (b * Build ) AdditionalTags () []string {
37
39
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 )}
39
41
}
40
42
41
43
tags := make ([]string , 0 , len (b .Response .Msg .AdditionalTags ))
@@ -52,10 +54,8 @@ func (b *Build) AdditionalTags() []string {
52
54
53
55
func (b * Build ) AdditionalCredentials () []Credential {
54
56
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 }}
59
59
}
60
60
61
61
creds := make ([]Credential , 0 , len (b .Response .Msg .AdditionalCredentials ))
@@ -82,6 +82,10 @@ func (b *Build) AuthProvider(dockerAuth driver.Auth) driver.Auth {
82
82
// This is important as the API may use a different project ID than the one
83
83
// initially requested (e.g. onboarding)
84
84
func (b * Build ) BuildProject () string {
85
+ if b .projectID != "" {
86
+ return b .projectID
87
+ }
88
+
85
89
if b .Response == nil || b .Response .Msg == nil {
86
90
return ""
87
91
}
@@ -107,8 +111,9 @@ func NewBuild(ctx context.Context, req *cliv1.CreateBuildRequest, token string)
107
111
}
108
112
109
113
func FromExistingBuild (ctx context.Context , buildID , token string ) (Build , error ) {
114
+ client := depotapi .NewBuildClient ()
115
+
110
116
finish := func (buildErr error ) {
111
- client := depotapi .NewBuildClient ()
112
117
req := cliv1.FinishBuildRequest {BuildId : buildID }
113
118
req .Result = & cliv1.FinishBuildRequest_Success {Success : & cliv1.FinishBuildRequest_BuildSuccess {}}
114
119
if buildErr != nil {
@@ -130,10 +135,18 @@ func FromExistingBuild(ctx context.Context, buildID, token string) (Build, error
130
135
}
131
136
}
132
137
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
+
133
144
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 ,
137
150
}, nil
138
151
}
139
152
0 commit comments